BATsh
view release on metacpan or search on metacpan
#-----------------------------------------------------------------------------
# $tar->add_files("$tardir/$file");
#-----------------------------------------------------------------------------
open(FH, $file) || die "Can't open file: $file\n"; #'
binmode FH;
local $/ = undef; # slurp mode
my $data = <FH>;
close FH;
#-----------------------------------------------------------------------------
# Kwalitee Indicator: buildtool_not_executable core
# The build tool (Build.PL/Makefile.PL) is executable. This is bad because
# you should specify which perl you want to use while installing.
#
# How to fix
# Change the permissions of Build.PL/Makefile.PL to not-executable.
#-----------------------------------------------------------------------------
my $tar = Archive::Tar->new;
if ($file =~ m/ (?: Build\.PL | Makefile\.PL ) \z/oxmsi) {
$tar->add_data("$tardir/$file", $data, {'mode' => 0664});
}
return $_[0];
}
}
# Test::Harness::runtests cannot work heavy load.
sub _runtests {
my @script = @_;
my @fail_testno = ();
my $ok_script = 0;
my $not_ok_script = 0;
my $total_ok = 0;
my $total_not_ok = 0;
my $total_skip = 0;
# cygwin warning:
# MS-DOS style path detected: C:/cpan/Char-X.XX
# Preferred POSIX equivalent is: /cygdrive/c/cpan/Char-X.XX
# CYGWIN environment variable option "nodosfilewarning" turns off this warning.
# Consult the user's guide for more details about POSIX paths: #'
# http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
if (exists $ENV{'CYGWIN'}) {
$ENV{'CYGWIN'} = join(' ', $ENV{'CYGWIN'}, 'nodosfilewarning');
}
}
my $start_time = time();
my $scriptno = 0;
for my $script (@script) {
next if not -e $script;
my $ok = 0;
my $not_ok = 0;
my $skip = 0;
if (my @result = qx{$^X $script}) {
if (my($tests) = shift(@result) =~ /^1..([0-9]+)/) {
for my $result (@result) {
# Read TAP test number directly to avoid offset from comment lines
if ($result =~ /^ok (\d+)/) {
my $tapno = $1;
if ($result =~ /\bSKIP\b/i) {
$skip++;
}
else {
$ok++;
}
}
elsif ($result =~ /^not ok (\d+)/) {
my $tapno = $1;
push @{$fail_testno[$scriptno]}, $tapno;
$not_ok++;
}
# TAP comment lines (^#) and other lines are silently ignored
}
if ($not_ok == 0) {
if ($skip > 0) {
printf("$script ok (skipped: %d)\n", $skip);
}
else {
printf("$script ok\n");
}
$ok_script++;
}
else {
printf("$script Failed %d/%d subtests\n", $not_ok, $ok+$not_ok+$skip);
$not_ok_script++;
}
}
}
$total_ok += $ok;
$total_not_ok += $not_ok;
$total_skip += $skip;
$scriptno++;
}
my $elapsed = time() - $start_time;
if (scalar(@script) == $ok_script) {
my $skip_msg = $total_skip > 0 ? " (skipped: $total_skip)" : '';
printf("All tests successful.\n");
printf("Files=%d, Tests=%d%s, %d wallclock secs\n",
scalar(@script), $total_ok + $total_not_ok + $total_skip,
$skip_msg, $elapsed);
printf("Result: PASS\n");
}
else {
print "\nTest Summary Report\n-------------------\n";
my $scriptno = 0;
for my $fail_testno (@fail_testno) {
if (defined $fail_testno) {
print $script[$scriptno], "\n";
print ' Failed test: ', join(', ', @{$fail_testno[$scriptno]}), "\n";
}
$scriptno++;
}
printf("Files=%d, Tests=%d, %d wallclock secs\n",
scalar(@script), $total_ok + $total_not_ok + $total_skip, $elapsed);
printf("Result: FAIL\n");
printf("Failed %d/%d test programs. %d/%d subtests failed.\n",
$not_ok_script, scalar(@script),
$total_not_ok, $total_ok + $total_not_ok + $total_skip);
}
}
######################################################################
# selfcheck: Perl 5.5.3 compat (--check1) and coding style (--check2)
#
# These routines check pmake.bat itself.
# All TAP harness, slurp, and scanner logic is embedded here
# so that no external modules beyond core are required.
######################################################################
t/0003-cmd-interpreter.t view on Meta::CPAN
));
_ok(( defined( $BATsh::Env::STORE{'CMD_T3'} ) ? $BATsh::Env::STORE{'CMD_T3'} : '' ) eq 'if_true',
'CMD3: IF condition true');
},
# CMD4: IF condition false
sub {
delete $BATsh::Env::STORE{'CMD_T4'};
BATsh->run_string(join("\n",
'SET CMD_T4=before',
'IF "1"=="2" SET CMD_T4=should_not_set',
));
_ok(( defined( $BATsh::Env::STORE{'CMD_T4'} ) ? $BATsh::Env::STORE{'CMD_T4'} : '' ) eq 'before',
'CMD4: IF condition false');
},
# CMD5: IF ... ( ... ) ELSE ( ... ) multiline
sub {
delete $BATsh::Env::STORE{'CMD_T5'};
BATsh->run_string(join("\n",
'IF "x"=="y" (',
t/0003-cmd-interpreter.t view on Meta::CPAN
'IF DEFINED CMD_T11_DEFINED SET CMD_T11_RESULT=defined_ok',
));
_ok(( defined( $BATsh::Env::STORE{'CMD_T11_RESULT'} ) ? $BATsh::Env::STORE{'CMD_T11_RESULT'} : '' ) eq 'defined_ok',
'CMD11: IF DEFINED');
},
# CMD12: IF NOT
sub {
delete $BATsh::Env::STORE{'CMD_T12'};
BATsh->run_string(join("\n",
'IF NOT "a"=="b" SET CMD_T12=not_ok',
));
_ok(( defined( $BATsh::Env::STORE{'CMD_T12'} ) ? $BATsh::Env::STORE{'CMD_T12'} : '' ) eq 'not_ok',
'CMD12: IF NOT condition');
},
# CMD13: SETLOCAL nested
# CMD_T13_L1 is set BETWEEN the two ENDLOCALs.
# The outer SETLOCAL was taken before CMD_T13_L1 existed, so ENDLOCAL
# will remove it (same as real cmd.exe behaviour).
# We verify the nested depth by checking CMD_T13 restores to L0.
sub {
$BATsh::Env::STORE{'CMD_T13'} = 'L0';
( run in 1.161 second using v1.01-cache-2.11-cpan-9581c071862 )