2 # Copyright (C) 2007-2008, Parrot Foundation.
11 use Cwd qw(cwd realpath);
12 realpath($Bin) =~ m{^(.*\/parrot)\/[^/]*\/[^/]*\/[^/]*$};
14 if ( defined $topdir ) {
15 print "\nOK: Parrot top directory located\n";
18 $topdir = realpath($Bin) . "/../../..";
20 unshift @INC, qq{$topdir/lib};
26 use File::Temp (qw| tempdir |);
29 plan -e "$cwd/DEVELOPING" ? ( tests => 86 ) :
30 ( skip_all => 'Requires DEVELOPING file' );
32 use_ok('Parrot::Ops2pm');
33 use IO::CaptureOutput qw| capture |;
35 use constant NUM_FILE => "src/ops/ops.num";
36 use constant SKIP_FILE => "src/ops/ops.skip";
38 ok( chdir $main::topdir, "Positioned at top-level Parrot directory" );
48 my $tdir = tempdir( CLEANUP => 1 );
49 ok( chdir $tdir, 'changed to temp directory for testing' );
50 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
51 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
52 foreach my $f (@ARGV) {
53 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
57 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
58 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
59 my @opsfiles = glob("./src/ops/*.ops");
61 my $self = Parrot::Ops2pm->new(
64 script => "tools/build/ops2pm.pl",
69 isa_ok( $self, q{Parrot::Ops2pm} );
71 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
72 ok( defined( $self->{ops} ), "'ops' key has been defined" );
74 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
75 ok( -f $num, "ops.num located after renumbering" );
76 ok( -f $skip, "ops.skip located after renumbering" );
78 ok( $self->sort_ops(), "sort_ops returned successfully" );
80 # To do: Test that the sorting was correct.
82 ok( chdir $cwd, 'changed back to starting directory after testing' );
86 # include experimental.ops in @ARGV
91 src/ops/experimental.ops
95 my $tdir = tempdir( CLEANUP => 1 );
96 ok( chdir $tdir, 'changed to temp directory for testing' );
97 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
98 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
99 foreach my $f (@ARGV) {
100 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
103 my $skip = SKIP_FILE;
104 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
105 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
106 my @opsfiles = glob("./src/ops/*.ops");
108 my $self = Parrot::Ops2pm->new(
111 script => "tools/build/ops2pm.pl",
116 isa_ok( $self, q{Parrot::Ops2pm} );
118 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
119 ok( defined( $self->{ops} ), "'ops' key has been defined" );
121 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
122 ok( -f $num, "ops.num located after renumbering" );
123 ok( -f $skip, "ops.skip located after renumbering" );
125 ok( $self->sort_ops(), "sort_ops returned successfully" );
127 # To do: Test that the sorting was correct.
129 ok( chdir $cwd, 'changed back to starting directory after testing' );
133 # include experimental.ops in @ARGV; use 'DEVELOPING' to trigger warning
138 src/ops/experimental.ops
142 my $tdir = tempdir( CLEANUP => 1 );
143 ok( chdir $tdir, 'changed to temp directory for testing' );
144 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
145 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
146 foreach my $f (@ARGV) {
147 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
150 my $skip = SKIP_FILE;
151 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
152 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
153 ok( copy( qq{$cwd/DEVELOPING}, qq{$tdir/DEVELOPING} ), "copied DEVELOPING file" );
154 my @opsfiles = glob("./src/ops/*.ops");
156 my $self = Parrot::Ops2pm->new(
159 script => "tools/build/ops2pm.pl",
164 isa_ok( $self, q{Parrot::Ops2pm} );
166 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
167 ok( defined( $self->{ops} ), "'ops' key has been defined" );
169 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
170 ok( -f $num, "ops.num located after renumbering" );
171 ok( -f $skip, "ops.skip located after renumbering" );
173 my ($stdout, $stderr);
175 sub { $self->sort_ops() },
179 ok($ret, "sort_ops returned successfully" );
181 # local $TODO = 'broken warning about experimental ops';
185 qr|experimental, not in ops\.num|,
186 "Got expected warning about experimental ops"
190 # To do: Test that the sorting was correct.
192 ok( chdir $cwd, 'changed back to starting directory after testing' );
196 # include object.ops in @ARGV; use 'DEVELOPING' to trigger warning
205 my $tdir = tempdir( CLEANUP => 1 );
206 ok( chdir $tdir, 'changed to temp directory for testing' );
207 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
208 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
209 foreach my $f (@ARGV) {
210 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
213 my $skip = SKIP_FILE;
214 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
215 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
216 ok( copy( qq{$cwd/DEVELOPING}, qq{$tdir/DEVELOPING} ), "copied DEVELOPING file" );
217 my $dummyops = "./src/ops/dummy.ops";
218 open my $FH, ">", $dummyops
219 or croak "Unable to open handle to create dummy ops file: $!";
220 print $FH <<DUMMYOPS;
225 inline op zzzzzz(inout INT, in INT) :base_core {
229 close $FH or croak "Unable to close handle after writing: $!";
230 my @opsfiles = glob("./src/ops/*.ops");
232 my $self = Parrot::Ops2pm->new(
235 script => "tools/build/ops2pm.pl",
240 isa_ok( $self, q{Parrot::Ops2pm} );
242 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
243 ok( defined( $self->{ops} ), "'ops' key has been defined" );
245 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
246 ok( -f $num, "ops.num located after renumbering" );
247 ok( -f $skip, "ops.skip located after renumbering" );
249 my ($stdout, $stderr);
250 eval { $self->sort_ops() };
253 qr|not in ops\.num nor ops\.skip|,
254 "Got expected failure about ops in neither ops.num or ops.skip"
257 # To do: Test that the sorting was correct.
259 ok( chdir $cwd, 'changed back to starting directory after testing' );
263 # include object.ops in @ARGV; do not use 'DEVELOPING' to trigger warning
272 my $tdir = tempdir( CLEANUP => 1 );
273 ok( chdir $tdir, 'changed to temp directory for testing' );
274 ok( ( mkdir qq{$tdir/src} ), "able to make tempdir/src" );
275 ok( ( mkdir qq{$tdir/src/ops} ), "able to make tempdir/src" );
276 foreach my $f (@ARGV) {
277 ok( copy( qq{$cwd/$f}, qq{$tdir/$f} ), "copied .ops file" );
280 my $skip = SKIP_FILE;
281 ok( copy( qq{$cwd/$num}, qq{$tdir/$num} ), "copied ops.num file" );
282 ok( copy( qq{$cwd/$skip}, qq{$tdir/$skip} ), "copied ops.skip file" );
284 # ok(copy(qq{$cwd/DEVELOPING}, qq{$tdir/DEVELOPING}),
285 # "copied DEVELOPING file");
286 my @opsfiles = glob("./src/ops/*.ops");
288 my $self = Parrot::Ops2pm->new(
291 script => "tools/build/ops2pm.pl",
296 isa_ok( $self, q{Parrot::Ops2pm} );
298 ok( $self->prepare_ops, "prepare_ops() returned successfully" );
299 ok( defined( $self->{ops} ), "'ops' key has been defined" );
301 ok( $self->load_op_map_files(), "load_op_map_files() completed successfully" );
302 ok( -f $num, "ops.num located after renumbering" );
303 ok( -f $skip, "ops.skip located after renumbering" );
305 my ($stdout, $stderr);
307 sub { $self->sort_ops() },
311 ok($ret, "sort_ops returned successfully" );
312 ok( ! $stderr, "Got no warning, as expected" );
314 # To do: Test that the sorting was correct.
316 ok( chdir $cwd, 'changed back to starting directory after testing' );
320 pass("Completed all tests in $0");
322 ################### DOCUMENTATION ###################
326 08-sort_ops.t - test C<Parrot::Ops2pm::sort_ops()>
330 % prove t/tools/ops2pm/08-sort_ops.t
334 The files in this directory test the publicly callable subroutines of
335 F<lib/Parrot/Ops2pm.pm> and F<lib/Parrot/Ops2pm/Auxiliary.pm>.
336 By doing so, they test the functionality of the F<ops2pm.pl> utility.
337 That functionality has largely been extracted
338 into the methods of F<Utils.pm>.
340 F<08-sort_ops.t> tests whether
341 C<Parrot::Ops2pm::sort_ops()> works properly.
349 Parrot::Ops2pm, F<ops2pm.pl>.
355 # cperl-indent-level: 4
358 # vim: expandtab shiftwidth=4: