xref: /openssl/util/c-compress-test.pl (revision be223152)
1#! /usr/bin/env perl
2#
3# TEST c-compress-pl with a number of examples and what should happen to them
4
5use strict;
6use warnings;
7
8use File::Basename;
9
10my @pairs =
11    (
12     [ <<'_____'
13/* A hell of a program */
14#def\
15ine foo/* bar */ 3
16#define bar /* haha "A /* comment */ that should    /* remain" */
17#define  haha /* hoho */ "A /* comment */ that should /* remain" */
18
19int 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" */
28int main() {
29int x;
30}
31_____
32     ]
33    );
34
35my $here = dirname $0;
36my $c_compress = "$here/lang-compress.pl";
37
38use FileHandle;
39use IPC::Open2;
40use Text::Diff;
41foreach (@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