Description
Problem
Calling cargo test
on a project that has the #![windows_subsystem = "windows"]
global attribute does not show the expected human-readable output.
Instead of showing
> cargo test
Compiling no_output v0.1.0 (C:\Programming\no_output)
Finished dev [unoptimized + debuginfo] target(s) in 0.71s
Running target\debug\deps\no_output-c8b57bda8502ba55.exe
running 1 test
test tests::test_panic ... FAILED
failures:
---- tests::test_panic stdout ----
thread 'tests::test_panic' panicked at 'This tape has just self-destructed!', src\main.rs:9:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
failures:
tests::test_panic
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
error: test failed, to rerun pass '--bin no_output'
it shows
> cargo test
Compiling no_output v0.1.0 (C:\Programming\no_output)
Finished dev [unoptimized + debuginfo] target(s) in 1.40s
Running target\debug\deps\no_output-c8b57bda8502ba55.exe
error: test failed, to rerun pass '--bin no_output'
which not quite as informative as the former message (it does not tell which tests failed).
Steps
This requires a Windows computer.
- Create a new project with
cargo new
. - Copy-paste the following into your
main.rs
file:
#![windows_subsystem = "windows"]
fn main() {
println!("Hello, world!");
}
#[cfg(test)]
mod tests {
#[test]
fn test_panic() {
panic!("This tape has just self-destructed!");
}
}
- call
cargo test
on your project.
Possible Solution(s)
My guess is that this is due to executables targeting the Windows subsystem having no console and standard output initialized by default on Windows. Therefore, 2 possible solutions come to my mind:
- forcing
cargo test
-compiled executables to target the console subsystem when compiled for Windows; - or having cargo explicitly initialize the console in the test framework automatically included in test executables: AFAIK this can be achieved by calling the
AllocConsole()
function provided by the Windows API.
Notes
Output of cargo version
: this happens on pretty much any cargo version.
Tested on cargo 1.39.0 (1c6ec66d5 2019-09-30)
and cargo 1.41.0-nightly (626f0f40e 2019-12-03)
.
Apologies if this has already been reported. I was unable to find a similar issue in the repository 😅
Metadata
Metadata
Assignees
Labels
Type
Projects
Status