-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix testing packages with multiple targets #19005
base: master
Are you sure you want to change the base?
fix testing packages with multiple targets #19005
Conversation
d1acee6
to
9e4161c
Compare
This comment has been minimized.
This comment has been minimized.
Ah sorry I forgot this. Now that the |
adcd9cf
to
c756cb6
Compare
c756cb6
to
1a9da62
Compare
Oh that's great, thank you @HKalbasi ! Do you have any thoughts about adding some testing to this feature? Having seen the dizzying number of permutations of how tests are defined and how they might be invoked I'm nervous about regressions. I'm thinking of an integration test using a sample workspace that tries to define every type of test and we might be able to simulate vscode interaction with "code --command" . |
If you want to add some end to end tests, look at https://github.com/rust-lang/rust-analyzer/blob/master/crates/rust-analyzer/tests/slow-tests/main.rs which creates a cargo project and communicate with rust-analyzer using lsp. But those tests slowdown CI so I would suggest having at most one test about test-explorer there (which can test many operations, most of the time is spent on the loading) and test other corner cases using unit tests that takes some hard coded json of cargo and/or assert text of the cargo commands instead of executing them. |
TargetKind::Example => "example", | ||
TargetKind::Test => "test", | ||
TargetKind::Bench => "bench", | ||
TargetKind::BuildScript => "custom-build", |
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.
TargetKind::BuildScript => "custom-build", | |
TargetKind::BuildScript => "build-script", |
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.
The actual name cargo uses for this target kind is custom-build
which is what needs to be used in commands and interpreting output.
https://docs.rs/cargo_metadata/latest/cargo_metadata/struct.Target.html
I'm using the display trait for formatting cargo arguments (maybe this is wrong?) so this change would require a new function to_cargo_str
or something. If your desire is to fix the code-smell of the display not matching the enum, a more correct change might be to change the enum name from BuildScript
to CustomBuild
.
(possibly a little moot for this bug fix since I'm not sure cargo test accepts tests in custom-build targets and I haven't tested it)
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's make this a method (instead of Display
) and give it a comment regarding what you explained to me (that is that these strings are significant to cargo).
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.
Done.
Much clearer intention and can now return an option to make it clear that not all RA TargetKinds can be converted to a Cargo TargetKinds.
crates/rust-analyzer/src/command.rs
Outdated
@@ -14,23 +14,60 @@ use process_wrap::std::{StdChildWrapper, StdCommandWrap}; | |||
use stdx::process::streaming_output; | |||
|
|||
/// Cargo output is structured as a one JSON per line. This trait abstracts parsing one line of | |||
/// cargo output into a Rust data type. | |||
/// cargo output into a Rust data type where the data is self-describing. | |||
pub(crate) trait ParseFromLine: Sized + Send + 'static { |
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.
Can we just discard this trait in favor of CargoParser
? This code is already fairly convoluted and this isn't really helping that
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.
I believe it can. Shall I make the change?
(I implemented this as an additional trait to minimise the level of change to unrelated code. I didn't know if there were particular motivations for the stateless parser and changing every Cargo invocation seemed like I would be over-presumptuous.)
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.
I guess its fine for now
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.
Done.
I went ahead to see what was affected and it was minimal and a decent simplification. If you don't want it, I'll back it out.
This comment has been minimized.
This comment has been minimized.
ef40ec7
to
07446d6
Compare
07446d6
to
8eff517
Compare
b6be8c6
to
5e2b50f
Compare
fix test running by invoking cargo per package remove hack_recover_crate_name make clippy happy fix testing for packages with multiple targets fix test running by invoking cargo per package remove hack_recover_crate_name make clippy happy fix testing for packages with multiple targets fix bad merge replace TargetKind::fmt with TargetKind::as_cargo_target to clarify intention dedupulicate requested test runs replace ParseFromLine with CargoParser formatting - remove trailing space formatting for rustfmt CI
5e2b50f
to
2f5a7a6
Compare
Looks good to me now, though I don't know anything about the test runner code so thats up to @HKalbasi to decide |
@HKalbasi good to go? |
This PR fixes #18955 and other bugs related to RA executing the wrong test and/or assigning results incorrectly.
It makes test execution aware of the difference between packages and targets.
It removes the need to use
hack_recover_crate_name
to match test output to tests.request::handle_run_test
test_runner::CargoTestHandle
CargoActor
main_loop
CargoTestMessage
in the event queue now contains the required information to assign to correct test