1#!./perl
2
3# quickie tests to see if h2ph actually runs and does more or less what is
4# expected
5
6BEGIN {
7    chdir 't' if -d 't';
8    @INC = '../lib';
9}
10
11require './test.pl';
12
13my $extracted_program = '../utils/h2ph'; # unix, nt, ...
14if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2ph.com'; }
15if (!(-e $extracted_program)) {
16    print "1..0 # Skip: $extracted_program was not built\n";
17    exit 0;
18}
19
20plan(6);
21
22# quickly compare two text files
23sub txt_compare {
24    local $/;
25    my ($A, $B);
26    for (($A,$B) = @_) { open(_,"<",$_) ? $_ = <_> : die "$_ : $!"; close _ }
27    $A cmp $B;
28}
29
30my $result = runperl( progfile => $extracted_program,
31                      stderr => 1,
32                      args => ['-d.', '-Q', 'lib/h2ph.h']);
33is( $result, '', "output is free of warnings" );
34is( $?, 0, "$extracted_program runs successfully" );
35
36is ( txt_compare("lib/h2ph.ph", "lib/h2ph.pht"),
37     0,
38     "generated file has expected contents" );
39
40$result = runperl( progfile => 'lib/h2ph.pht',
41                   switches => ['-c'],
42                   stderr => 1 );
43like( $result, qr/syntax OK$/, "output compiles");
44
45$result = runperl( progfile => '_h2ph_pre.ph',
46                   switches => ['-c'],
47                   stderr => 1 );
48like( $result, qr/syntax OK$/, "preamble compiles");
49
50$result = runperl( switches => ['-I.', "-w"],
51                   stderr => 1,
52                   prog => <<'PROG' );
53$SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht);
54PROG
55is( $result, '', "output free of warnings" );
56
57# cleanup
58END {
59    1 while unlink("lib/h2ph.ph");
60    1 while unlink("_h2ph_pre.ph");
61}
62