App-Fetchware
view release on metacpan or search on metacpan
t/App-Fetchware-Util.t view on Meta::CPAN
EOM
print_ok(sub {vmsg(1,2,3,4,5,6,7,8,9,0,"\n")},
<<EOM, 'test vmsg() many args success.');
1234567890
EOM
print_ok(sub {vmsg "Testing 1...2...3!!!\n"},
<<EOM, 'test vmsg success.');
Testing 1...2...3!!!
EOM
print_ok(sub {vmsg "Testing\n", "1...2...3!!!\n"},
<<EOM, 'test vmsg 2 args success.');
Testing
1...2...3!!!
EOM
print_ok(sub {vmsg 1,2,3,4,5,6,7,8,9,0,"\n"},
<<EOM, 'test vmsg many args success.');
1234567890
EOM
# Test -q (quite) mode works.
# Set bin/fetchware's $quiet to true.
$fetchware::quiet = 1;
ok(sub{vmsg 'Did I print anything???'}->() eq undef,
'test vmsg quiet mode success.');
};
subtest 'test run_prog()' => sub {
# Set bin/fetchware's $quiet to false.
$fetchware::quiet = 0;
# Test using perl itself, because what other program is guaranteed to
# be availabe on all platforms fetchware supports?
# The insane >> thing is a "right shift" operator, which shifts the value of
# system()'s return value 8 bits right, yielding the proper perl return
# value as bash would return it in its $? (Not Perl's $?, which is the same
# as system()'s return value.). And then it is tested if it ran successfully
# in which case it would be 0, which means it ran successfully. See perldoc
# system for more.
ok(run_prog("$Config{perlpath}", '-e print "Testing 1...2...3!!!\n"') >> 8 == 0,
'test run_prog() success');
# Set bin/fetchware's $quiet to true.
$fetchware::quiet = 1;
ok(run_prog("$Config{perlpath}", '-e print "Testing 1...2...3!!!\n"') >> 8 == 0,
'test run_prog() success');
# Set bin/fetchware's $quiet to false.
$fetchware::quiet = 0;
};
subtest 'test create_tempdir()' => sub {
# Create my own original_cwd(), because it gets tainted, because I chdir
# more than just once.
my $original_cwd = cwd();
# Test create_tempdir() successes.
my $temp_dir = create_tempdir();
ok(-e $temp_dir, 'checked create_tempdir() success.');
ok(-e 'fetchware.sem', 'checked fetchware semaphore creation.');
# chdir back to original_cwd(), so that this tempdir can be deleted.
chdir original_cwd() or fail("Failed to chdir back to original_cwd()!");
$temp_dir = create_tempdir(KeepTempDir => 1);
ok(-e $temp_dir, 'checked create_tempdir() KeepTempDir success.');
ok(-e 'fetchware.sem', 'checked fetchware semaphore creation.');
note "TEMPDIR[$temp_dir]";
# Cleanup $temp_dir, because this one won't automatically be cleaned up.
unlink 'fetchware.sem' or fail("Failed to delete 'fetchware.sem'! [$!]");
chdir original_cwd() or fail("Failed to chdir back to original_cwd()!");
rmdir $temp_dir or fail("Failed to delete temp_dir[$temp_dir]! [$!]");
# Test create_tempdir() successes with a custom temp_dir set.
$temp_dir = create_tempdir(TempDir => tmpdir());
ok(-e $temp_dir, 'checked create_tempdir() success.');
# Cleanup $temp_dir, because this one won't automatically be cleaned up.
unlink 'fetchware.sem' or fail("Failed to delete 'fetchware.sem'! [$!]");
chdir original_cwd() or fail("Failed to chdir back to original_cwd()!");
rmdir $temp_dir or fail("Failed to delete temp_dir[$temp_dir]! [$!]");
$temp_dir = create_tempdir(KeepTempDir => 1);
ok(-e $temp_dir, 'checked create_tempdir() KeepTempDir success.');
ok(-e 'fetchware.sem', 'checked fetchware semaphore creation.');
note "TEMPDIR[$temp_dir]";
# Cleanup $temp_dir, because this one won't automatically be cleaned up.
unlink 'fetchware.sem' or fail("Failed to delete 'fetchware.sem'! [$!]");
chdir original_cwd() or fail("Failed to chdir back to original_cwd()!");
rmdir $temp_dir or fail("Failed to delete temp_dir[$temp_dir]! [$!]");
# Test create_tempdir() failure
eval_ok( sub {create_tempdir(
TempDir => 'doesnotexist' . int(rand(238378290)))},
<<EOE, 'tested create_tempdir() temp_dir does not exist failure.');
App-Fetchware: run-time error. Fetchware tried to use File::Temp's tempdir()
subroutine to create a temporary file, but tempdir() threw an exception. That
exception was []. See perldoc App::Fetchware.
EOE
#chdir back to $original_cwd, so that File::Temp's END block can delete
#this last temp_dir. Otherwise, a warning is printed from File::Temp about
#this.
chdir original_cwd() or fail("Failed to chdir back to [@{[original_cwd]}]!");
};
subtest 'test cleanup_tempdir()' => sub {
# Create a tempdir to test cleaning it up.
my $temp_dir = create_tempdir();
ok(-e $temp_dir, 'checked create_tempdir() success.');
( run in 0.513 second using v1.01-cache-2.11-cpan-39bf76dae61 )