Skip to content

Test case uses locale-dependent output #137116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
crlf0710 opened this issue Feb 16, 2025 · 6 comments · Fixed by #137117
Closed

Test case uses locale-dependent output #137116

crlf0710 opened this issue Feb 16, 2025 · 6 comments · Fixed by #137117
Labels
A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust A-test-infra Area: test infrastructure (may span bootstrap/compiletest/more) A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@crlf0710
Copy link
Member

I was running ui-tests, and this test case fail on my windows machine:

---- [ui] tests\ui\unpretty\staged-api-invalid-path-108697.rs stdout ----
$DIR\lol
$DIR\staged-api-invalid-path-108697.rs
Saved the actual stderr to "L:\\ThirdParty\\rust\\build\\x86_64-pc-windows-msvc\\test\\ui\\unpretty\\staged-api-invalid-path-108697\\staged-api-invalid-path-108697.stderr"
diff of stderr:

-       error: couldn't read `$DIR/lol`: No such file or directory (os error 2)
+       error: couldn't read `$DIR/lol`: 系统找不到指定的文件。 (os error 2)
2         --> $DIR/staged-api-invalid-path-108697.rs:8:1
3          |
4       LL | mod foo;

Maybe we should not rely on such locale-dependent output, or maybe we could configure Rust standard library/compiler to use English as UI language.

@crlf0710 crlf0710 added the C-bug Category: This is a bug. label Feb 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 16, 2025
@ChrisDenton
Copy link
Member

ChrisDenton commented Feb 16, 2025

Maybe we should not rely on such locale-dependent output

If that's the only test that fails then I think we don't normally rely on locale? It may just be this test needs tweaking.

EDIT: wait that's not a linker erorr, huh. Ignore this next bit.

linker stuff

or maybe we could configure Rust standard library/compiler to use English as UI language.

We do configure Rust to use English for the linker

/// Disables non-English messages from localized linkers.
/// Such messages may cause issues with text encoding on Windows (#35785)
/// and prevent inspection of linker output in case of errors, which we occasionally do.
/// This should be acceptable because other messages from rustc are in English anyway,
/// and may also be desirable to improve searchability of the linker diagnostics.
pub(crate) fn disable_localization(linker: &mut Command) {
// No harm in setting both env vars simultaneously.
// Unix-style linkers.
linker.env("LC_ALL", "C");
// MSVC's `link.exe`.
linker.env("VSLANG", "1033");
}

However it relies on the English language pack being installed via the Visual Studio Installer.

@crlf0710
Copy link
Member Author

Currently the std::io::Error's debug output relies on winapi FormatMessage behavior, which relies on thread language (locale).

unsafe {
    SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}

If above code is called from rustc, i think the output will be deterministic.

@ChrisDenton
Copy link
Member

I think that would need to be an option exposed by libtest. It manages running test threads.

@Noratrieb
Copy link
Member

This error comes from rustc, not a libtest thread. rustc itself would need to set its language to english for this

@Noratrieb Noratrieb added A-testsuite Area: The testsuite used to check the correctness of rustc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 16, 2025
@ChrisDenton
Copy link
Member

In which case we could set it in rustc main (early, before anything can error) but I think that would need a Major Change Proposal (MCP).

@jieyouxu
Copy link
Member

jieyouxu commented Feb 16, 2025

If that's the only test that fails then I think we don't normally rely on locale? It may just be this test needs tweaking.

This is a general problem where the test infra doesn't try to account for locale (because rustc will forward system error messages in different locale IIRC).

I don't think the test infra can really properly account for this (e.g. snapshot tests) without setting the locale for rustc somehow.

@jieyouxu jieyouxu added the A-test-infra Area: test infrastructure (may span bootstrap/compiletest/more) label Feb 16, 2025
@ChrisDenton ChrisDenton linked a pull request Feb 16, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new or seasoned contributors to Rust A-test-infra Area: test infrastructure (may span bootstrap/compiletest/more) A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants