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

refactor(test): Clarify asserts are for UI #10778

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ use url::Url;
/// Other heuristics are applied to try to ensure Windows-style paths aren't
/// a problem.
/// - Carriage returns are removed, which can help when running on Windows.
pub fn assert() -> snapbox::Assert {
pub fn assert_ui() -> snapbox::Assert {
let root = paths::root();
// Use `from_file_path` instead of `from_dir_path` so the trailing slash is
// put in the users output, rather than hidden in the variable
Expand Down
6 changes: 3 additions & 3 deletions crates/cargo-test-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,13 +1262,13 @@ impl TestEnv for snapbox::cmd::Command {

/// Test the cargo command
pub trait CargoCommand {
fn cargo() -> Self;
fn cargo_ui() -> Self;
}

impl CargoCommand for snapbox::cmd::Command {
fn cargo() -> Self {
fn cargo_ui() -> Self {
Self::new(cargo_exe())
.with_assert(compare::assert())
.with_assert(compare::assert_ui())
.test_env()
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/doc/contrib/src/tests/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ mod <case>;
`tests/testsuite/<command>/<case>/mod.rs`:
```rust,ignore
use cargo_test_support::prelude::*;
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::Project;
use cargo_test_support::curr_dir;

Expand All @@ -139,7 +139,7 @@ fn <name>() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("run")
.arg_line("--bin foo")
.current_dir(cwd)
Expand All @@ -148,7 +148,7 @@ fn <name>() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
```

Expand All @@ -170,13 +170,13 @@ Then populate
- The project is copied from a directory in the repo
- Each project is in a separate directory in the sandbox

[`Command`] via `Command::cargo()`:
[`Command`] via `Command::cargo_ui()`:
- Set up and run a command.

[`OutputAssert`] via `Command::assert()`:
- Perform assertions on the result of the [`Command`]

[`Assert`] via `assert()`:
[`Assert`] via `assert_ui()`:
- Verify the command modified the file system as expected

#### Updating Snapshots
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/add_basic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn add_basic() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn add_basic() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/add_multiple/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn add_multiple() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package1 my-package2")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn add_multiple() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/add_normalized_name_external/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn add_normalized_name_external() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("linked_hash_map Inflector")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn add_normalized_name_external() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/build/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn build() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("--build my-build-package1 my-build-package2")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn build() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn build_prefer_existing_version() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("cargo-list-test-fixture-dependency --build")
.current_dir(cwd)
Expand All @@ -21,7 +21,7 @@ fn build_prefer_existing_version() {
.stdout_matches_path("tests/testsuite/cargo_add/build_prefer_existing_version/stdout.log")
.stderr_matches_path("tests/testsuite/cargo_add/build_prefer_existing_version/stderr.log");

assert().subset_matches(
assert_ui().subset_matches(
"tests/testsuite/cargo_add/build_prefer_existing_version/out",
&project_root,
);
Expand Down
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/change_rename_target/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn change_rename_target() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package2 --rename some-package")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn change_rename_target() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/default_features/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn default_features() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package1 my-package2@0.4.1 --default-features")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn default_features() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/deprecated_default_features/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn deprecated_default_features() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package")
.current_dir(&cwd)
Expand All @@ -21,5 +21,5 @@ fn deprecated_default_features() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/deprecated_section/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn deprecated_section() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package")
.current_dir(&cwd)
Expand All @@ -21,5 +21,5 @@ fn deprecated_section() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/detect_workspace_inherit/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn detect_workspace_inherit() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.masquerade_as_nightly_cargo()
.arg("add")
.args(["foo", "-p", "bar"])
Expand All @@ -22,5 +22,5 @@ fn detect_workspace_inherit() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn detect_workspace_inherit_features() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.masquerade_as_nightly_cargo()
.arg("add")
.args(["foo", "-p", "bar", "--features", "test"])
Expand All @@ -22,5 +22,5 @@ fn detect_workspace_inherit_features() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn detect_workspace_inherit_optional() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.masquerade_as_nightly_cargo()
.arg("add")
.args(["foo", "-p", "bar", "--optional"])
Expand All @@ -22,5 +22,5 @@ fn detect_workspace_inherit_optional() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/dev/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn dev() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("--dev my-dev-package1 my-dev-package2")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn dev() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
6 changes: 3 additions & 3 deletions tests/testsuite/cargo_add/dev_build_conflict/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cargo_test_support::compare::assert;
use cargo_test_support::compare::assert_ui;
use cargo_test_support::prelude::*;
use cargo_test_support::Project;

Expand All @@ -12,7 +12,7 @@ fn dev_build_conflict() {
let project_root = project.root();
let cwd = &project_root;

snapbox::cmd::Command::cargo()
snapbox::cmd::Command::cargo_ui()
.arg("add")
.arg_line("my-package --dev --build")
.current_dir(cwd)
Expand All @@ -21,5 +21,5 @@ fn dev_build_conflict() {
.stdout_matches_path(curr_dir!().join("stdout.log"))
.stderr_matches_path(curr_dir!().join("stderr.log"));

assert().subset_matches(curr_dir!().join("out"), &project_root);
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
}
Loading