Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

nicopap
Copy link
Contributor

@nicopap nicopap commented Aug 12, 2023

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
use std::str::fom_utf8;
use std::str::from_utf8;

Comment on lines +358 to +359
let stdout = from_utf8(&output.stdout).unwrap_or("");
let stderr = from_utf8(&output.stderr).unwrap_or("");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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?

@nicopap
Copy link
Contributor Author

nicopap commented Aug 12, 2023

I did use gir a bit more and this is a regression in certain cases.

It seems stderr actually is printed and is visible in the terminal when running cargo test. With this change, we lose the nice color formatting of the error.

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 compile function? I don't know.

Since this is a regression I'm going to put the pull request in draft mode.

@nicopap nicopap marked this pull request as draft August 12, 2023 09:53
@nicopap
Copy link
Contributor Author

nicopap commented Aug 13, 2023

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.

@nicopap nicopap closed this Aug 13, 2023
@nicopap nicopap deleted the better-test-failures branch August 30, 2023 13:35
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.

2 participants