-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
Make generated test failures more useful #1498
Conversation
Currently, when a `sys` compilation fails, the only context given is the command used to compile the code. This is less than helpful. This PR adds all the compilation commands' output to the error message. It also prints the message. `unwrap` doesn't format properly error messages, so we use `println!` as well. This results in the output being duplicated. I consider the duplicate output to be acceptable, it's already far better than the current output, the fact that code is generated makes testing and developing a lot harder and we shouldn't let perfect be enemy of the better. Here is a sample of the difference this commit makes: BEFORE ``` thread 'cross_validate_layout_with_c' panicked at 'called `Result::unwrap()` on an `Err` value: "compilation command \"cc\" \"-Wno-deprecated-declarations\" \"-std=c11\" \"-D__USE_MINGW_ANSI_STDIO\" \"-I/usr/include/wpe-webkit-1.1\" \"-I/usr/include/glib-2.0\" \"-I/usr/lib/glib-2.0/include\" \"-I/usr/include/sysprof-4\" \"-I/usr/include/libsoup-3.0\" \"-I/usr/include/libmount\" \"-I/usr/include/blkid\" \"-pthread\" \"-I/usr/include/wpe-1.0\" \"-DWPE_ENABLE_XKB=1\" \"tests/layout.c\" \"-o\" \"/tmp/abiXdITDL/layout\" failed, exit status: 1" ``` AFTER ``` compilation command "cc" "-Wno-deprecated-declarations" "-std=c11" "-D__USE_MINGW_ANSI_STDIO" "-I/usr/include/wpe-webkit-1.1" "-I/usr/include/glib-2.0" "-I/usr/lib/glib-2.0/include" "-I/usr/include/sysprof-4" "-I/usr/include/libsoup-3.0" "-I/usr/include/libmount" "-I/usr/include/blkid" "-pthread" "-I/usr/include/wpe-1.0" "-DWPE_ENABLE_XKB=1" "tests/layout.c" "-o" "/tmp/abiXdITDL/layout" failed, exit status: 1 stdout: stderr: In file included from tests/layout.c:7: tests/manual.h:3:10: fatal error: cog/cog.h: No such file or directory 3 | #include <cog/cog.h> | ^~~~~~~~~~~ compilation terminated. thread 'cross_validate_layout_with_c' panicked at 'called `Result::unwrap()` on an `Err` value: "compilation command \"cc\" \"-Wno-deprecated-declarations\" \"-std=c11\" \"-D__USE_MINGW_ANSI_STDIO\" \"-I/usr/include/wpe-webkit-1.1\" \"-I/usr/include/glib-2.0\" \"-I/usr/lib/glib-2.0/include\" \"-I/usr/include/sysprof-4\" \"-I/usr/include/libsoup-3.0\" \"-I/usr/include/libmount\" \"-I/usr/include/blkid\" \"-pthread\" \"-I/usr/include/wpe-1.0\" \"-DWPE_ENABLE_XKB=1\" \"tests/layout.c\" \"-o\" \"/tmp/abiXdITDL/layout\" failed, exit status: 1\nstdout: \nstderr: In file included from tests/layout.c:7:\ntests/manual.h:3:10: fatal error: cog/cog.h: No such file or directory\n 3 | #include <cog/cog.h>\n | ^~~~~~~~~~~\ncompilation terminated.\n"', tests/abi.rs:198:31 ```
@@ -346,13 +346,22 @@ impl Compiler { | |||
} | |||
|
|||
pub fn compile(&self, src: &Path, out: &Path) -> Result<(), Box<dyn Error>> { | |||
use std::str::fom_utf8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use std::str::fom_utf8; | |
use std::str::from_utf8; |
let stdout = from_utf8(&output.stdout).unwrap_or(""); | ||
let stderr = from_utf8(&output.stderr).unwrap_or(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let stdout = from_utf8(&output.stdout).unwrap_or(""); | |
let stderr = from_utf8(&output.stderr).unwrap_or(""); | |
let stdout = from_utf8(&output.stdout).unwrap_or_default(); | |
let stderr = from_utf8(&output.stderr).unwrap_or_default(); |
maybe?
I did use It seems stderr actually is printed and is visible in the terminal when running I'm not sure why in the first place I didn't see the compilation error output. I'm fairly certain it didn't show up. Maybe it depends on what calls the Since this is a regression I'm going to put the pull request in draft mode. |
I now know why the tests previously failed without showing any errors. I'm closing this in favor of a fix for the problem in question. |
Currently, when a
sys
compilation fails, the only context given is the command used to compile the code.This is less than helpful. This PR adds all the compilation commands' output to the error message.
It also prints the message.
unwrap
doesn't format properly error messages, so we useprintln!
as well. This results in the output being duplicated.I consider the duplicate output to be acceptable, it's already far better than the current output, the fact that code is generated makes testing and developing a lot harder and we shouldn't let perfect be enemy of the better.
Here is a sample of the difference this commit makes:
BEFORE
AFTER