Skip to content

Commit 7aec412

Browse files
committed
Fix HttpGetFile.t locale handling
Setting the POSIX locale does not affect what FormatMessage does, so in order to test specific error messages, we need to make sure we are in a Windows locale with known message values.
1 parent 88807a7 commit 7aec412

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

t/HttpGetFile.t

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use warnings;
33
use Test;
44
use Win32;
55
use Digest::SHA;
6-
use POSIX qw(locale_h);
7-
setlocale(LC_ALL, "C"); # to make error messages predictable
86

97
my $tmpfile = "http-download-test-$$.tgz";
108
END { 1 while unlink $tmpfile; }
@@ -14,6 +12,9 @@ unless (defined &Win32::HttpGetFile) {
1412
exit;
1513
}
1614

15+
# We can only verify specific error messages with a known locale.
16+
my $english_locale = (Win32::FormatMessage(1) eq "Incorrect function.\r\n");
17+
1718
# We may not always have an internet connection, so don't
1819
# attempt remote connections unless the user has done
1920
# set PERL_WIN32_INTERNET_OK=1
@@ -41,7 +42,12 @@ ok($LastError, '12005', "correct error code for invalid URL");
4142

4243
my ($ok, $message) = HttpGetFileList('nonesuch://example.com', 'NUL:');
4344
ok($ok, "", "'nonesuch://' is not a real protocol");
44-
ok($message, "The URL does not use a recognized protocol\r\n", "correct bad protocol message");
45+
if ($english_locale) {
46+
ok($message, "The URL does not use a recognized protocol\r\n", "correct bad protocol message");
47+
}
48+
else {
49+
skip("Cannot verify error on non-English locale setting");
50+
}
4551
ok($LastError, '12006', "correct error code for unrecognized protocol with list context return");
4652

4753
if ($ENV{PERL_WIN32_INTERNET_OK}) {
@@ -58,8 +64,12 @@ if ($ENV{PERL_WIN32_INTERNET_OK}) {
5864

5965
my ($ok, $message) = HttpGetFileList('https://cpan.metacpan.org/authors/id/Z/ZZ/ZILCH/nonesuch.tar.gz', 'NUL:');
6066
ok($ok, '', 'Download of nonexistent file from real site should fail with 404');
61-
ok($message, 'Not Found', 'Should get text of 404 message');
62-
67+
if ($english_locale) {
68+
ok($message, 'Not Found', 'Should get text of 404 message');
69+
}
70+
else {
71+
skip("Cannot verify error on non-English locale setting");
72+
}
6373
# Since all GitHub downloads use redirects, we can test that they work.
6474
ok(Win32::HttpGetFile('https://github.com/perl-libwin32/win32/archive/refs/tags/v0.57.zip', $tmpfile),
6575
'1',

0 commit comments

Comments
 (0)