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