c-compress-test.pl 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #! /usr/bin/env perl
  2. #
  3. # TEST c-compress-pl with a number of examples and what should happen to them
  4. use strict;
  5. use warnings;
  6. use File::Basename;
  7. my @pairs =
  8. (
  9. [ <<'_____'
  10. /* A hell of a program */
  11. #def\
  12. ine foo/* bar */ 3
  13. #define bar /* haha "A /* comment */ that should /* remain" */
  14. #define haha /* hoho */ "A /* comment */ that should /* remain" */
  15. int main() {
  16. int x;
  17. /* one lonely comment */
  18. }
  19. _____
  20. , <<'_____'
  21. #define foo 3
  22. #define bar that should
  23. #define haha "A /* comment */ that should /* remain" */
  24. int main() {
  25. int x;
  26. }
  27. _____
  28. ]
  29. );
  30. my $here = dirname $0;
  31. my $c_compress = "$here/lang-compress.pl";
  32. use FileHandle;
  33. use IPC::Open2;
  34. use Text::Diff;
  35. foreach (@pairs) {
  36. my $source = $_->[0];
  37. my $expected = $_->[1];
  38. my $pid = open2(\*Reader, \*Writer, "perl $c_compress 'C'");
  39. print Writer $source;
  40. close Writer;
  41. local $/ = undef; # slurp
  42. my $got = <Reader>;
  43. if ($got ne $expected) {
  44. print "MISMATCH:\n", diff \$expected, \$got;
  45. }
  46. }