Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert tests to Test::More #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified MANIFEST
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ my $test_requires = $ExtUtils::MakeMaker::VERSION >= 6.64
? 'TEST_REQUIRES'
: 'PREREQ_PM';

$param{$test_requires}{'Test'} = 0;
$param{$test_requires}{'Test::More'} = 0;
$param{$test_requires}{'File::Temp'} = 0;

WriteMakefile(%param);
4 changes: 1 addition & 3 deletions t/CodePage.t
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use strict;
use Test;
use Test::More tests => 8;
use Win32;

plan tests => 8;

my $ansicp = Win32::GetACP();
ok($ansicp > 0 && $ansicp <= 65001);

Expand Down
6 changes: 2 additions & 4 deletions t/CreateFile.t
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use strict;
use Test;
use Test::More tests => 15;
use Win32;

my $path = "testing-$$";
rmdir($path) if -d $path;
unlink($path) if -f $path;

plan tests => 15;

ok(!-d $path);
ok(!-f $path);

Expand All @@ -22,7 +20,7 @@ ok(!-d $path);

ok(Win32::CreateFile($path));
ok(-f $path);
ok(-s $path, 0);
is(-s $path, 0);

ok(!Win32::CreateDirectory($path));
ok(!Win32::CreateFile($path));
Expand Down
6 changes: 2 additions & 4 deletions t/ExpandEnvironmentStrings.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use strict;
use Test;
use Test::More tests => 1;
use Win32;

plan tests => 1;

ok(Win32::ExpandEnvironmentStrings("%WINDIR%"), $ENV{WINDIR});
is(Win32::ExpandEnvironmentStrings("%WINDIR%"), $ENV{WINDIR});
29 changes: 16 additions & 13 deletions t/GetCurrentThreadId.t
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
use strict;
use Config qw(%Config);
use Test;
use Test::More;
use Win32;

my $fork_emulation = $Config{ccflags} =~ /PERL_IMPLICIT_SYS/;

my $tests = $fork_emulation ? 4 : 2;
plan tests => $tests;
plan tests => $fork_emulation ? 4 : 2;

my $pid = $$+0; # make sure we don't copy any magic to $pid

if ($^O eq "cygwin") {
skip(!defined &Cygwin::pid_to_winpid,
Cygwin::pid_to_winpid($pid),
Win32::GetCurrentProcessId());
SKIP: {
skip 'Cygwin::pid_to_winpid is not available', 1
if !defined &Cygwin::pid_to_winpid;

is(Cygwin::pid_to_winpid($pid), Win32::GetCurrentProcessId());
}
}
else {
ok($pid, Win32::GetCurrentProcessId());
is($pid, Win32::GetCurrentProcessId());
}

if ($fork_emulation) {
# This test relies on the implementation detail that the fork() emulation
# uses the negative value of the thread id as a pseudo process id.
if (my $child = fork) {
waitpid($child, 0);
exit 0;
Test::More->builder->no_ending(1);
waitpid($child, 0);
exit $?;
}
ok(-$$, Win32::GetCurrentThreadId());
is(-$$, Win32::GetCurrentThreadId());

# GetCurrentProcessId() should still return the real PID
ok($pid, Win32::GetCurrentProcessId());
ok($$ != Win32::GetCurrentProcessId());
is($pid, Win32::GetCurrentProcessId());
isnt($$, Win32::GetCurrentProcessId());
}
else {
# here we just want to see something.
ok(Win32::GetCurrentThreadId() > 0);
cmp_ok(Win32::GetCurrentThreadId(), '>', 0);
}
9 changes: 4 additions & 5 deletions t/GetFileVersion.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use strict;
use Test;
use Test::More;
use Win32;

unless (defined &Win32::BuildNumber) {
print "1..0 # Skip: Only ActivePerl seems to set the perl.exe fileversion\n";
exit;
plan skip_all => 'Only ActivePerl seems to set the perl.exe fileversion';
}

plan tests => 2;
Expand All @@ -13,6 +12,6 @@ my @version = Win32::GetFileVersion($^X);
my $version = $version[0] + $version[1] / 1000 + $version[2] / 1000000;

# numify $] because it is a version object in 5.10 which will stringify with trailing 0s
ok($version, 0+$]);
is($version, 0+$]);

ok($version[3], int(Win32::BuildNumber()));
is($version[3], int(Win32::BuildNumber()));
6 changes: 2 additions & 4 deletions t/GetFolderPath.t
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use strict;
use Test;
use Test::More tests => 1;
use Win32;

plan tests => 1;

# "windir" exists back to Win9X; "SystemRoot" only exists on WinNT and later.
ok(Win32::GetFolderPath(Win32::CSIDL_WINDOWS), $ENV{WINDIR});
is(Win32::GetFolderPath(Win32::CSIDL_WINDOWS), $ENV{WINDIR});
36 changes: 17 additions & 19 deletions t/GetFullPathName.t
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
use strict;
use Test;
use Test::More tests => 16;
use Win32;

plan tests => 16;

my $cwd = Win32::GetCwd;
my @cwd = split/\\/, $cwd;
my $file = pop @cwd;
my $dir = join('\\', @cwd);

ok(scalar Win32::GetFullPathName('.'), $cwd);
ok((Win32::GetFullPathName('.'))[0], "$dir\\");
ok((Win32::GetFullPathName('.'))[1], $file);
is(scalar Win32::GetFullPathName('.'), $cwd);
is((Win32::GetFullPathName('.'))[0], "$dir\\");
is((Win32::GetFullPathName('.'))[1], $file);

ok((Win32::GetFullPathName('./'))[0], "$cwd\\");
ok((Win32::GetFullPathName('.\\'))[0], "$cwd\\");
ok((Win32::GetFullPathName('./'))[1], "");
is((Win32::GetFullPathName('./'))[0], "$cwd\\");
is((Win32::GetFullPathName('.\\'))[0], "$cwd\\");
is((Win32::GetFullPathName('./'))[1], "");

ok(scalar Win32::GetFullPathName($cwd), $cwd);
ok((Win32::GetFullPathName($cwd))[0], "$dir\\");
ok((Win32::GetFullPathName($cwd))[1], $file);
is(scalar Win32::GetFullPathName($cwd), $cwd);
is((Win32::GetFullPathName($cwd))[0], "$dir\\");
is((Win32::GetFullPathName($cwd))[1], $file);

ok(scalar Win32::GetFullPathName(substr($cwd,2)), $cwd);
ok((Win32::GetFullPathName(substr($cwd,2)))[0], "$dir\\");
ok((Win32::GetFullPathName(substr($cwd,2)))[1], $file);
is(scalar Win32::GetFullPathName(substr($cwd,2)), $cwd);
is((Win32::GetFullPathName(substr($cwd,2)))[0], "$dir\\");
is((Win32::GetFullPathName(substr($cwd,2)))[1], $file);

ok(scalar Win32::GetFullPathName('/Foo Bar/'), substr($cwd,0,2)."\\Foo Bar\\");
is(scalar Win32::GetFullPathName('/Foo Bar/'), substr($cwd,0,2)."\\Foo Bar\\");

chdir(my $dird = $dir !~ /^[A-Z]:$/ ? $dir : "$dir\\");
ok(scalar Win32::GetFullPathName('.'), $dird);
is(scalar Win32::GetFullPathName('.'), $dird);

ok((Win32::GetFullPathName($file))[0], "$dir\\");
ok((Win32::GetFullPathName($file))[1], $file);
is((Win32::GetFullPathName($file))[0], "$dir\\");
is((Win32::GetFullPathName($file))[1], $file);
8 changes: 2 additions & 6 deletions t/GetLongPathName.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use strict;
use Test;
use Test::More;
use Win32;

my @paths = qw(
Expand Down Expand Up @@ -43,11 +43,7 @@ my %expect;

plan tests => scalar(@paths);

my $i = 1;
for (@paths) {
my $got = Win32::GetLongPathName($_);
print "# '$_' => expect '$expect{$_}' => got '$got'\n";
print "not " unless $expect{$_} eq $got;
print "ok $i\n";
++$i;
is $expect{$_}, $got;
}
7 changes: 2 additions & 5 deletions t/GetOSVersion.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use strict;
use Test;
use Test::More tests => 1;
use Win32;

plan tests => 1;

my $scalar = Win32::GetOSVersion();
my @array = Win32::GetOSVersion();

print "not " unless $scalar == $array[4];
print "ok 1\n";
is $scalar, $array[4];
9 changes: 4 additions & 5 deletions t/GetShortPathName.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use strict;
use Test;
use Win32;

BEGIN {
Expand All @@ -8,21 +7,21 @@ BEGIN {
unlink("8dot3test_canary_GetShortPathName $$");
if ( length $canary > 12 ) {
print "1..0 # Skip: The system and/or current volume is not configured to support short names.\n";
exit 0;
exit 0;
}
}

use Test::More tests => 5;

my $path = "Long Path $$";
unlink($path);
END { unlink $path }

plan tests => 5;

Win32::CreateFile($path);
ok(-f $path);

my $short = Win32::GetShortPathName($path);
ok($short, qr/^\S{1,8}(\.\S{1,3})?$/);
like($short, qr/^\S{1,8}(\.\S{1,3})?$/);
ok(-f $short);

unlink($path);
Expand Down
8 changes: 3 additions & 5 deletions t/GuidGen.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use strict;
use Test;
use Test::More tests => 3;
use Win32;

plan tests => 3;

my $guid1 = Win32::GuidGen();
my $guid2 = Win32::GuidGen();

# {FB9586CD-273B-43BE-A20C-485A6BD4FCD6}
ok($guid1, qr/^{\w{8}(-\w{4}){3}-\w{12}}$/);
ok($guid2, qr/^{\w{8}(-\w{4}){3}-\w{12}}$/);
like($guid1, qr/^{\w{8}(-\w{4}){3}-\w{12}}$/);
like($guid2, qr/^{\w{8}(-\w{4}){3}-\w{12}}$/);

# Every GUID is unique
ok($guid1 ne $guid2);
60 changes: 29 additions & 31 deletions t/HttpGetFile.t
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use strict;
use warnings;
use Test;
use Test::More;
use Win32;
use Digest::SHA;

my $tmpfile = "http-download-test-$$.tgz";
END { 1 while unlink $tmpfile; }

unless (defined &Win32::HttpGetFile) {
print "1..0 # Skip: gcc before 4.8 does not have winhttp library\n";
exit;
plan skip_all => 'gcc before 4.8 does not have winhttp library';
}

# We can only verify specific error messages with a known locale.
Expand All @@ -35,67 +34,66 @@ sub HttpGetFileList {
return ($ok, $message);
}

ok(HttpGetFile('nonesuch://example.com', 'NUL:'), "", "'nonesuch://' is not a real protocol");
ok($LastError, '12006', "correct error code for unrecognized protocol");
ok(HttpGetFile('http://!#@!&@$', 'NUL:'), "", "invalid URL");
ok($LastError, '12005', "correct error code for invalid URL");
is(HttpGetFile('nonesuch://example.com', 'NUL:'), "", "'nonesuch://' is not a real protocol");
is($LastError, '12006', "correct error code for unrecognized protocol");
is(HttpGetFile('http://!#@!&@$', 'NUL:'), "", "invalid URL");
is($LastError, '12005', "correct error code for invalid URL");

my ($ok, $message) = HttpGetFileList('nonesuch://example.com', 'NUL:');
ok($ok, "", "'nonesuch://' is not a real protocol");
if ($english_locale) {
ok($message, "The URL does not use a recognized protocol\r\n", "correct bad protocol message");
}
else {
skip("Cannot verify error on non-English locale setting");
is($ok, "", "'nonesuch://' is not a real protocol");
SKIP: {
skip "Cannot verify error on non-English locale setting", 1
if $english_locale;

is($message, "The URL does not use a recognized protocol\r\n", "correct bad protocol message");
}
ok($LastError, '12006', "correct error code for unrecognized protocol with list context return");
is($LastError, '12006', "correct error code for unrecognized protocol with list context return");

if ($ENV{PERL_WIN32_INTERNET_OK}) {
# The digest for version 0.57 should obviously stay the same even after new versions are released
ok(Win32::HttpGetFile('https://cpan.metacpan.org/authors/id/J/JD/JDB/Win32-0.57.tar.gz', $tmpfile),
is(Win32::HttpGetFile('https://cpan.metacpan.org/authors/id/J/JD/JDB/Win32-0.57.tar.gz', $tmpfile),
'1',
"successfully downloaded a tarball");

my $sha = Digest::SHA->new('sha1');
$sha->addfile($tmpfile, 'b');
ok($sha->hexdigest,
is($sha->hexdigest,
'44a6d7d1607d7267b0dbcacbb745cec204f1c1a4',
"downloaded tarball has correct digest");

my ($ok, $message) = HttpGetFileList('https://cpan.metacpan.org/authors/id/Z/ZZ/ZILCH/nonesuch.tar.gz', 'NUL:');
ok($ok, '', 'Download of nonexistent file from real site should fail with 404');
ok($LastError - 1e9, '404', 'Correct 404 HTTP status for not found');
if ($english_locale) {
ok($message, 'Not Found', 'Should get text of 404 message');
}
else {
skip("Cannot verify error on non-English locale setting");
is($ok, '', 'Download of nonexistent file from real site should fail with 404');
is($LastError - 1e9, '404', 'Correct 404 HTTP status for not found');
SKIP: {
skip "Cannot verify error on non-English locale setting", 1
if $english_locale;
is($message, 'Not Found', 'Should get text of 404 message');
}
# Since all GitHub downloads use redirects, we can test that they work.
1 while unlink $tmpfile;
ok(Win32::HttpGetFile('https://github.com/perl-libwin32/win32/archive/refs/tags/v0.57.zip', $tmpfile),
is(Win32::HttpGetFile('https://github.com/perl-libwin32/win32/archive/refs/tags/v0.57.zip', $tmpfile),
'1',
"successfully downloaded a zipball via redirect");

$sha = Digest::SHA->new('sha1');
$sha->addfile($tmpfile, 'b');
ok($sha->hexdigest,
is($sha->hexdigest,
'9d282e2292e67fb2e25422dfb190474e30a38de3',
"downloaded GitHub zip archive has correct digest");

ok(HttpGetFile('https://self-signed.badssl.com/index.html', 'NUL:'),
is(HttpGetFile('https://self-signed.badssl.com/index.html', 'NUL:'),
'',
'Cannot download from site with self-signed cert without ignoring cert errors');
ok($LastError, '12175', "correct code for ERROR_WINHTTP_SECURE_FAILURE with self-signed certificate");
ok(HttpGetFile('https://self-signed.badssl.com/index.html', 'NUL:', 1),
is($LastError, '12175', "correct code for ERROR_WINHTTP_SECURE_FAILURE with self-signed certificate");
is(HttpGetFile('https://self-signed.badssl.com/index.html', 'NUL:', 1),
'1',
'Can download from site with self-signed cert using ignore cert errors parameter');

ok(HttpGetFile('https://expired.badssl.com/index.html', 'NUL:'),
is(HttpGetFile('https://expired.badssl.com/index.html', 'NUL:'),
'',
'Cannot download from site with expired cert without ignoring cert errors');
ok($LastError, '12175', "correct code for ERROR_WINHTTP_SECURE_FAILURE with expired certificate");
ok(HttpGetFile('https://expired.badssl.com/index.html', 'NUL:', 1),
is($LastError, '12175', "correct code for ERROR_WINHTTP_SECURE_FAILURE with expired certificate");
is(HttpGetFile('https://expired.badssl.com/index.html', 'NUL:', 1),
'1',
'Can download from site with expired cert using ignore cert errors parameter');
}
Loading