/
harness
155 lines (121 loc) · 4.15 KB
/
harness
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#! perl
=head1 NAME
languages/pipp/t/harness - A harness for Pipp
=head1 SYNOPSIS
perl t/harness
perl t/harness --with-phc
perl t/harness --with-pct
perl t/harness --verbose t/hello.t
=head1 DESCRIPTION
If I'm called with no args, I run the complete suite.
Otherwise I run the tests that were passed on the command line.
The options C<--with-pct> and C<--with-phc> select
the variant of Pipp. Default is the PCT variant, using the
Parrot Compiler Toolkit.
=cut
# pragmata
use strict;
use warnings;
use FindBin ();
use lib "$FindBin::Bin/../../../lib", "$FindBin::Bin/../lib", "$FindBin::Bin/../parrot/lib";
use Cwd ();
use File::Spec ();
use TAP::Harness 3.12; # support closures for the 'exec' option
use TAP::Harness::Archive 0.12;
use Getopt::Long;
use Parrot::Harness::Smoke;
my ( $send_to_smolder_flag, $archive_flag, $verbose_flag );
my ( $php_flag, $pct_flag, $phc_flag);
GetOptions(
'send-to-smolder' => \$send_to_smolder_flag,
'archive' => \$archive_flag,
'verbose' => \$verbose_flag,
'with-pct' => \$pct_flag,
'with-phc' => \$phc_flag,
'with-php' => \$php_flag,
);
my $hll = 'pipp';
my $verbosity = $verbose_flag ? 1 : $ENV{HARNESS_VERBOSE};
$verbosity ||= 0;
{
my $path_to_parrot = path_to_parrot();
my @cmd = ( "$path_to_parrot/parrot", 'pipp.pbc' );
if ( $php_flag ) {
@cmd = qw{ php-cgi -q -C -n } ;
}
elsif ( $phc_flag ) {
push @cmd, '--variant=phc';
}
my @files;
if ( scalar(@ARGV) ) {
# Someone specified tests for me to run.
@files = grep { -f $_ } @ARGV
}
else {
( undef, undef, my $current_dir ) = File::Spec->splitpath( Cwd::getcwd() );
if ( $current_dir eq $hll ) {
@files = glob( File::Spec->catfile( 't', '*/*.t' ) );
}
else {
die "Where am I?";
}
}
my $exec_sub
= sub {
my ( $harness, $test_file ) = @_;
# the directory t/embed contains only PIR test files
#return [ "$path_to_parrot/parrot pipp.pbc", '--run-pir', $test_file ] if $test_file =~ m!t/embed/.*[.]t$!;
return [ "$path_to_parrot/parrot", $test_file ] if $test_file =~ m!t/embed/.*[.]t$!;
# the directory t/pmc contains only PIR test files
#return [ "$path_to_parrot/parrot pipp.pbc", '--run-pir', $test_file ] if $test_file =~ m!t/pmc/.*[.]t$!;
return [ "$path_to_parrot/parrot", $test_file ] if $test_file =~ m!t/pmc/.*[.]t$!;
# the directory t/in_php contains only test scripts written in PHP
return [ @cmd, $test_file ] if $test_file =~ m!t/in_php/.*[.]t$!;
# all other directories contain test scripts written in Perl
return [ $^X, $test_file ];
};
if ( $archive_flag ) {
my %env_data = Parrot::Harness::Smoke::collect_test_environment_data();
my $report_file = ['pipp_test_run.tar.gz'];
my $harness = TAP::Harness::Archive->new(
{
exec => $exec_sub,
verbosity => $verbosity,
archive => $report_file->[0],
merge => 1,
extra_properties => \%env_data,
}
);
$harness->runtests(@files);
if ( $send_to_smolder_flag ) {
$env_data{report_file} = $report_file;
$env_data{project_id} = 10;
Parrot::Harness::Smoke::send_archive_to_smolder(%env_data);
}
}
else {
my $harness = TAP::Harness->new(
{
exec => $exec_sub,
verbosity => $verbosity,
}
);
$harness->runtests(@files);
}
}
sub path_to_parrot {
my $path = $INC{'Parrot/Config.pm'};
$path =~ s{ /lib/Parrot/Config.pm \z}{}xms;
return Cwd::realpath( $path );
}
=head1 SEE ALSO
F<languages/perl6/t/harness>
=head1 AUTHOR
Bernhard Schmalhofer - <Bernhard.Schmalhofer@gmx.de>
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: