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