[t][TT #1122] Convert t/op/numbert.t to PIR, mgrimes++
[parrot.git] / t / tools / pbc_disassemble.t
blobc857cfb0abc7eadbc07d7ba29ed02309b68a2d1d
1 #! perl
2 # Copyright (C) 2009, Parrot Foundation
3 # $Id$
5 =head1 NAME
7 t/tools/pbc_disassemble.t - test the Parrot Bytecode (PBC) Disassembler
9 =head1 SYNOPSIS
11     % prove t/tools/pbc_disassemble.t
13 =head1 DESCRIPTION
15 Tests the C<pbc_disassemble> 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_disassemble.  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_disassemble, 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 File::Spec;
38 use Parrot::Test;
40 my $path;
42 BEGIN {
43     $path = File::Spec->catfile( ".", "pbc_disassemble" );
44     my $exefile = $path . $PConfig{exe};
45     unless ( -f $exefile ) {
46         plan skip_all => "pbc_disassemble hasn't been built. Run make parrot_utils";
47         exit(0);
48     }
49     plan tests => 4;
52 disassemble_output_like( <<PIR, "pir", qr/PMC_CONST.*set_n_nc.*print_n/ms, 'pbc_disassemble numeric ops');
53 .sub main :main
54     \$N3 = 3.14159
55     print \$N3
56     print "\\n"
57 .end
58 PIR
60 disassemble_output_like( <<PIR, "pir", qr/PMC_CONST.*set_i_ic.*print_i/ms, 'pbc_disassemble integer ops');
61 .sub main :main
62     \$I0 = 1982
63     print \$I0
64     print "\\n"
65 .end
66 PIR
68 disassemble_output_like( <<PIR, "pir", qr/PMC_CONST.*new_p_sc.*"ResizablePMCArray".*set_p_kic_ic\s*P.*set_i_p_kic\s*I.*/ms, 'pbc_disassemble pmc ops');
69 .sub main :main
70     \$P0    = new 'ResizablePMCArray'
71     \$P0[0] = 42
72     \$I0 = \$P0[0]
73 .end
74 PIR
76 disassemble_output_like( <<PIR, "pir", qr/PMC_CONST.*set_s_sc\s*S.*print_s\s*S.*print_sc/ms, 'pbc_disassemble string ops');
77 .sub main :main
78     \$S0 = "Wheels within wheels"
79     print \$S0
80     print "\\n"
81 .end
82 PIR
84 =head1 HELPER SUBROUTINES
86 =head2 disassemble_output_like
88     disassemble_output_like(<<PASM, "pasm", "some output", "running $file");
90 Takes 3-4 arguments: a file to run,
91 the filename-extension of the file (probably "pir" or "pasm"),
92 an arrayref or single regex string to match within pbc_disassemble's output,
93 and the optional test diagnostic.
95 =cut
97 sub disassemble_output_like {
98     pbc_postprocess_output_like($path, @_ );
101 # Local Variables:
102 #   mode: cperl
103 #   cperl-indent-level: 4
104 #   fill-column: 100
105 # End:
106 # vim: expandtab shiftwidth=4: