Refactor LC_NUMERIC test out of t/run/fresh_perl.t
authorNiko Tyni <ntyni@debian.org>
Wed, 27 Oct 2010 06:49:38 +0000 (09:49 +0300)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 27 Oct 2010 12:50:18 +0000 (05:50 -0700)
Neither lib/locale.t nor t/run/fresh_perl.t should be used for new tests,
so take the locale related tests and the setup code from fresh_perl.t
to make ground for more.

MANIFEST
t/run/fresh_perl.t
t/run/locale.t [new file with mode: 0644]

index 22d4ca6..c19bb4b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4802,6 +4802,7 @@ t/re/uniprops.t                   Test unicode \p{} regex constructs
 t/run/cloexec.t                        Test close-on-exec.
 t/run/exit.t                   Test perl's exit status.
 t/run/fresh_perl.t             Tests that require a fresh perl.
+t/run/locale.t         Tests related to locale handling
 t/run/noswitch.t               Test aliasing ARGV for other switch tests
 t/run/runenv.t                 Test if perl honors its environment variables.
 t/run/script.t                 See if script invocation works
index 3666f09..927d7f6 100644 (file)
@@ -565,42 +565,6 @@ EOT
 EXPECT
 ok
 ########
-# This test is here instead of lib/locale.t because
-# the bug depends on in the internal state of the locale
-# settings and pragma/locale messes up that state pretty badly.
-# We need a "fresh run".
-BEGIN {
-    eval { require POSIX };
-    if ($@) {
-       exit(0); # running minitest?
-    }
-}
-use Config;
-my $have_setlocale = $Config{d_setlocale} eq 'define';
-$have_setlocale = 0 if $@;
-# Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
-# and mingw32 uses said silly CRT
-$have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
-exit(0) unless $have_setlocale;
-my @locales;
-if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
-    while(<LOCALES>) {
-        chomp;
-        push(@locales, $_);
-    }
-    close(LOCALES);
-}
-exit(0) unless @locales;
-for (@locales) {
-    use POSIX qw(locale_h);
-    use locale;
-    setlocale(LC_NUMERIC, $_) or next;
-    my $s = sprintf "%g %g", 3.1, 3.1;
-    next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
-    print "$_ $s\n";
-}
-EXPECT
-########
 # [ID 20001202.002] and change #8066 added 'at -e line 1';
 # reversed again as a result of [perl #17763]
 die qr(x)
diff --git a/t/run/locale.t b/t/run/locale.t
new file mode 100644 (file)
index 0000000..9f9d32c
--- /dev/null
@@ -0,0 +1,50 @@
+#!./perl
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+    require './test.pl';    # for fresh_perl_is() etc
+}
+
+use strict;
+
+########
+# This test is here instead of lib/locale.t because
+# the bug depends on in the internal state of the locale
+# settings and pragma/locale messes up that state pretty badly.
+# We need a "fresh run".
+BEGIN {
+    eval { require POSIX };
+    if ($@) {
+       skip_all("could not load the POSIX module"); # running minitest?
+    }
+}
+use Config;
+my $have_setlocale = $Config{d_setlocale} eq 'define';
+$have_setlocale = 0 if $@;
+# Visual C's CRT goes silly on strings of the form "en_US.ISO8859-1"
+# and mingw32 uses said silly CRT
+$have_setlocale = 0 if (($^O eq 'MSWin32' || $^O eq 'NetWare') && $Config{cc} =~ /^(cl|gcc)/i);
+skip_all("no setlocale available") unless $have_setlocale;
+my @locales;
+if (-x "/usr/bin/locale" && open(LOCALES, "/usr/bin/locale -a 2>/dev/null|")) {
+    while(<LOCALES>) {
+        chomp;
+        push(@locales, $_);
+    }
+    close(LOCALES);
+}
+skip_all("no locales available") unless @locales;
+
+plan tests => &last;
+fresh_perl_is("for (qw(@locales)) {\n" . <<'EOF',
+    use POSIX qw(locale_h);
+    use locale;
+    setlocale(LC_NUMERIC, "$_") or next;
+    my $s = sprintf "%g %g", 3.1, 3.1;
+    next if $s eq '3.1 3.1' || $s =~ /^(3.+1) \1$/;
+    print "$_ $s\n";
+}
+EOF
+    "", {}, "no locales where LC_NUMERIC breaks");
+
+sub last { 1 }