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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
#!/usr/bin/env perl
use 5.014;
use strict;
use warnings;
use autodie;
use Getopt::Long qw/ GetOptions /;
use Env::Path ();
use Path::Tiny qw/ path /;
use File::Basename qw/ basename /;
my $bindir = path(__FILE__)->parent;
my $abs_bindir = $bindir->absolute;
# Whether to use prove instead of runprove.
my $use_prove = $ENV{FCS_USE_TEST_RUN} ? 0 : 1;
my $num_jobs = $ENV{TEST_JOBS};
sub _is_parallized
{
return ( $use_prove && $num_jobs );
}
sub _calc_prove
{
return [ 'prove',
( defined($num_jobs) ? sprintf( "-j%d", $num_jobs ) : () ) ];
}
my $exit_success;
sub run_tests
{
my $tests = shift;
my @cmd = ( ( $use_prove ? @{ _calc_prove() } : 'runprove' ), @$tests );
if ( $ENV{RUN_TESTS_VERBOSE} )
{
print "Running [@cmd]\n";
}
# Workaround for Windows spawning-SNAFU.
my $exit_code = system(@cmd);
exit( $exit_success ? 0 : $exit_code ? (-1) : 0 );
}
my $tests_glob = "*.{t.exe,py,t}";
my $exclude_re_s;
my @execute;
GetOptions(
'--exclude-re=s' => \$exclude_re_s,
'--execute|e=s' => \@execute,
'--exit0!' => \$exit_success,
'--glob=s' => \$tests_glob,
'--prove!' => \$use_prove,
'--jobs|j=n' => \$num_jobs,
) or die "Wrong opts - $!";
sub myglob
{
return glob( shift . "/$tests_glob" );
}
{
my $fcs_path = Path::Tiny->cwd;
local $ENV{FCS_PATH} = $fcs_path;
local $ENV{FCS_SRC_PATH} = $abs_bindir;
local $ENV{PYTHONDONTWRITEBYTECODE} = '1';
local $ENV{FCS_TEST_TAGS} = join ' ',
sort { $a cmp $b }
( path('.')->child(qw/t TAGS.txt/)->slurp_utf8 =~ /([a-zA-Z_0-9]+)/g );
my $preset_dest = path('.')->child( "t", "Presets" );
my $preset_src = $abs_bindir->child("Presets");
my $pset_files_dest = $preset_dest->child("presets");
my $pset_files_src = $preset_src->child("presets");
$pset_files_dest->mkpath;
foreach my $f ( path($pset_files_src)->children(qr{\.sh\z}) )
{
$f->copy( $pset_files_dest->child( $f->basename ) );
}
my $files_dest_abs = $pset_files_dest->child("STUB.TXT")->absolute;
$files_dest_abs =~ s{STUB\.TXT\z}{};
my $testing_preset_rc = $preset_dest->child("presetrc")->absolute;
$testing_preset_rc->spew_utf8(
$fcs_path->child( "Presets", "presetrc" )->slurp_utf8 =~
s{^(dir=)([^\n]*)}{$1$files_dest_abs}gmrs );
local $ENV{FREECELL_SOLVER_PRESETRC} = $testing_preset_rc;
local $ENV{FREECELL_SOLVER_QUIET} = 1;
Env::Path->PATH->Prepend(
Path::Tiny->cwd->child("board_gen"),
$abs_bindir->child( "t", "scripts" ),
);
my $IS_WIN = ( $^O eq "MSWin32" );
Env::Path->CPATH->Prepend( $abs_bindir, );
Env::Path->LD_LIBRARY_PATH->Prepend($fcs_path);
if ($IS_WIN)
{
# For the shared objects.
Env::Path->PATH->Append($fcs_path);
}
my $foo_lib_dir = $abs_bindir->child( "t", "lib" );
foreach my $add_lib ( Env::Path->PERL5LIB(), Env::Path->PYTHONPATH() )
{
$add_lib->Append($foo_lib_dir);
}
my $get_config_fn = sub {
my $basename = shift;
return $bindir->child( "t", "config", $basename )->absolute;
};
local $ENV{HARNESS_ALT_INTRP_FILE} = $get_config_fn->(
$IS_WIN
? "alternate-interpreters--mswin.yml"
: "alternate-interpreters.yml"
);
local $ENV{HARNESS_TRIM_FNS} = 'keep:1';
local $ENV{HARNESS_PLUGINS} = join(
' ', qw(
BreakOnFailure ColorSummary ColorFileVerdicts AlternateInterpreters
TrimDisplayedFilenames
)
);
my $is_ninja = ( -e "build.ninja" );
my $MAKE = $IS_WIN ? 'gmake' : 'make';
if ($is_ninja)
{
system( "ninja", "boards" );
}
else
{
if ( system( $MAKE, "-s", "boards" ) )
{
die "$MAKE failed";
}
}
chdir("t");
if ( !$is_ninja )
{
if ( system( $MAKE, "-s" ) )
{
die "$MAKE failed";
}
}
# Put the valgrind tests last, because they take a long time.
my @tests =
sort {
( ( ( $a =~ /valgrind/ ) <=> ( $b =~ /valgrind/ ) ) *
( _is_parallized() ? -1 : 1 ) )
|| ( basename($a) cmp basename($b) )
|| ( $a cmp $b )
} (
myglob('t'),
myglob('.'),
(
( $fcs_path ne $abs_bindir )
? ( myglob("$abs_bindir/t/t") )
: ()
),
);
if ( defined($exclude_re_s) )
{
my $re = qr/$exclude_re_s/ms;
@tests = grep { basename($_) !~ $re } @tests;
}
@tests = grep { basename($_) !~ /\A(?:lextab|yacctab)\.py\z/ } @tests;
if ( !$ENV{FCS_TEST_BUILD} )
{
@tests = grep { !/build-process/ } @tests;
}
if ( $ENV{FCS_TEST_WITHOUT_VALGRIND} )
{
@tests = grep { !/valgrind/ } @tests;
}
print STDERR <<"EOF";
FCS_PATH = $ENV{FCS_PATH}
FCS_SRC_PATH = $ENV{FCS_SRC_PATH}
FCS_TEST_TAGS = <$ENV{FCS_TEST_TAGS}>
EOF
if ( $ENV{FCS_TEST_SHELL} )
{
system("bash");
}
elsif (@execute)
{
system(@execute);
}
else
{
run_tests( \@tests );
}
}
__END__
=head1 COPYRIGHT AND LICENSE
This file is part of Freecell Solver. It is subject to the license terms in
the COPYING.txt file found in the top-level directory of this distribution
and at http://fc-solve.shlomifish.org/docs/distro/COPYING.html . No part of
Freecell Solver, including this file, may be copied, modified, propagated,
or distributed except according to the terms contained in the COPYING file.
Copyright (c) 2000 Shlomi Fish
=cut
|