mingw: skip some tests in t9115 due to file name issues
[git/raj.git] / t / t0202 / test.pl
blob2c10cb4693e28eecf7771978a2f3b702e5f3bd30
1 #!/usr/bin/perl
2 use 5.008;
3 use lib (split(/:/, $ENV{GITPERLLIB}));
4 use strict;
5 use warnings;
6 use POSIX qw(:locale_h);
7 use Test::More tests => 8;
8 use Git::I18N;
10 my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
12 ok(1, "Testing Git::I18N with " .
13 ($has_gettext_library
14 ? (defined $Locale::Messages::VERSION
15 ? "Locale::Messages version $Locale::Messages::VERSION"
16 # Versions of Locale::Messages before 1.17 didn't have a
17 # $VERSION variable.
18 : "Locale::Messages version <1.17")
19 : "NO Perl gettext library"));
20 ok(1, "Git::I18N is located at $INC{'Git/I18N.pm'}");
23 my $exports = @Git::I18N::EXPORT;
24 ok($exports, "sanity: Git::I18N has $exports export(s)");
26 is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N exports everything by default");
28 # prototypes
30 # Add prototypes here when modifying the public interface to add
31 # more gettext wrapper functions.
32 my %prototypes = (qw(
33 __ $
34 ));
35 while (my ($sub, $proto) = each %prototypes) {
36 is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
40 # Test basic passthrough in the C locale
42 local $ENV{LANGUAGE} = 'C';
43 local $ENV{LC_ALL} = 'C';
44 local $ENV{LANG} = 'C';
46 my ($got, $expect) = (('TEST: A Perl test string') x 2);
48 is(__($got), $expect, "Passing a string through __() in the C locale works");
51 # Test a basic message on different locales
52 SKIP: {
53 unless ($ENV{GETTEXT_LOCALE}) {
54 # Can't reliably test __() with a non-C locales because the
55 # required locales may not be installed on the system.
57 # We test for these anyway as part of the shell
58 # tests. Skipping these here will eliminate failures on odd
59 # platforms with incomplete locale data.
61 skip "GETTEXT_LOCALE must be set by lib-gettext.sh for exhaustive Git::I18N tests", 2;
64 # The is_IS UTF-8 locale passed from lib-gettext.sh
65 my $is_IS_locale = $ENV{is_IS_locale};
67 my $test = sub {
68 my ($got, $expect, $msg, $locale) = @_;
69 # Maybe this system doesn't have the locale we're trying to
70 # test.
71 my $locale_ok = setlocale(LC_ALL, $locale);
72 is(__($got), $expect, "$msg a gettext library + <$locale> locale <$got> turns into <$expect>");
75 my $env_C = sub {
76 $ENV{LANGUAGE} = 'C';
77 $ENV{LC_ALL} = 'C';
80 my $env_is = sub {
81 $ENV{LANGUAGE} = 'is';
82 $ENV{LC_ALL} = $is_IS_locale;
85 # Translation's the same as the original
86 my ($got, $expect) = (('TEST: A Perl test string') x 2);
88 if ($has_gettext_library) {
90 local %ENV; $env_C->();
91 $test->($got, $expect, "With", 'C');
95 my ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur');
96 local %ENV; $env_is->();
97 $test->($got, $expect, "With", $is_IS_locale);
99 } else {
101 local %ENV; $env_C->();
102 $test->($got, $expect, "Without", 'C');
106 local %ENV; $env_is->();
107 $test->($got, $expect, "Without", 'is');