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

move one snapshot/add test into testsuite/cargo_add/ #10631

Merged
merged 1 commit into from
May 6, 2022

Conversation

Muscraft
Copy link
Member

@Muscraft Muscraft commented May 4, 2022

This is an experiment with moving the test code related to a snapshot into the testsuite directory so it's easier to review.

  • To kick the tire on these changes, a single test was ported

This is a step towards #10627. A follow up will port all of the tests

r? @epage

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 2022
crates/cargo-test-macro/build.rs Outdated Show resolved Hide resolved
crates/cargo-test-support/src/lib.rs Outdated Show resolved Hide resolved
tests/testsuite/main.rs Outdated Show resolved Hide resolved
tests/testsuite/main.rs Outdated Show resolved Hide resolved
crates/cargo-test-macro/src/lib.rs Outdated Show resolved Hide resolved
crates/cargo-test-macro/src/lib.rs Outdated Show resolved Hide resolved
@Muscraft Muscraft force-pushed the move-snapshot-tests branch 3 times, most recently from 29921ca to e40350f Compare May 5, 2022 14:32
build.rs Outdated
@@ -11,6 +11,7 @@ fn main() {
"cargo:rustc-env=RUST_HOST_TARGET={}",
std::env::var("TARGET").unwrap()
);
println!("cargo:rerun-if-changed=tests/snapshots");
Copy link
Contributor

Choose a reason for hiding this comment

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

Talking this over with @ehuss, we are concerned about the balance we are striking between writing new tests and the cost of rebuilding. In case its not clear, this line means that any time anything in the snapshots directory changes, whether directly by the user or from rebase from master, all of cargo, lib and bin, will rebuild.

If we had globbing support in rerun-if-changed, we could limit this to just tests/snapshots/*/*/mod.rs which might still cause too many rebuilds.

I know we proposed this solution and you put in a lot of work to learn how to write the function-like macro and get this working but I think we should change to a naive / macro-less solution for now where we rename tests/testsuite/cargo_add.rs to tests/testsuite/cargo_add/mod.rs and tests/snapshots/add/add_basic/mod.rs to tests/testsuite/cargo_add/add_basic/mod.rs and move the snapshots along with it so we can just mod add_basic; in cargo_add/mod.rs. The downside is that test writers have to make sure they keep the linkage up-to-date and don't add tests without linking them in but we already have that problem in tests/testsuite.

Copy link
Member Author

Choose a reason for hiding this comment

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

I completely agree with this decision. I do not think the rebuilds were worth it, even while testing this and making changes it was happening. It wasn't bad because I have a fast machine but it still slowed things down. It also completely mitigated some of the benefits of snapshot.

I like the proposed solution better than using a macro here. Even if rerun-if-changed supported globs the explicitness of having to add a test might be nice. As for the downsides of having to remember to link everything up, for me personally, I don't think it's a problem since Clion says if a mod.rs isn't attached anywhere. That being said it may be nice to have something more set up so you don't have to manage paths in a mod.rs test

Copy link
Member

Choose a reason for hiding this comment

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

rename tests/testsuite/cargo_add.rs to tests/testsuite/cargo_add/mod.rs and tests/snapshots/add/add_basic/mod.rs to tests/testsuite/cargo_add/add_basic/mod.rs

Would this end up making more files with only one test case inside? I can imagine it is a little annoying when navigating a group of related tests but you need to jump back and forth between files.

Copy link
Contributor

Choose a reason for hiding this comment

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

The whole aim of this direction is to have a file per test function, regardless of what the files are renamed. I've been dealing with this in my other crates with trycmd and its not bad. I also see a lot of this as an experiment. We'll try things out, see what we think, and change as needed.

@Muscraft Muscraft changed the title move snapshot tests into snapshot directory move one snapshot/add test into testsuite/cargo_add/ May 6, 2022
@epage epage marked this pull request as ready for review May 6, 2022 15:56
@epage
Copy link
Contributor

epage commented May 6, 2022

@bors r+

@bors
Copy link
Contributor

bors commented May 6, 2022

📌 Commit ea31298 has been approved by epage

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 6, 2022
@bors
Copy link
Contributor

bors commented May 6, 2022

⌛ Testing commit ea31298 with merge acaf8e2...

@bors
Copy link
Contributor

bors commented May 6, 2022

☀️ Test successful - checks-actions
Approved by: epage
Pushing acaf8e2 to master...

@bors bors merged commit acaf8e2 into rust-lang:master May 6, 2022
bors added a commit that referenced this pull request May 7, 2022
Move snapshot tests into testsuite

This moves all tests from the `snapshot` folder into the `testsuite` folder as described by [this comment](#10631 (comment)). A macro was also added so there is no need to specify the path in a `snapshot` test just the file. This was done for ease of refactoring and ease of porting new tests to `snapshot`

close #10627

r? `@epage`
bors added a commit to rust-lang-ci/rust that referenced this pull request May 12, 2022
Update cargo

20 commits in a44758ac805600edbb6ba51e7e6fb81a6077c0cd..3f052d8eed98c6a24f8b332fb2e6e6249d12d8c1
2022-05-04 02:29:34 +0000 to 2022-05-12 15:19:04 +0000
- pre-stabilization documentation for workspace inheritance (rust-lang/cargo#10659)
- test: Make curr_dir work in/out of workspace (rust-lang/cargo#10658)
- Fix no_cross_doctests race condition. (rust-lang/cargo#10660)
- Fix typo (rust-lang/cargo#10657)
- feat(install): Support `foo@version` like cargo-add (rust-lang/cargo#10650)
- fix typos found by the `typos-cli` crate (rust-lang/cargo#10649)
- feat(yank): Support foo@version like cargo-add (rust-lang/cargo#10597)
- add `cargo-features` to unstable docs for workspace inheritance (rust-lang/cargo#10648)
- Use the traits added to the Rust 2021 Edition prelude (rust-lang/cargo#10646)
- Pass `--target` to `rustdoc` for `cargo test` if specified with host target. (rust-lang/cargo#10594)
- Fix use of .. in dep-info-basedir (rust-lang/cargo#10281)
- fix some typos (rust-lang/cargo#10639)
- Move snapshot tests into testsuite (rust-lang/cargo#10638)
- Improve support of condition compilation checking (rust-lang/cargo#10566)
- When documenting private items in a binary, ignore warnings about links to private items (rust-lang/cargo#10142)
- Extend pkgid syntax with ``@`` support (rust-lang/cargo#10582)
- move one `snapshot/add` test into `testsuite/cargo_add/` (rust-lang/cargo#10631)
- Add caveat for covering features (rust-lang/cargo#10605)
- Improve CARGO_ENCODED_RUSTFLAGS and CARGO_ENCODED_RUSTDOCFLAGS variables docs (rust-lang/cargo#10633)
- reorganize `snapshot` tests to better work in contexts that sort by extension (rust-lang/cargo#10629)
@ehuss ehuss added this to the 1.62.0 milestone May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants