git/t/t0202/test.pl
brian m. carlson 702d8c1f3b Require Perl 5.26.0
Our platform support policy states that we require "versions of
dependencies which are generally accepted as stable and supportable,
e.g., in line with the version used by other long-term-support
distributions".  Of Debian, Ubuntu, RHEL, and SLES, the four most common
distributions that provide LTS versions, the version with mainstream
long-term security support with the oldest Perl is 5.26.0 in SLES 15.6.

This is a major upgrade, since Perl 5.8.1, according to the Perl
documentation, was released in September of 2003.  It brings a lot of
new features that we can choose to use, such as s///r to return the
modified string, the postderef functionality, and subroutine signatures,
although the latter was still considered experimental until 5.36.

This change was made with the following one-liner, which intentionally
excludes modifying the vendored modules we include to avoid conflicts:

    git grep -l 'use 5.008001' | grep -v 'LoadCPAN/' | xargs perl -pi -e 's/use 5.008001/require v5.26/'

Use require instead of use to avoid changing the behavior as the latter
enables features and the former does not.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2024-10-23 16:16:36 -04:00

123 lines
3.2 KiB
Perl
Executable File

#!/usr/bin/perl
require v5.26;
use lib (split(/:/, $ENV{GITPERLLIB}));
use strict;
use warnings;
use POSIX qw(:locale_h);
use Test::More tests => 13;
use Git::I18N;
my $has_gettext_library = $Git::I18N::__HAS_LIBRARY;
ok(1, "Testing Git::I18N with " .
($has_gettext_library
? (defined $Locale::Messages::VERSION
? "Locale::Messages version $Locale::Messages::VERSION"
# Versions of Locale::Messages before 1.17 didn't have a
# $VERSION variable.
: "Locale::Messages version <1.17")
: "NO Perl gettext library"));
ok(1, "Git::I18N is located at $INC{'Git/I18N.pm'}");
{
my $exports = @Git::I18N::EXPORT;
ok($exports, "sanity: Git::I18N has $exports export(s)");
}
is_deeply(\@Git::I18N::EXPORT, \@Git::I18N::EXPORT_OK, "sanity: Git::I18N exports everything by default");
# prototypes
{
# Add prototypes here when modifying the public interface to add
# more gettext wrapper functions.
my %prototypes = (qw(
__ $
__n $$$
N__ $
));
while (my ($sub, $proto) = each %prototypes) {
is(prototype(\&{"Git::I18N::$sub"}), $proto, "sanity: $sub has a $proto prototype");
}
}
# Test basic passthrough in the C locale
{
local $ENV{LANGUAGE} = 'C';
local $ENV{LC_ALL} = 'C';
local $ENV{LANG} = 'C';
my ($got, $expect) = (('TEST: A Perl test string') x 2);
is(__($got), $expect, "Passing a string through __() in the C locale works");
my ($got_singular, $got_plural, $expect_singular, $expect_plural) =
(('TEST: 1 file', 'TEST: n files') x 2);
is(__n($got_singular, $got_plural, 1), $expect_singular,
"Get singular string through __n() in C locale");
is(__n($got_singular, $got_plural, 2), $expect_plural,
"Get plural string through __n() in C locale");
is(N__($got), $expect, "Passing a string through N__() in the C locale works");
}
# Test a basic message on different locales
SKIP: {
unless ($ENV{GETTEXT_LOCALE}) {
# Can't reliably test __() with a non-C locales because the
# required locales may not be installed on the system.
#
# We test for these anyway as part of the shell
# tests. Skipping these here will eliminate failures on odd
# platforms with incomplete locale data.
skip "GETTEXT_LOCALE must be set by lib-gettext.sh for exhaustive Git::I18N tests", 2;
}
# The is_IS UTF-8 locale passed from lib-gettext.sh
my $is_IS_locale = $ENV{is_IS_locale};
my $test = sub {
my ($got, $expect, $msg, $locale) = @_;
# Maybe this system doesn't have the locale we're trying to
# test.
my $locale_ok = setlocale(LC_ALL, $locale);
is(__($got), $expect, "$msg a gettext library + <$locale> locale <$got> turns into <$expect>");
};
my $env_C = sub {
$ENV{LANGUAGE} = 'C';
$ENV{LC_ALL} = 'C';
};
my $env_is = sub {
$ENV{LANGUAGE} = 'is';
$ENV{LC_ALL} = $is_IS_locale;
};
# Translation's the same as the original
my ($got, $expect) = (('TEST: A Perl test string') x 2);
if ($has_gettext_library) {
{
local %ENV; $env_C->();
$test->($got, $expect, "With", 'C');
}
{
my ($got, $expect) = ($got, 'TILRAUN: Perl tilraunastrengur');
local %ENV; $env_is->();
$test->($got, $expect, "With", $is_IS_locale);
}
} else {
{
local %ENV; $env_C->();
$test->($got, $expect, "Without", 'C');
}
{
local %ENV; $env_is->();
$test->($got, $expect, "Without", 'is');
}
}
}