-
Notifications
You must be signed in to change notification settings - Fork 44
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 tests for --dry-run
and cargo ws plan
#157
Open
popzxc
wants to merge
4
commits into
pksunkara:master
Choose a base branch
from
popzxc:dry-run-fix-plus-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Contributing to `cargo-workspaces` | ||
|
||
If you want to contribute to the project, take a look at [open issues](https://github.com/pksunkara/cargo-workspaces/issues) | ||
or create a PR. | ||
|
||
Please make sure that new functionality has tests. | ||
|
||
## Running tests | ||
|
||
The recommended way to run tests for the crate is as follows: | ||
|
||
```sh | ||
cargo test --manifest-path cargo-workspaces/Cargo.toml -j1 | ||
``` | ||
|
||
The integration tests manipulate the file system, so running them from multiple threads | ||
may cause race conditions and unexpected failures. | ||
|
||
### Adding tests and updating snapshots | ||
|
||
`cargo-workspaces` uses [`insta`](https://docs.rs/insta/) for snapshot testing. | ||
|
||
When updating tests, you may run tests via: | ||
|
||
``` | ||
INSTA_UPDATE=always cargo test <args> | ||
``` | ||
|
||
If you don't want to override any existing snapshots, use: | ||
|
||
``` | ||
INSTA_UPDATE=unseen cargo test <args> | ||
``` | ||
|
||
Always make sure that generated snapshots match what you expect the test to produce. | ||
Do not blindly commit changes in snapshots that you do not anticipate. | ||
|
||
For more details, check the `insta` documentation. | ||
|
||
### Troubleshooting | ||
|
||
If you observe unexpected differences in snapshots, you may want to override your compiler to | ||
the same version as used in [CI](.github/workflows/ci.yml), e.g.: | ||
|
||
``` | ||
cargo override set 1.70 | ||
``` | ||
|
||
The newer versions of `cargo` may produce different output, which would break snapshot tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,9 @@ impl Publish { | |
} | ||
} | ||
|
||
info!("success", "ok"); | ||
if !self.dry_run { | ||
info!("success", "ok"); | ||
} | ||
Ok(()) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
mod utils; | ||
use insta::assert_snapshot; | ||
|
||
#[test] | ||
fn test_plan_single() { | ||
// `err` may contain a warning about missing `http.cainfo` config value. | ||
let (out, _err) = utils::run("../fixtures/single", &["ws", "plan"]); | ||
assert_snapshot!(out); | ||
} | ||
|
||
#[test] | ||
fn test_plan_normal() { | ||
// `err` may contain a warning about missing `http.cainfo` config value. | ||
let (out, _err) = utils::run("../fixtures/normal", &["ws", "plan"]); | ||
assert_snapshot!(out); | ||
} | ||
|
||
#[test] | ||
fn test_plan_normal_long() { | ||
// `err` may contain a warning about missing `http.cainfo` config value. | ||
let (out, _err) = utils::run("../fixtures/normal", &["ws", "plan", "--long"]); | ||
assert_snapshot!(out); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
mod utils; | ||
use insta::assert_snapshot; | ||
|
||
#[test] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see some test failures caused by parallel execution. |
||
fn test_dry_run_single() { | ||
// `--allow-dirty` is supplied to not break tests during development. | ||
let mut err = utils::run_err( | ||
"../fixtures/single", | ||
&["ws", "publish", "--dry-run", "--allow-dirty"], | ||
); | ||
utils::normalize_output(&mut err); | ||
assert_snapshot!(err); | ||
} | ||
|
||
#[test] | ||
fn test_dry_run_normal() { | ||
// `--allow-dirty` is supplied to not break tests during development. | ||
let mut err = utils::run_err( | ||
"../fixtures/normal", | ||
&["ws", "publish", "--dry-run", "--allow-dirty"], | ||
); | ||
utils::normalize_output(&mut err); | ||
assert_snapshot!(err); | ||
} | ||
|
||
#[test] | ||
fn test_dry_run_normal_missing_fields() { | ||
// `--allow-dirty` is supplied to not break tests during development. | ||
let mut err = utils::run_err( | ||
"../fixtures/normal_missing_fields", | ||
&["ws", "publish", "--dry-run", "--allow-dirty"], | ||
); | ||
utils::normalize_output(&mut err); | ||
assert_snapshot!(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,17 @@ name = "dep1" | |
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "dep1" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
[package] | ||
name = "dep2" | ||
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "dep2" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
pre_dep1 = { version = "0.1.0", path = "../dep1", package = "dep1" } | ||
|
@@ -22,6 +26,8 @@ name = "top" | |
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "top" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
dep = { version = "0.1.0", path = "../dep1", package = "dep1" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
--- | ||
source: tests/exec.rs | ||
assertion_line: 29 | ||
expression: out | ||
|
||
--- | ||
[package] | ||
name = "dep1" | ||
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "dep1" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: tests/plan.rs | ||
expression: out | ||
--- | ||
dep1 | ||
dep2 | ||
top | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: tests/plan.rs | ||
expression: out | ||
--- | ||
dep1 v0.1.0 dep1 | ||
dep2 v0.1.0 dep2 | ||
top v0.1.0 top | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
source: tests/plan.rs | ||
expression: out | ||
--- | ||
simple | ||
|
10 changes: 10 additions & 0 deletions
10
cargo-workspaces/tests/snapshots/publish__dry_run_normal.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
source: tests/publish.rs | ||
expression: err | ||
--- | ||
warn Dry run doesn't check that all dependencies have been published. | ||
warn Dry run doesn't perform versioning. | ||
info checking dep1 | ||
info checking dep2 | ||
info checking top | ||
info success ok |
11 changes: 11 additions & 0 deletions
11
cargo-workspaces/tests/snapshots/publish__dry_run_normal_missing_fields.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
source: tests/publish.rs | ||
expression: err | ||
--- | ||
warn Dry run doesn't check that all dependencies have been published. | ||
warn Dry run doesn't perform versioning. | ||
info checking dep1 | ||
warn check failed 'description' field should be set | ||
info checking dep2 | ||
info checking top | ||
warn failure some checks failed |
8 changes: 8 additions & 0 deletions
8
cargo-workspaces/tests/snapshots/publish__dry_run_single.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
source: tests/publish.rs | ||
expression: err | ||
--- | ||
warn Dry run doesn't check that all dependencies have been published. | ||
warn Dry run doesn't perform versioning. | ||
info checking simple | ||
info success ok |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,7 @@ name = "dep1" | |
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "dep1" | ||
license = "MIT" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ name = "dep2" | |
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "dep2" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
pre_dep1 = { version = "0.1.0", path = "../dep1", package = "dep1" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ name = "top" | |
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "top" | ||
license = "MIT" | ||
|
||
[dependencies] | ||
dep = { version = "0.1.0", path = "../dep1", package = "dep1" } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[workspace] | ||
members = [ | ||
"top", | ||
"dep1", | ||
"dep2", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "dep1" | ||
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
license = "MIT" | ||
|
||
[dependencies] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "dep2" | ||
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
description = "dep2" | ||
|
||
[dependencies] | ||
pre_dep1 = { version = "0.1.0", path = "../dep1", package = "dep1" } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "top" | ||
version = "0.1.0" | ||
authors = ["Pavan Kumar Sunkara <[email protected]>"] | ||
edition = "2018" | ||
keywords = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven"] | ||
|
||
[dependencies] | ||
dep = { version = "0.1.0", path = "../dep1", package = "dep1" } | ||
dep2 = { version = "0.1.0", path = "../dep2" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You don't need the
j1
if you add#[serial]
to all the tests.