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

add no lib targets test #847

Merged
merged 28 commits into from
Aug 16, 2024

Conversation

suaviloquence
Copy link
Contributor

Depends on #846. Adds a test when there are no library targets in a workspace, which is (currently) an error.

@suaviloquence suaviloquence force-pushed the add-no-lib-targets-test branch from 3c297bf to 5df1844 Compare August 2, 2024 23:50
@suaviloquence
Copy link
Contributor Author

suaviloquence commented Aug 3, 2024

Oops, I think I ran the test on nightly, which gave a backtrace. Will fix soon

@suaviloquence
Copy link
Contributor Author

Never mind, I read the diff wrong, need to figure out why 1.78 is giving different output.

@suaviloquence suaviloquence force-pushed the add-no-lib-targets-test branch from 5df1844 to 0b7e2ee Compare August 3, 2024 00:57
@suaviloquence
Copy link
Contributor Author

suaviloquence commented Aug 3, 2024

(fixed in 7495147)

expression: "&output"
---
exit_code: 1
stderr: "error: no crates with library targets selected, nothing to semver-check\nnote: only library targets contain an API surface that can be checked for semver\nnote: skipped the following crates since they have no library target: bin_only\n"
Copy link
Owner

Choose a reason for hiding this comment

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

This isn't the most readable output: the explicit \n are quite annoying, as are the extremely long line lengths.

Consider individually snapshotting the stderr and stdout into separate files that are stored verbatim, like rustc does with its ui tests? For example: /~https://github.com/rust-lang/rust/blob/fd8d6fbe505ecf913f5e2ca590c69a7da2789879/tests/ui/nll/issue-50716.stderr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ron output:

CommandOutput(
  exit_code: Some(1),
  stderr: "error: no crates with library targets selected, nothing to semver-check\nnote: only library targets contain an API surface that can be checked for semver\nnote: skipped the following crates since they have no library target: bin_only\n",
  stdout: "",
)

I think we can use the default insta::assert_snapshot! on the stdout and stderr, which will use their Display impls, which should print new lines.

Copy link
Owner

Choose a reason for hiding this comment

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

Consider doing a hybrid approach. Make the CommandOutput struct contain three fields: stdout, stderr, and "everything else" inside a single struct that can be ron-serialized and snapshotted that way.

Separately, consider looking at the "redactions" and "filters" features of insta to remove information that will be a source of non-determinism: https://insta.rs/docs/redactions/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like insta provides the insta-cmd crate which does exactly what we want. I refactored to use that.

Copy link
Owner

Choose a reason for hiding this comment

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

Wow, TIL! Nice find, that looks quite good ✨

@suaviloquence suaviloquence force-pushed the add-no-lib-targets-test branch from 0b7e2ee to 3ec951f Compare August 3, 2024 01:55
@suaviloquence suaviloquence force-pushed the add-no-lib-targets-test branch 2 times, most recently from eefb456 to 028a923 Compare August 3, 2024 05:19
@suaviloquence suaviloquence force-pushed the add-no-lib-targets-test branch from 028a923 to 81f76bb Compare August 15, 2024 18:24
@suaviloquence
Copy link
Contributor Author

Copy link
Owner

@obi1kenobi obi1kenobi left a comment

Choose a reason for hiding this comment

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

A couple of nitpicks, broadly looks good.

Comment on lines 181 to 182
/// Running `cargo semver-checks --workspace` on a workspace that has library
/// targets should be an error.
Copy link
Owner

Choose a reason for hiding this comment

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

typo, presumably?

Suggested change
/// Running `cargo semver-checks --workspace` on a workspace that has library
/// targets should be an error.
/// Running `cargo semver-checks --workspace` on a workspace that
/// doesn't have any library targets should be an error.

Copy link
Owner

Choose a reason for hiding this comment

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

Is the addition of files under .../new/new/ intentional here?

@obi1kenobi obi1kenobi merged commit 0ed4827 into obi1kenobi:main Aug 16, 2024
33 checks passed
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