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