Skip to content
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
This repository was archived by the owner on Mar 10, 2026. It is now read-only.

testlang.c test fails under C.utf-8 #5097

Closed

Description

@OdyX

I've uploaded 2.2.4-62-g4f272af7b to Debian and the testlang test broke all builds (e.g. amd64 ) with the following confusing error:

Running language API tests...
./testlang
Language = "C"
Encoding = "utf-8"
No       = "No" (FAIL)
Yes      = "Yes" (FAIL)
_cupsStrScand("1") number=1.000000
_cupsStrFormatd(1.000000) buffer="1"
_cupsStrScand("-1") number=-1.000000
_cupsStrFormatd(-1.000000) buffer="-1"
_cupsStrScand("3") number=3.000000
_cupsStrFormatd(3.000000) buffer="3"
_cupsStrScand("5.125") number=5.125000
_cupsStrFormatd(5.125000) buffer="5.125"
Makefile:517: recipe for target 'testlang' failed

It seems that the test expects a different result between the original locale and the build locale. Above, when built with C.UTF-8 it breaks although with my fr_CH.utf-8 it succeeds:

./testlang
Language = "fr_CH"
Encoding = "utf-8"
No       = "Non" (PASS)
Yes      = "Oui" (PASS)

This seems quite fragile to me.

Activity

  1. michaelrsweet commented on Aug 27, 2017

    @michaelrsweet
    Contributor

    a) this is a unit test, and b) the code is testing whether it gets a different pointer (i.e. it has a localization) for each of the strings, showing that the underlying localization code is working (i.e. this is a unit test).

    If you don't use a locale with a localization, this unit test will fail. Using even "en" will make it work.

    I will look at updating the unit test program to override the default locale if it is any variant of "C".

  2. OdyX commented on Aug 27, 2017

    @OdyX
    ContributorAuthor

    If you don't use a locale with a localization, this unit test will fail. Using even "en" will make it work.

    That's not what I see here:

    $ LC_MESSAGES=en ./cups/testlang ; echo $?
    Language = "en"
    Encoding = "utf-8"
    No       = "No" (FAIL)
    Yes      = "Yes" (FAIL)
    _cupsStrScand("1") number=1.000000
    _cupsStrFormatd(1.000000) buffer="1"
    _cupsStrScand("-1") number=-1.000000
    _cupsStrFormatd(-1.000000) buffer="-1"
    _cupsStrScand("3") number=3.000000
    _cupsStrFormatd(3.000000) buffer="3"
    _cupsStrScand("5.125") number=5.125000
    _cupsStrFormatd(5.125000) buffer="5.125"
    1
    

    … where …

    $ LC_MESSAGES=fr ./cups/testlang ; echo $?
    Language = "fr"
    Encoding = "utf-8"
    No       = "Non" (PASS)
    Yes      = "Oui" (PASS)
    _cupsStrScand("1") number=1.000000
    _cupsStrFormatd(1.000000) buffer="1"
    _cupsStrScand("-1") number=-1.000000
    _cupsStrFormatd(-1.000000) buffer="-1"
    _cupsStrScand("3") number=3.000000
    _cupsStrFormatd(3.000000) buffer="3"
    _cupsStrScand("5.125") number=5.125000
    _cupsStrFormatd(5.125000) buffer="5.125"
    0
    

    I stand to saying that this is fragile: a unit-test should not depend on the environment.

  3. michaelrsweet commented on Aug 27, 2017

    @michaelrsweet
    Contributor

    When the unit test is explicitly testing the environment (i.e. test language localization using the current locale), it ABSOLUTELY MUST DO ITS JOB AND FAIL IF NO LOCALIZATION IS FOUND.

    Again, this unit test is working exactly as it is supposed to. The failure (even for "en" in this case, since on Linux different localization files are involved) is 100% valid and points to an implementation bug.

  4. OdyX commented on Aug 27, 2017

    @OdyX
    ContributorAuthor

    Fair enough.

    Debian buildds have restricted environments with only C.utf-8 available and I make a point to run all available tests. How would you proceed there? Comment the test out?

  5. michaelrsweet commented on Aug 27, 2017

    @michaelrsweet
    Contributor

    First, testlang uses the message catalogs in the locale directory so it doesn't matter what the host OS has available/installed - we are testing the internal localization features of libcups.

    Second, once I fix the bug in this unit test (and make sure there is a cups_en.po file), the test will work for both the POSIX ("C" locale) and other locales... The goal here is to catch localization bugs as soon as possible, and this unit test was updated for 2.2.4 to address a macOS localization bug that wasn't caught.

  6. OdyX commented on Aug 28, 2017

    @OdyX
    ContributorAuthor

    I debugged this further and found out why it worked locally but not during a build: it seems testlang uses the configured LOCALEDIR aka /usr/share/cups/locale. So ./testlang succeeds on a system with CUPS installed, but not during a clean build.

    It seems a mechanism like the one in testppd (creating a fake symlink tree of the locale files to test) would be needed here, such as OdyX/cups@e3136bc .

    Through doing that patch, I also noticed that the translation code defaults to using …/C/cups_C.po for ten+years https://github.com/apple/cups/blob/master/cups/language.c#L1659 where that file was never provided:

         /*
          * No generic localization, so use POSIX...
          */
          snprintf(filename, sizeof(filename), "%s/C/cups_C.po", cg->localedir);
    
  7. michaelrsweet commented on Aug 28, 2017

    @michaelrsweet
    Contributor

    [master 9964a31] Fix the localization unit test on Linux (Issue #5097)

  8. michaelrsweet commented on Aug 28, 2017

    @michaelrsweet
    Contributor

    OK, this appears to be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions