Skip to content

Commit

Permalink
[t] create utility module for parrot tests
Browse files Browse the repository at this point in the history
~ add function for createing cross-platform tempfiles
~ convert tests to use it

git-svn-id: https://svn.parrot.org/parrot/trunk@32058 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
particle committed Oct 20, 2008
1 parent 27b82e5 commit 2abaa9d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 35 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -2734,6 +2734,7 @@ lib/Parrot/Test/PGE.pm [devel]
lib/Parrot/Test/PIR_PGE.pm [devel]
lib/Parrot/Test/Perl6.pm [devel]
lib/Parrot/Test/Punie.pm [devel]
lib/Parrot/Test/Util.pm [devel]
lib/Parrot/Test/Util/Runloop.pm [devel]
lib/Parrot/Vtable.pm [devel]
lib/Perl/Critic/Policy/CodeLayout/ProhibitDuplicateCoda.pm [devel]
Expand Down
54 changes: 54 additions & 0 deletions lib/Parrot/Test/Util.pm
@@ -0,0 +1,54 @@
# Copyright (C) 2008, The Perl Foundation.
# $Id$

=head1 NAME
Parrot::Test::Util - utilities for Parrot tests
=head1 SYNOPSIS
use Parrot::Test::Util 'create_tempfile';
my ($FOO, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );
=head1 DESCRIPTION
This module provides basic utilities for Parrot test scripts. So far, there's
only one utility, C<create_tempfile>, which must be requested for import.
=head1 AUTHOR
Written by Jerry Gay.
=cut

package Parrot::Test::Util;

use strict;
use warnings;

use File::Temp 'tempfile';
use Exporter;

our @ISA = qw( Exporter );
our @EXPORT_OK = qw( create_tempfile );


sub create_tempfile {
my ($filehandle, $filename) = &tempfile;
$filename =~ s/\\/\//g;
return ( $filehandle, $filename );
}


1;

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
10 changes: 2 additions & 8 deletions t/compilers/imcc/syn/file.t
Expand Up @@ -4,14 +4,14 @@

use strict;
use warnings;
use lib qw( . lib ../lib ../../lib );
use lib qw( lib );

use Cwd 'cwd';

use File::Spec;
use Test::More;

use File::Temp 'tempfile';
use Parrot::Test::Util 'create_tempfile';

use Parrot::Config;
use Parrot::Test tests => 14;
Expand Down Expand Up @@ -507,12 +507,6 @@ sub system_or_die {
print "# Return $rc\n";
}

sub create_tempfile {
my ($filehandle, $filename) = &tempfile;
$filename =~ s/\\/\//g;
return ( $filehandle, $filename );
}

# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Expand Down
4 changes: 2 additions & 2 deletions t/pmc/eval.t
Expand Up @@ -7,7 +7,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use File::Temp 'tempfile';
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test tests => 17;

Expand Down Expand Up @@ -512,7 +512,7 @@ CODE
ok
OUTPUT

my ($TEMP, $filename) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
my ($TEMP, $filename) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );

print $TEMP <<PIR;
.sub foo
Expand Down
6 changes: 3 additions & 3 deletions t/pmc/multidispatch.t
Expand Up @@ -7,7 +7,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use File::Temp 'tempfile';
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test tests => 45;

Expand Down Expand Up @@ -212,7 +212,7 @@ ok 2
-42
OUTPUT

my ($TEMP, $temp_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
my ($TEMP, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );

print $TEMP <<'EOF';
.sub Integer_divide_Integer
Expand Down Expand Up @@ -927,7 +927,7 @@ CODE
2
OUTPUT

($TEMP, $temp_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
($TEMP, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );

print $TEMP <<'EOF';
.namespace ["AInt"]
Expand Down
30 changes: 15 additions & 15 deletions t/pmc/sub.t
Expand Up @@ -7,7 +7,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use File::Temp 'tempfile';
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test tests => 65;
use Parrot::Config;
Expand Down Expand Up @@ -180,7 +180,7 @@ in sub
back
OUTPUT

my ($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
my ($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );
print $TEMP <<'EOF';
.pcc_sub _sub1:
say "in sub1"
Expand Down Expand Up @@ -209,7 +209,7 @@ found sub
in sub1
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub _sub1:
Expand Down Expand Up @@ -240,7 +240,7 @@ in sub1
back
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub _sub1:
Expand Down Expand Up @@ -291,7 +291,7 @@ in sub1
back
OUTPUT

my (undef, $temp_pbc) = tempfile( SUFFIX => '.pbc', UNLINK => 1 );
my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pbc', UNLINK => 1 );

system(".$PConfig{slash}parrot$PConfig{exe}", '-o', $temp_pbc, $temp_pasm);

Expand Down Expand Up @@ -412,7 +412,7 @@ CODE
ok
OUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub :load _sub1:
Expand All @@ -433,7 +433,7 @@ in sub1
back
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub _error:
Expand Down Expand Up @@ -470,7 +470,7 @@ in sub1
back
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub :load _sub1:
Expand Down Expand Up @@ -518,7 +518,7 @@ in sub2
back
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub _sub1:
Expand Down Expand Up @@ -566,7 +566,7 @@ in sub1
back
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub :load _sub1:
Expand Down Expand Up @@ -679,7 +679,7 @@ CODE
/too few arguments passed \(1\) - 2 params expected/
OUTPUT

($TEMP, $temp_pasm) = tempfile();
($TEMP, $temp_pasm) = create_tempfile();
print $TEMP <<'EOF';
.sub _sub1 :load
say "in sub1"
Expand All @@ -700,7 +700,7 @@ in sub1
back
OUTPUT

($TEMP, $temp_pasm) = tempfile();
($TEMP, $temp_pasm) = create_tempfile();
print $TEMP <<'EOF';
.sub _foo
print "error\n"
Expand All @@ -727,7 +727,7 @@ in sub1
back
OUTPUT

($TEMP, my $temp_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
($TEMP, my $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );

print $TEMP <<'EOF';
.sub _foo
Expand Down Expand Up @@ -975,7 +975,7 @@ ok
nofoo/
OUTPUT

($TEMP, my $l1_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
($TEMP, my $l1_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );
(my $l1_pbc = $l1_pir) =~ s/\.pir/.pbc/;

print $TEMP <<'EOF';
Expand All @@ -989,7 +989,7 @@ print $TEMP <<'EOF';
EOF
close $TEMP;

($TEMP, my $l2_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
($TEMP, my $l2_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );
(my $l2_pbc = $l2_pir) =~ s/\.pir/.pbc/;

print $TEMP <<'EOF';
Expand Down
4 changes: 2 additions & 2 deletions t/pmc/sys.t
Expand Up @@ -7,7 +7,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use File::Temp 'tempfile';
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test tests => 2;

Expand All @@ -25,7 +25,7 @@ Tests system dependend stuff
=cut

my (undef, $temp_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
my (undef, $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );

pir_output_is( <<"CODE", <<OUT, "spawnw, _config" );
Expand Down
10 changes: 5 additions & 5 deletions t/src/extend.t
Expand Up @@ -7,7 +7,7 @@ use warnings;
use lib qw( . lib ../lib ../../lib );

use Test::More;
use File::Temp 'tempfile';
use Parrot::Test::Util 'create_tempfile';

use Parrot::Test;
use Parrot::Config;
Expand Down Expand Up @@ -392,7 +392,7 @@ Wibble
6
OUTPUT

my ($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
my ($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub _sub1:
Expand All @@ -410,7 +410,7 @@ EOF
close $TEMP;

# compile to pbc
my (undef, $temp_pbc) = tempfile( SUFFIX => '.pbc', UNLINK => 1 );
my (undef, $temp_pbc) = create_tempfile( SUFFIX => '.pbc', UNLINK => 1 );
system(".$PConfig{slash}parrot$PConfig{exe}", '-o', $temp_pbc, $temp_pasm);

c_output_is( <<"CODE", <<'OUTPUT', 'call a parrot sub' );
Expand Down Expand Up @@ -471,7 +471,7 @@ hello in sub2
back
OUTPUT

($TEMP, $temp_pasm) = tempfile( SUFFIX => '.pasm', UNLINK => 1 );
($TEMP, $temp_pasm) = create_tempfile( SUFFIX => '.pasm', UNLINK => 1 );

print $TEMP <<'EOF';
.pcc_sub _sub1:
Expand Down Expand Up @@ -543,7 +543,7 @@ caught
back
OUTPUT

($TEMP, my $temp_pir) = tempfile( SUFFIX => '.pir', UNLINK => 1 );
($TEMP, my $temp_pir) = create_tempfile( SUFFIX => '.pir', UNLINK => 1 );

print $TEMP <<'EOF';
.sub main :main
Expand Down

0 comments on commit 2abaa9d

Please sign in to comment.