summaryrefslogtreecommitdiff
path: root/lib/h2ph.t
blob: 64d9dc080f489da21274536091db031aa92f14cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!./perl
use strict;

# quickie tests to see if h2ph actually runs and does more or less what is
# expected

BEGIN {
    chdir 't' if -d 't';
    @INC = '../lib';
}

require './test.pl';

my $extracted_program = '../utils/h2ph'; # unix, nt, ...
if ($^O eq 'VMS') { $extracted_program = '[-.utils]h2ph.com'; }
if (!(-e $extracted_program)) {
    print "1..0 # Skip: $extracted_program was not built\n";
    exit 0;
}

plan(6);

# quickly compare two text files
sub txt_compare {
    local $/;
    my ($A, $B);
    for (($A,$B) = @_) { open(_,"<$_") ? $_ = <_> : die "$_ : $!"; close _ }
    $A cmp $B;
}

my $result = runperl( progfile => $extracted_program,
                      stderr => 1,
                      args => ['-d.', '-Q', 'lib/h2ph.h']);
is( $result, '', "output is free of warnings" );
is( $?, 0, "$extracted_program runs successfully" );

is ( txt_compare("lib/h2ph.ph", "lib/h2ph.pht"),
     0,
     "generated file has expected contents" );

$result = runperl( progfile => 'lib/h2ph.pht',
                   switches => ['-c'],
                   stderr => 1 );
like( $result, qr/syntax OK$/, "output compiles");

$result = runperl( progfile => '_h2ph_pre.ph',
                   switches => ['-c'],
                   stderr => 1 );
like( $result, qr/syntax OK$/, "preamble compiles");

$result = runperl( switches => ['-I.', "-w"],
                   stderr => 1,
                   prog => <<'PROG' );
$SIG{__WARN__} = sub { die $_[0] }; require q(lib/h2ph.pht);
PROG
is( $result, '', "output free of warnings" );

# cleanup
END {
    1 while unlink("lib/h2ph.ph");
    1 while unlink("_h2ph_pre.ph");
}