Skip to content

Commit a955329

Browse files
committed
I18N-Langinfo/t/Langinfo.t: Reinstate tests, modernize
The comments say that a bunch of tests were disabled due to the poor support of nl_langinfo() at the time, 2001. I haven't seen these issues lately, and so am reinstating many of the tests, using the modern Test::More that the rest of the file in the meantime had been updated to use. The tests that weren't reinstated were because results for them may vary by platform.
1 parent f1d36e7 commit a955329

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

ext/I18N-Langinfo/t/Langinfo.t

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@ plan skip_all => "I18N::Langinfo or POSIX unavailable"
88

99
my @constants = qw(ABDAY_1 DAY_1 ABMON_1 MON_1 RADIXCHAR AM_STR THOUSEP D_T_FMT D_FMT T_FMT);
1010

11-
plan tests => 1 + 3 * @constants;
11+
my %want =
12+
(
13+
ABDAY_1 => "Sun",
14+
DAY_1 => "Sunday",
15+
ABMON_1 => "Jan",
16+
MON_1 => "January",
17+
RADIXCHAR => ".",
18+
THOUSEP => "",
19+
);
20+
21+
my @want = sort keys %want;
22+
23+
plan tests => 1 + 3 * @constants + keys(@want);
1224

1325
use_ok('I18N::Langinfo', 'langinfo', @constants);
1426

27+
use POSIX;
28+
setlocale(LC_ALL, "C");
29+
1530
for my $constant (@constants) {
1631
SKIP: {
1732
my $string = eval { langinfo(eval "$constant()") };
@@ -22,53 +37,12 @@ for my $constant (@constants) {
2237
}
2338
}
2439

25-
exit(0);
26-
27-
# Background: the langinfo() (in C known as nl_langinfo()) interface
28-
# is supposed to be a portable way to fetch various language/country
29-
# (locale) dependent constants like "the first day of the week" or
30-
# "the decimal separator". Give a portable (numeric) constant,
31-
# get back a language-specific string. That's a comforting fantasy.
32-
# Now tune in for blunt reality: vendors seem to have implemented for
33-
# those constants whatever they felt like implementing. The UNIX
34-
# standard says that one should have the RADIXCHAR constant for the
35-
# decimal separator. Not so for many Linux and BSD implementations.
36-
# One should have the CODESET constant for returning the current
37-
# codeset (say, ISO 8859-1). Not so. So let's give up any real
38-
# testing (leave the old testing code here for old times' sake,
39-
# though.) --jhi
40-
41-
my %want =
42-
(
43-
ABDAY_1 => "Sun",
44-
DAY_1 => "Sunday",
45-
ABMON_1 => "Jan",
46-
MON_1 => "January",
47-
RADIXCHAR => ".",
48-
AM_STR => qr{^(?:am|a\.m\.)$}i,
49-
THOUSEP => "",
50-
D_T_FMT => qr{^%a %b %[de] %H:%M:%S %Y$},
51-
D_FMT => qr{^%m/%d/%y$},
52-
T_FMT => qr{^%H:%M:%S$},
53-
);
54-
55-
56-
my @want = sort keys %want;
57-
58-
print "1..", scalar @want, "\n";
59-
6040
for my $i (1..@want) {
6141
my $try = $want[$i-1];
6242
eval { I18N::Langinfo->import($try) };
63-
unless ($@) {
64-
my $got = langinfo(&$try);
65-
if (ref $want{$try} && $got =~ $want{$try} || $got eq $want{$try}) {
66-
print qq[ok $i - $try is "$got"\n];
67-
} else {
68-
print qq[not ok $i - $try is "$got" not "$want{$try}"\n];
69-
}
70-
} else {
71-
print qq[ok $i - Skip: $try not defined\n];
43+
SKIP: {
44+
skip "$try not defined", 1, if $@;
45+
no strict 'refs';
46+
is (langinfo(&$try), $want{$try}, "$try => '$want{$try}'");
7247
}
7348
}
74-

0 commit comments

Comments
 (0)