-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Rework cargo-test-support
& testsuite
to use CARGO_BIN_EXE_*
for Cargo
#15692
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
base: master
Are you sure you want to change the base?
Conversation
@@ -2,7 +2,7 @@ | |||
//! | |||
//! # Example | |||
//! | |||
//! ```no_run | |||
//! ```ignore |
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.
Would prefer for these not to be ignore
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 issue is that these example use .cargo()
which is no longer callable in cargo-test-support
. So the example no longer compiles
Perhaps, we can keep it no_run
if we comment (or remove) the .cargo()
calls from the examples.
Maybe something like this for publish.rs
//! let registry = RegistryBuilder::new().http_api().http_index().build();
//!
//! let p = project()
//! .file(...)
//! .file("src/main.rs", "fn main() {}")
//! .build();
//!
//! // p.cargo("publish --no-verify")
//! // .replace_crates_io(registry.index_url())
//! // .run();
//!
//! validate_upload(
//! r#"...."#,
//! "foo-0.0.1.crate",
//! &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
//! );
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.
Either that or we could ust do:
//! validate_upload(
//! r#"...."#,
//! "foo-0.0.1.crate",
//! &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
//! );
tests/testsuite/bad_config.rs
Outdated
@@ -6,6 +6,8 @@ use cargo_test_support::registry::{self, Package}; | |||
use cargo_test_support::str; | |||
use cargo_test_support::{basic_manifest, project, rustc_host}; | |||
|
|||
use crate::utils::ext::CargoProjectExt; |
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.
Should we put this in a prelude and maybe re-export cargo_test_support::prelude::*
in 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.
That could even be done as a refactor commit before any of the other changes
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.
sure, that was something I was considering but didn't end following through with.
I think its a good idea.
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.
Also, we should probably check how https://doc.crates.io/contrib/tests/writing.html needs to be updated
71f7c4a
to
843083d
Compare
843083d
to
b553378
Compare
tests/testsuite/bench.rs
Outdated
use cargo_test_support::{basic_bin_manifest, basic_lib_manifest, basic_manifest, project, str}; | ||
|
||
|
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.
whats this blank line that got added to a lot of these files?
use crate::prelude::*; | ||
|
||
pub mod prelude { | ||
pub use crate::utils::ext::CargoProjectExt; |
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 you split out the creation of CargoProjectExt
from the prelude, as in create the prelude in one commit and then CargoProjectExt
after it?
This touches a lot of files and so being minimal with what is changed can make it a lot easier to review or come back later and see what was done
See also #15692 (comment)
tests/testsuite/alt_registry.rs
Outdated
|
||
use cargo_test_support::compare::assert_e2e; | ||
use crate::prelude::*; | ||
use cargo_test_support::compare::assert_e2e; | ||
use cargo_test_support::publish::validate_alt_upload; | ||
use cargo_test_support::registry::{self, Package, RegistryBuilder}; | ||
use cargo_test_support::str; | ||
use cargo_test_support::{basic_manifest, paths, project}; | ||
|
||
|
||
#[cargo_test] |
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.
This commit seems to have some unrelated changes in it
tests/testsuite/lints/error/mod.rs
Outdated
use crate::prelude::*; | ||
use crate::utils::ext::CargoCommandExt; |
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.
Why is the use
added when its in the prelude
?
b553378
to
1d064ab
Compare
1d064ab
to
02b56d4
Compare
Okay sorry, I cleaned up the commits. (Not quiet sure what happened) I split out the commits as you suggested in this comment and updated the testing documentation as well |
What does this PR try to resolve?
This PR reworks
cargo-test-support
andtestsuite
to use Snapbox'scargo_bin!()
instead ofcargo_bin()
which makes assumptions about the structure of Cargo's build directory.cargo_bin!()
usesCARGO_BIN_EXE_*
for locating thecargo
binary which should be more resilient to directory/layout changes.Linking a relevant Zulip discussion here#t-cargo > cargo_bin_exe and tests
As shown in that link, we could make these variables available at runtime and not need to do this. However,
cargo-test-support
, as an API, is a bit weird in that it is baking in support for one specific binary. This can be confusing for callers and makes it more annoying for callers provide their ownfn cargo
, e.g. see crate-ci/cargo-fixit#7Implementation Notes
cargo_bin!()
only works when being called from thetestsuite
as it's only set when executing integration tests andcargo-test-support
is a regular crate.To make this change, I introduced an extension trait
CargoProjectExt
intestsuite
for running.cargo()
and implemented it onProject
.In
cargo-test-support
other functionality relies on.cargo()
so these also needed to be moved totestsuite
src/tools.rs
src/cross_compile
disabled()
requires running Cargo to check if we should disable cross compile tests.cross_compile
are used incargo-test-support
so moving everything totestsuite
would have ended up requiring moving many things to test suite.How to test and review this PR?
I'd definitely recommend reviewing commit by commit.
There are a lot of diffs due to the nature of reorganizing things.
I did my best to split things things into smaller PRs but they still contain a lot of
use
statement diffs.r? @epage