[t][TT #1122] Convert t/op/numbert.t to PIR, mgrimes++
[parrot.git] / t / tools / pbc_dump.t
bloba269f1a808e3a557bfa6c1c62f7926b0e0dc678b
1 #! perl
2 # Copyright (C) 2009, Parrot Foundation.
3 # $Id$
5 =head1 NAME
7 t/tools/pbc_dump.t - test the Parrot Bytecode (PBC) Dumper
9 =head1 SYNOPSIS
11     % prove t/tools/pbc_dump.t
13 =head1 DESCRIPTION
15 Tests the C<pbc_dump> tool by providing it with a number of source
16 files, and running through it with various commands.
18 We never actually check the I<full> output of pbc_dump.  We simply check
19 several smaller components to avoid a test file that is far too unwieldy.
22 =head1 REQUIREMENTS
24 This test script requires you to build pbc_dump, by typing
25 "make parrot_utils" (using a suitable make tool for your platform).
26 If this requirement has not been met, all tests will be skipped.
28 =cut
30 use strict;
31 use warnings;
32 use lib qw(lib);
34 use Test::More;
35 use IO::File ();
36 use Parrot::Config;
37 use Parrot::Test;
38 use File::Spec;
40 my $path;
42 BEGIN {
43     $path = File::Spec->catfile( ".", "pbc_dump" );
44     my $exefile = $path . $PConfig{exe};
45     unless ( -f $exefile ) {
46         plan skip_all => "pbc_dump hasn't been built. Run make parrot_utils";
47         exit(0);
48     }
49     plan tests => 6;
52 dump_output_like( <<PIR, "pir", [qr/FIXUP_t/, qr/CONSTANT_t/, qr/BYTECODE_t/], 'pbc_dump basic sanity');
53 .sub main :main
54     \$I0 = 42
55 .end
56 PIR
58 dump_output_like( <<PIR, "pir", qr/HEADER\s*=>\s*\[.*wordsize.*byteorder.*floattype.*parrot-version.*bytecode-version.*UUID.*\]/ms, 'pbc_dump HEADER sanity');
59 .sub main :main
60     \$I0 = 42
61 .end
62 PIR
64 dump_output_like( <<PIR, "pir", qr/DIRECTORY\s*=>\s*\[.*offs.*op_count.*itype.*id.*size.*segments/ms, 'pbc_dump DIRECTORY sanity');
65 .sub main :main
66     \$I0 = 42
67 .end
68 PIR
70 dump_output_like( <<PIR, "pir", qr/BYTECODE_t.*=>.*\[.*offs.*op_count.*itype.*id.*size.*mappings/ms, 'pbc_dump BYTECODE sanity');
71 .sub main :main
72     \$I0 = 42
73 .end
74 PIR
76 =head1 HELPER SUBROUTINES
78 =head2 dump_output_like
80     dump_output_like(<<PASM, "pasm", "some output", "running $file");
82 Takes 3-4 arguments: a file to run,
83 the filename-extension of the file (probably "pir" or "pasm"),
84 an arrayref or single regex string to match within pbc_dump's output,
85 and the optional test diagnostic.
87 =cut
89 sub dump_output_like {
90     pbc_postprocess_output_like($path, @_ );
93 # Local Variables:
94 #   mode: cperl
95 #   cperl-indent-level: 4
96 #   fill-column: 100
97 # End:
98 # vim: expandtab shiftwidth=4: