Skip to content

Conversation

crywolf
Copy link

@crywolf crywolf commented Aug 17, 2023

Running tests with non-English locale set in Linux terminal makes system tests (system_tests/run_command) fail. Setting the locale in failing test explicitly to 'C' fixes the failure.

How to reproduce test failure:
Setting LC_ALL=cs_CZ.UTF-8 (export LC_ALL=cs_CZ.UTF-8) in terminal and then running make check should be enough.

Fix:
My terminal is by default set to non-English locale and the test failed because it checks for English error message, but the terminal produces error message in the language set by locale. Then I manually set export LC_ALL=C in my terminal and all tests passed. So I explicitly set env variable 'LC_ALL' to 'C' in the code of failing test.

Running tests with non-English locale set in Linux terminal makes system tests (system_tests/run_command') fail.
Setting the locale env variable 'LC_ALL' in failing test explicitly to 'C' fixes the failure.
@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 17, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK jonatack

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #29489 (test: Remove Windows-specific code from system_tests/run_command by hebasto)
  • #28981 (Replace Boost.Process with cpp-subprocess by hebasto)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot DrahtBot added the Tests label Aug 17, 2023
@crywolf
Copy link
Author

crywolf commented Aug 17, 2023

During the workshop wit Gloria @glozow on Dev/Hack/Day (part of BTC Prague conference) my tests failed. Later that day I found what the problem was and now I am finally presenting my fix as an attempt to make my first PR in this repo.

@jonatack
Copy link
Member

Concept ACK, though I'm unable to reproduce this on macOS, which makes sense per src/common/system.cpp#L66-73:

    // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
    // may be invalid, in which case the "C.UTF-8" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
    try {
        std::locale(""); // Raises a runtime error if current locale is invalid
    } catch (const std::runtime_error&) {
        setenv("LC_ALL", "C.UTF-8", 1);
    }

@@ -79,6 +79,7 @@ BOOST_AUTO_TEST_CASE(run_command)
const std::string command{"cmd.exe /c dir nosuchfile"};
const std::string expected{wine_runtime ? "File not found." : "File Not Found"};
#else
setenv("LC_ALL", "C", 1); // explicitly set locale env to get error message in English
const std::string command{"ls nosuchfile"};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but if the file exists, this will also fail.

Might be better to use a pure command that does not depend on the env vars and filesystem state

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@maflcko
Copy link
Member

maflcko commented Feb 29, 2024

Apologies for the slow review on this, and it eventually going stale. I'll close for now, but the issue will still need a fix. Ideally like #28286 (comment)

Anyone is welcome to open a new pull request with the fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants