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;
# 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'}) {
if ($ENV{'CYGWIN'} !~ /\b nodosfilewarning \b/x) {
$ENV{'CYGWIN'} = join(' ', $ENV{'CYGWIN'}, 'nodosfilewarning');
}
}
my $scriptno = 0;
for my $script (@script) {
next if not -e $script;
my $testno = 1;
my $ok = 0;
my $not_ok = 0;
if (my @result = qx{$^X $script}) {
if (my($tests) = shift(@result) =~ /^1..([0-9]+)/) {
for my $result (@result) {
if ($result =~ /^ok /) {
$ok++;
}
elsif ($result =~ /^not ok /) {
push @{$fail_testno[$scriptno]}, $testno;
$not_ok++;
}
$testno++;
}
if ($ok == $tests) {
printf("$script ok\n");
$ok_script++;
}
else {
printf("$script Failed %d/%d subtests\n", $not_ok, $ok+$not_ok);
$not_ok_script++;
}
}
}
$total_ok += $ok;
$total_not_ok += $not_ok;
$scriptno++;
}
if (scalar(@script) == $ok_script) {
printf <<'END', scalar(@script), $total_ok + $total_not_ok;
All tests successful.
Files=%d, Tests=%d
Result: PASS
END
}
else {
print <<'END';
Test Summary Report
-------------------
END
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\n", scalar(@script), $total_ok + $total_not_ok);
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);
}
}
sub check_usascii {
my($file) = @_;
if (open(FILE,$file)) {
while (<FILE>) {
if (not /^[\x0A\x20-\x7E]+$/) {
die "error not US-ASCII: $file, q(;_;)bad!!";
}
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.638 second using v1.01-cache-2.11-cpan-39bf76dae61 )