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

Allow multiple executions for test targets #29

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bluejekyll
Copy link

I've been working with cargo-make recently, and coverage reports weren't accurate. I came across this project, and found the requirement to specify which test you wanted to run to be a little onerous.

This change essentially loops over all targets that might have tests, we might want the others, but right now, lib, tests, bin, and examples are supported. Not sure if we'll want to use this. When this is combined with --all-targets, --bins, --examples, and/or --tests this should work.

I'm only posting a draft for feedback at the moment. I need to add a test to cover this before it's ready.

Thanks for the great project!

@cbourjau
Copy link
Owner

Thanks for the PR and I'm glad you find this project useful! Just so that I understand you correctly: You want to build a project and run all (as in N >= 1) artifacts individually through whatever command you give. As you have certainly noticed, the current behavior was to expect one final binary or else we assumed that there must have been an error. That said, the current behavior was more of a conservative guess based on some "reverse engineering" of the data provided by cargo. From the top of my head I don't see a reason why we could not relax the current behavior. Do I get understand you correctly?

@bluejekyll
Copy link
Author

Yes, you understand what I'm doing here. I did this quickly, and it works for my use case. I think the restriction that was there before is correct for other targets, like run, but for test there are many targets.

For an example of it's usage, see here: https://github.com/bluejekyll/trust-dns/blob/3b6b50e99fbe7503e0248deb74bf4664b381923f/Makefile.toml#L415-L416

This will end up expanding to these, as can be seen in the logs:

2019-12-19T17:34:56.9159285Z Executing `cargo test --message-format=json --no-run --lib --bins --tests --examples --all-features`
2019-12-19T17:34:57.0345337Z     Finished test [unoptimized + debuginfo] target(s) in 0.11s
2019-12-19T17:34:57.0683572Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/trust_dns_server-97286ed9f2ae8597"
2019-12-19T17:34:58.2476905Z 
2019-12-19T17:34:58.2477279Z running 3 tests
2019-12-19T17:34:58.2515384Z test authority::message_response::tests::test_truncation_ridiculous_number_nameservers ... ok
2019-12-19T17:34:58.2530009Z test authority::message_response::tests::test_truncation_ridiculous_number_answers ... ok
2019-12-19T17:34:58.2609419Z test store::file::authority::tests::test_load_zone ... ok
2019-12-19T17:34:58.2609972Z 
2019-12-19T17:34:58.2610422Z test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
2019-12-19T17:34:58.2610750Z 
2019-12-19T17:34:58.2738300Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/txt_tests-89c5a98c1b58d52a"
2019-12-19T17:35:00.3942532Z 
2019-12-19T17:35:00.3943597Z running 4 tests
2019-12-19T17:35:00.3988778Z test test_bad_cname_at_a ... ok
2019-12-19T17:35:00.3991247Z test test_aname_at_soa ... ok
2019-12-19T17:35:00.4064386Z test test_bad_cname_at_soa ... ok
2019-12-19T17:35:00.4132802Z test test_zone ... ok
2019-12-19T17:35:00.4133239Z 
2019-12-19T17:35:00.4133665Z test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
2019-12-19T17:35:00.4133893Z 
2019-12-19T17:35:00.4346247Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/timeout_stream_tests-0c462bacc1eb75b5"
2019-12-19T17:35:01.2085912Z 
2019-12-19T17:35:01.2086331Z running 2 tests
2019-12-19T17:35:01.2118519Z test test_no_timeout ... ok
2019-12-19T17:35:01.2133206Z test test_timeout ... ok
2019-12-19T17:35:01.2133652Z 
2019-12-19T17:35:01.2134067Z test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
2019-12-19T17:35:01.2134979Z 
2019-12-19T17:35:01.2331663Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/config_tests-65cb2c99f038902b"
2019-12-19T17:35:02.6652468Z 
2019-12-19T17:35:02.6653287Z running 17 tests
2019-12-19T17:35:02.6695283Z test dns_over_https ... ok
2019-12-19T17:35:02.6718387Z test all_supported_dnssec ... ok
...
2019-12-19T17:35:02.6996259Z test test_parse_zone_keys ... ok
2019-12-19T17:35:02.7027986Z test test_read_config ... ok
2019-12-19T17:35:02.7029756Z 
2019-12-19T17:35:02.7031301Z test result: ok. 17 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
2019-12-19T17:35:02.7032728Z 
2019-12-19T17:35:02.7311127Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/store_sqlite_tests-c18619bb97ca2cfb"
2019-12-19T17:35:04.6864090Z 
2019-12-19T17:35:04.6865036Z running 36 tests
2019-12-19T17:35:04.7403683Z test basic::sqlite::test_a_lookup ... ok
...
2019-12-19T17:35:06.1830214Z test dynamic_update::sqlite_update::test_delete_rrset ... ok
2019-12-19T17:35:06.1830315Z 
2019-12-19T17:35:06.1830466Z test result: ok. 36 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
2019-12-19T17:35:06.1830569Z 
2019-12-19T17:35:06.2262686Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/sqlite_tests-049ec6c9f4442176"
2019-12-19T17:35:07.6731137Z 
2019-12-19T17:35:07.6732180Z running 4 tests
2019-12-19T17:35:07.6795051Z test test_insert_and_select_record ... ok
2019-12-19T17:35:07.6802431Z test test_init_journal ... ok
2019-12-19T17:35:07.6831510Z test test_new_journal ... ok
2019-12-19T17:35:07.6844545Z test test_iterator ... ok
2019-12-19T17:35:07.6844959Z 
2019-12-19T17:35:07.6845346Z test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
2019-12-19T17:35:07.6845568Z 
2019-12-19T17:35:07.7207386Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/forwarder-c09fea26fdabc6ad"
2019-12-19T17:35:10.4041091Z 
2019-12-19T17:35:10.4041992Z running 1 test
2019-12-19T17:35:10.4042524Z test test_lookup ... ignored
2019-12-19T17:35:10.4043255Z 
2019-12-19T17:35:10.4043781Z test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
2019-12-19T17:35:10.4044463Z 
2019-12-19T17:35:10.4407752Z Executing with: "/home/runner/work/trust-dns/trust-dns/target/kcov//build/src//kcov" "--include-pattern=/home/runner/work/trust-dns/trust-dns/crates/server/src/" "/home/runner/work/trust-dns/trust-dns/target/coverage/trust_dns_server" "/home/runner/work/trust-dns/trust-dns/target/debug/store_file_tests-dc6592a4d11441cd"
2019-12-19T17:35:12.0638988Z 
2019-12-19T17:35:12.0639807Z running 27 tests
2019-12-19T17:35:12.0780014Z test basic::file::test_a_lookup ... ok
...
2019-12-19T17:35:12.7229930Z test dnssec::file::test_wildcard ... ok
2019-12-19T17:35:12.7230265Z 
2019-12-19T17:35:12.7230595Z test result: ok. 27 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Copy link
Owner

@cbourjau cbourjau left a comment

Choose a reason for hiding this comment

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

Thanks again for this PR and sorry for the delay; I was off the grid over the holidays. I think there are only a few things missing before we can merge this, I think. If you could think of potential corner-case we should test it would be even better.

@@ -61,7 +61,7 @@ impl<'a> CargoCmd<'a> {

/// Run the cargo command and get the output back as a vector
pub(crate) fn run(&self) -> Result<CargoBuildOutput, Error> {
debug!(
println!(
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure we want to print this by default

Copy link
Author

Choose a reason for hiding this comment

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

See the above output. Without this line, we end up with very little information about what command is being run that executes immediately after that.

Copy link
Collaborator

@barskern barskern Dec 30, 2019

Choose a reason for hiding this comment

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

You could use info instead of debug here.

}

/// Selects the buildopt which fits with the requirements
///
/// If there are multiple possible candidates, this will return an error
fn select_buildopt(&self) -> Result<&CargoBuildOutputElement, Error> {
fn select_buildopt(&self) -> Result<Vec<PathBuf>, Error> {
Copy link
Owner

Choose a reason for hiding this comment

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

Now that this function can return several paths the docs and names should be updated

@@ -201,14 +201,14 @@ struct Target {
}

impl<'a> CargoBuildOutput<'a> {
pub(crate) fn artifact(&self) -> Result<PathBuf, Error> {
Ok(self.select_buildopt()?.artifact())
pub(crate) fn artifact(&self) -> Result<Vec<PathBuf>, Error> {
Copy link
Owner

Choose a reason for hiding this comment

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

Function name should reflect that this returns multiple artifacts

@@ -233,33 +233,51 @@ impl<'a> CargoBuildOutput<'a> {
// We expect exactly one candidate; everything else is 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.

With this change, we should also update the comments in this regard.

@@ -233,33 +233,51 @@ impl<'a> CargoBuildOutput<'a> {
// We expect exactly one candidate; everything else is an error
match candidates.as_slice() {
[] => Err(err_msg("No suitable build artifacts found.")),
[ref the_one] => Ok(the_one),
[ref the_one] => Ok(vec![the_one.artifact()]),
Copy link
Owner

Choose a reason for hiding this comment

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

Is there a reason to still differentiate between one and several artifacts here?

@@ -26,7 +26,7 @@ fn main() {
}

// Make a separate runner to print errors using Display instead of Debug
fn try_main() -> Result<Void, Error> {
fn try_main() -> Result<(), Error> {
Copy link
Owner

Choose a reason for hiding this comment

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

I can't remember the reason for using Void, but thanks for getting rid of that dependency! Could you also fix the unused import and the Cargo.toml file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Before we used exec in the sense that it "took over" the current process to run the new command. That way instead of using pipes etc. for stdin and stdout, the started command (such as gdb) would be executed in place of the cargo with command. Not doing this might have unfortunate consequences when using interactive commands, hence we have to make sure that this PR doesn't break that usecase.

Copy link
Author

Choose a reason for hiding this comment

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

that's a very good point. I could leave this function alone, possibly, and execute in a different manner with one of the below options.

@barskern
Copy link
Collaborator

barskern commented Dec 29, 2019

As an aside, this is a breaking change hence I think it should be "hidden" behind a cli option. --accept-all or --multiple perhaps?

@cbourjau
Copy link
Owner

As an aside, this is a breaking change hence I think it should be "hidden" behind a cli option. --accept-all or --multiple perhaps?

Is it? Previously execution aborted with non-zero exit code in these cases. Now such cases succeed. So its not breaking something which was working previously, but enables a few things which failed previously. I don't think that stability guarantees should extend to failures - at least not for a small 0.x tool. Or am I missing something?

@barskern
Copy link
Collaborator

barskern commented Dec 29, 2019

That's a fair point. I was just thinking about the situation where you would expect the tool to fail, but now it continues. Let's say you want to examine the tests of your library, but not your binary, with the same name. Previously it would error explaining you to be more specific, but now it will just throw you into a gdb environment which debugs both the binary and library.

I am not sure what classifies a breaking change using minor versions though, so I may be wrong.

EDIT: And as you say, turning an error into success is probably not a breaking change after all.

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.

3 participants