From 6c5c8e03c5d3bc9b253897e71618b40b818a9991 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 17 Aug 2021 14:23:21 +0200 Subject: [PATCH] Move the numeric locale tests to a different file This lets us check for locales once, and to have littlecheck mark the test as skipped. --- tests/checks/locale-numeric.fish | 37 ++++++++++++++++++++++++++++++++ tests/checks/printf.fish | 27 ----------------------- tests/checks/test.fish | 17 --------------- 3 files changed, 37 insertions(+), 44 deletions(-) create mode 100644 tests/checks/locale-numeric.fish diff --git a/tests/checks/locale-numeric.fish b/tests/checks/locale-numeric.fish new file mode 100644 index 000000000..91b00bcc8 --- /dev/null +++ b/tests/checks/locale-numeric.fish @@ -0,0 +1,37 @@ +# RUN: %fish %s +# musl currently does not have a `locale` command, so we skip this test there. +# REQUIRES: command -v locale +# We need a comma-using locale we know. +# REQUIRES: locale -a | grep -i '(bg_BG\|de_DE\|es_ES\|fr_FR\|ru_RU).(UTF-8|utf8)' +# OpenBSD does not use LC_NUMERIC, this test is pointless there. +# REQUIRES: test "$(uname)" != OpenBSD + +set -l locales (locale -a) +set -l acceptable_locales bg_BG de_DE es_ES fr_FR ru_RU +set -l numeric_locale +for locale in {$acceptable_locales}.{UTF-8,UTF8} + if string match -i -q $locale $locales + set numeric_locale $locale + break + end +end + +if not set -q numeric_locale[1] + # Note we tried to check for a locale above, + # but in case this fails because of e.g. case issues, + # let's error again. + echo Please install one of the following locales: >&2 + printf '%s\n' $acceptable_locales".utf-8" >&2 + exit 127 +end + +begin + set -x LC_NUMERIC $numeric_locale + printf '%e\n' "3,45" # should succeed, output should be 3,450000e+00 + # CHECK: 3,450000e+00 + printf '%e\n' "4.56" # should succeed, output should be 4,560000e+00 + # CHECK: 4,560000e+00 + + # This should succeed without output + test 42.5 -gt 37.2 +end diff --git a/tests/checks/printf.fish b/tests/checks/printf.fish index f342bee7d..83da2c878 100644 --- a/tests/checks/printf.fish +++ b/tests/checks/printf.fish @@ -68,33 +68,6 @@ printf '%e\n' "2,34" # should fail # CHECK: 2.000000e+00 # CHECKERR: 2,34: value not completely converted -# Try to use one of several locales that use a comma as the decimal mark -# rather than the period used in english speaking locales. If we don't find -# one installed we simply don't run this test. -# -# musl currently does not have a `locale` command, so we also skip it then. -set -l locales (command -sq locale; and locale -a) -set -l acceptable_locales bg_BG de_DE es_ES fr_FR ru_RU -set -l numeric_locale -for locale in {$acceptable_locales}.{UTF-8,UTF8} - if string match -i -q $locale $locales - set numeric_locale $locale - break - end -end - -# OpenBSD's wcstod does not honor LC_NUMERIC, meaning this feature is broken there. -if set -q numeric_locale[1]; and test (uname) != OpenBSD - set -x LC_NUMERIC $numeric_locale - printf '%e\n' "3,45" # should succeed, output should be 3,450000e+00 - printf '%e\n' "4.56" # should succeed, output should be 4,560000e+00 -else - echo '3,450000e+00' - echo '4,560000e+00' -end -# CHECK: 3,450000e+00 -# CHECK: 4,560000e+00 - # Verify long long ints are handled correctly. See issue #3352. printf 'long hex1 %x\n' 498216206234 # CHECK: long hex1 73ffffff9a diff --git a/tests/checks/test.fish b/tests/checks/test.fish index cda8d7fc6..6372c73f3 100644 --- a/tests/checks/test.fish +++ b/tests/checks/test.fish @@ -51,20 +51,3 @@ t 5,2 # CHECKERR: ^ # CHECKERR: in function 't' with arguments '5,2' # CHECKERR: called on line {{\d+}} of file {{.*}}test.fish - -if command -q locale - # Try to get a comma-using locale. - # We have a cheesy list hardcoded, and try to get it in the spelling - # that "locale" uses. - set -l locales (locale -a) - set -l use - for locale in de_de fr_fr nl_NL pt_BR - set use (string match -ri "$locale.utf.?8" -- $locales) - and break - end - if set -q use[1] - set -gx LC_ALL $use - # This should succeed without output - test 42.5 -gt 37.2 - end -end