Skip to content

test suite: Output UTF-8 from cmd.exe on Windows #25654

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

Merged
merged 2 commits into from
Jun 2, 2015

Conversation

petrochenkov
Copy link
Contributor

Fixes #25268 and a couple of similar test errors

r? @alexcrichton

@alexcrichton
Copy link
Member

Oh interesting! If this setting is applied, what happens when the program does indeed print non-utf8 contents? Does it die with an error or does Windows auto-translate it?

@retep998
Copy link
Member

I'm somewhat confused how SetConsoleOutputCP works here since we're piping stdout and not working with the actual console, and the docs state it's just used to map codepoints to font glyphs.
Looks like I've got more research to do.

@petrochenkov
Copy link
Contributor Author

@retep998

we're piping stdout and not working with the actual console

There is a console, that exact console where you type make check. This console instance is inherited (and shared) by all the child processes, including cmd.exe process spawned from tests.

what happens when the program does indeed print non-utf8 contents?

cmd.exe is special in the regard that it encodes its output according to the console code page, I don't think this tweak will affect any test code written in Rust.

I've added a test for this issue which will fail if the proposed tweak is incorrect and the testing machine have English (US) system locale.
I also improved the fix - now it restores the old code page after running the tests.

@alexcrichton
Copy link
Member

This console instance is inherited (and shared) by all the child processes, including cmd.exe process spawned from tests

We override the standard console handles, however, when spawning a child process. Are you sure that this test fails on Windows before this change?

I also improved the fix

I'm somewhat wary about changing the global state of the Windows console here (e.g. if you ctrl-c then the old state is lost), so I'd personally be more in favor of just not assuming the output is UTF-8 and pass along Vec<u8> elsewhere and only convert to a str when necessary (printing errors as appropriate).

@petrochenkov
Copy link
Contributor Author

We override the standard console handles, however, when spawning a child process. Are you sure that this test fails on Windows before this change?

Yes.
(I haven't checked yet what is overriden when a process is spawned, but associated console and stdout/stderr handles may be unrelated things.)

not assuming the output is UTF-8 and pass along Vec elsewhere and only convert to a str when necessary (printing errors as appropriate)

It doesn't help other failing tests like test_inherit_env in process which assume that environment variable list goes unharmed through cmd.exe

Ideally I'd moved the fix from libtest to compiletest to localize it, but some tests are run through librustdoc and not compiletest.

@petrochenkov
Copy link
Contributor Author

Or ConsoleOutputCPGuard can be used locally around every invocation of cmd.exe, there are not so many of them.

@petrochenkov
Copy link
Contributor Author

Oh wait, tests can run in parallel. That's bad :D
Probably a documentation solution could be the simplest one here, something like "Dear Windows developer, please execute cmd /c "chcp 65001" in your console before running the test suite, otherwise some tests may fail. You can restore you favourite non-UTF-8 code page later if you wish"

@alexcrichton
Copy link
Member

Whoa there are multiple tests failing if the code page for cmd.exe is not UTF-8? In that case this does sound like a "let's provide a warning when make check is run" kind of situation.

@retep998
Copy link
Member

I guess setting the code page of the console affects what encoding certain processes use when writing to a piped stdout/stderr even though a pipe isn't a console.

@petrochenkov
Copy link
Contributor Author

So, I removed all the changes and left only a warning.
I put the check into check-sanitycheck.py, it looks like a proper place for such things. I also made some more test targets other than check (check-notidy, check-lite etc) dependent on check-sanitycheck because it seems equally applicable to them.

@alexcrichton
Copy link
Member

@bors: r+ 8c86f8f

Thanks!

@bors
Copy link
Collaborator

bors commented Jun 1, 2015

⌛ Testing commit 8c86f8f with merge affcc24...

@bors
Copy link
Collaborator

bors commented Jun 1, 2015

💔 Test failed - auto-mac-64-opt

@retep998
Copy link
Member

retep998 commented Jun 1, 2015

It seems your @only_on(('windows')) didn't work on mac.

@petrochenkov
Copy link
Contributor Author

Yeah, one forgotten comma and one platform turns into seven :)

@alexcrichton
Copy link
Member

@bors: r+ a40bca2

@bors
Copy link
Collaborator

bors commented Jun 1, 2015

⌛ Testing commit a40bca2 with merge 2bc526a...

@bors
Copy link
Collaborator

bors commented Jun 1, 2015

💔 Test failed - auto-linux-32-nopt-t

@petrochenkov
Copy link
Contributor Author

The failure seems completely unrelated.

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Jun 2, 2015

⌛ Testing commit a40bca2 with merge f813f97...

bors added a commit that referenced this pull request Jun 2, 2015
@bors bors merged commit a40bca2 into rust-lang:master Jun 2, 2015
@petrochenkov petrochenkov deleted the encenv branch September 21, 2015 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test run-pass\process-remove-from-env.rs fails on Windows with non-English locale
4 participants