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

t/indexer.t may fail (non-English locale?) #25

Closed
eserte opened this issue Jun 15, 2016 · 6 comments
Closed

t/indexer.t may fail (non-English locale?) #25

eserte opened this issue Jun 15, 2016 · 6 comments

Comments

@eserte
Copy link

eserte commented Jun 15, 2016

Some of my smokers report the following failure, probably only when a German locale is in effect, and probably also only for perl <= 5.22:

#   Failed test 'Should get exception with file names for bad copy'
#   at t/indexer.t line 166.
# expecting: Regexp ((?^:Cannot copy t\/test_doc_root\/mirror\/dist\/nonexistent\/0\.1\.0\/nonexistent\-0\.1\.0\.zip to t\/test_doc_root\/dist\/nonexistent\/0\.1\.0\/nonexistent\-0\.1\.0\.zip: No such file or directory))
# found: Cannot copy t/test_doc_root/mirror/dist/nonexistent/0.1.0/nonexistent-0.1.0.zip to t/test_doc_root/dist/nonexistent/0.1.0/nonexistent-0.1.0.zip: Datei oder Verzeichnis nicht gefunden
# Looks like you failed 1 test of 249.
t/indexer.t .. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/249 subtests 
@theory
Copy link
Member

theory commented Jun 15, 2016

Hrm. Does this fix it?

diff --git a/t/indexer.t b/t/indexer.t
index 335b9db..550c2db 100644
--- a/t/indexer.t
+++ b/t/indexer.t
@@ -162,7 +162,7 @@ file_not_exists_ok(
 $meta->{name} = 'nonexistent';
 my $src = catfile $api->mirror_root, qw(dist nonexistent 0.1.0 nonexistent-0.1.0.zip);
 my $dst = catfile $api->doc_root,    qw(dist nonexistent 0.1.0 nonexistent-0.1.0.zip);
-throws_ok { $indexer->copy_files($params ) }
+throws_ok { local $ENV{LANG} = 'en_US'; $indexer->copy_files($params ) }
     qr{Cannot copy \Q$src\E to \Q$dst\E: No such file or directory},
     'Should get exception with file names for bad copy';
 $meta->{name} = 'pair';

@theory
Copy link
Member

theory commented Jun 15, 2016

Or maybe set $LANG to "C"?

@eserte
Copy link
Author

eserte commented Jun 15, 2016

LC_ALL has higher precedence than LANG, so I propose to set that environment variable. Also, setting locale-specific environment variables within a perl script does not have an effect to the process itself, only to spawned children. But one can use POSIX::setlocale instead:

diff --git a/t/indexer.t b/t/indexer.t
index 335b9db..99bdf6d 100644
--- a/t/indexer.t
+++ b/t/indexer.t
@@ -16,6 +16,13 @@ use Test::MockModule;
 use Archive::Zip;
 use utf8;

+BEGIN {
+    if ($] < 5.022) {
+        require POSIX;
+        POSIX::setlocale(&POSIX::LC_ALL, 'C');
+    }
+}
+
 my $CLASS;
 BEGIN {
     $File::Copy::Recursive::KeepMode = 0;

I am quite positive that POSIX.pm is available in all perl installations nowadays, but maybe you want to be sure and don't fail here if POSIX.pm is missing, in this case you would need another eval block here.

@theory
Copy link
Member

theory commented Jun 15, 2016

Sqitch already requires POSIX, so I think we're good there. Does your patch fix the issue?

@eserte
Copy link
Author

eserte commented Jun 15, 2016

Yes, I checked on a linux system with perl 5.20.3.

@theory theory closed this as completed in af96385 Jun 15, 2016
@theory
Copy link
Member

theory commented Jun 15, 2016

Thank you, as always @eserte!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants