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

Generated sys tests: Better command error handling #1499

Merged
merged 2 commits into from
Aug 16, 2023

Conversation

nicopap
Copy link
Contributor

@nicopap nicopap commented Aug 13, 2023

The generated tests for sys crates sometimes call Command::output. It is used to find CFLAGS arguments for tested packages and run the executables created from constant.c and layout.c tests. Command::output, by default, captures stdout and stderr. This means that, by default, no feedback for why the tests fail will be printed. The only information shown to the end-user is the command that was ran.

You could copy/paste and run yourself the command printed in the error message, but it might not be evident as a "next step" for users.

This is unlike the compilation command, which uses cmd.spawn()?.wait()?. We can see compilation error messages, but not pkg-config error messages.

To solve this, we:

  1. Inherit stderr from the parent descriptor. This will print the command's error message in the terminal.
  2. Add the command's stdout to the error message returned by pkg_config_cflags and get_c_output.

Now. Errors generated by the spawned process are visible to the end user, which makes test errors more actionables.

The output is included for exhaustiveness. It may not be useful, but it makes sense to give to the user all the information necessary.

The generated tests for `sys` crates sometimes call `Command::output`.
It is used to find CFLAGS arguments for tested packages and run the
executables created from `constant.c` and `layout.c` tests.
`Command::output`, by default, captures `stdout` and `stderr`.
This means that, by default, no feedback for why the tests fail will be
printed. The only information shown to the end-user is the command that
was ran.

You could copy/paste and run yourself the command printed in the error
message, but it might not be evident as a "next step" for users.

This is unlike the compilation command, which uses
`cmd.spawn()?.wait()?`. We can see compilation error messages, but not
pkg-config error messages.

To solve this, we:

1. Inherit `stderr` from the parent descriptor. This will print the
   command's error message in the terminal.
2. Add the command's `stdout` to the error message returned by
   `pkg_config_cflags` and `get_c_output`.

Now. Errors generated by the spawned process are visible to the end
user, which makes test errors more actionables.

The output is included for exhaustiveness. It may not be useful, but it
makes sense to give to the user all the information necessary.
src/codegen/sys/tests.rs Outdated Show resolved Hide resolved
Copy link
Member

@sdroege sdroege left a comment

Choose a reason for hiding this comment

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

Looks good to me otherwise, thanks :)

@nicopap nicopap marked this pull request as ready for review August 15, 2023 07:06
@sdroege sdroege merged commit de3fd6d into gtk-rs:master Aug 16, 2023
6 checks passed
@nicopap nicopap deleted the better-test-failures-2 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.

None yet

2 participants