Skip to content

Commit cbd4edb

Browse files
committed
refactor(test): Clarify asserts are for UI
In writing the contrib documentation for functional vs ui tests, I realized that as we work to make snapbox work for the functional tests, we'll need distinct `Assert` objects since we'll want to elide a lot more content in functional tests. I'm making room for this by qualifying the existing asserts as being for "ui".
1 parent c9d8c28 commit cbd4edb

File tree

144 files changed

+421
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+421
-421
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use url::Url;
7070
/// Other heuristics are applied to try to ensure Windows-style paths aren't
7171
/// a problem.
7272
/// - Carriage returns are removed, which can help when running on Windows.
73-
pub fn assert() -> snapbox::Assert {
73+
pub fn assert_ui() -> snapbox::Assert {
7474
let root = paths::root();
7575
// Use `from_file_path` instead of `from_dir_path` so the trailing slash is
7676
// put in the users output, rather than hidden in the variable

crates/cargo-test-support/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,13 +1262,13 @@ impl TestEnv for snapbox::cmd::Command {
12621262

12631263
/// Test the cargo command
12641264
pub trait CargoCommand {
1265-
fn cargo() -> Self;
1265+
fn cargo_ui() -> Self;
12661266
}
12671267

12681268
impl CargoCommand for snapbox::cmd::Command {
1269-
fn cargo() -> Self {
1269+
fn cargo_ui() -> Self {
12701270
Self::new(cargo_exe())
1271-
.with_assert(compare::assert())
1271+
.with_assert(compare::assert_ui())
12721272
.test_env()
12731273
}
12741274
}

src/doc/contrib/src/tests/writing.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod <case>;
129129
`tests/testsuite/<command>/<case>/mod.rs`:
130130
```rust,ignore
131131
use cargo_test_support::prelude::*;
132-
use cargo_test_support::compare::assert;
132+
use cargo_test_support::compare::assert_ui;
133133
use cargo_test_support::Project;
134134
use cargo_test_support::curr_dir;
135135
@@ -139,7 +139,7 @@ fn <name>() {
139139
let project_root = project.root();
140140
let cwd = &project_root;
141141
142-
snapbox::cmd::Command::cargo()
142+
snapbox::cmd::Command::cargo_ui()
143143
.arg("run")
144144
.arg_line("--bin foo")
145145
.current_dir(cwd)
@@ -148,7 +148,7 @@ fn <name>() {
148148
.stdout_matches_path(curr_dir!().join("stdout.log"))
149149
.stderr_matches_path(curr_dir!().join("stderr.log"));
150150
151-
assert().subset_matches(curr_dir!().join("out"), &project_root);
151+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
152152
}
153153
```
154154

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

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

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

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

182182
#### Updating Snapshots

tests/testsuite/cargo_add/add_basic/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

15-
snapbox::cmd::Command::cargo()
15+
snapbox::cmd::Command::cargo_ui()
1616
.arg("add")
1717
.arg_line("my-package")
1818
.current_dir(cwd)
@@ -21,5 +21,5 @@ fn add_basic() {
2121
.stdout_matches_path(curr_dir!().join("stdout.log"))
2222
.stderr_matches_path(curr_dir!().join("stderr.log"));
2323

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/add_multiple/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/add_normalized_name_external/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

15-
snapbox::cmd::Command::cargo()
15+
snapbox::cmd::Command::cargo_ui()
1616
.arg("add")
1717
.arg_line("linked_hash_map Inflector")
1818
.current_dir(cwd)
@@ -21,5 +21,5 @@ fn add_normalized_name_external() {
2121
.stdout_matches_path(curr_dir!().join("stdout.log"))
2222
.stderr_matches_path(curr_dir!().join("stderr.log"));
2323

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/build/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/build_prefer_existing_version/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(
24+
assert_ui().subset_matches(
2525
"tests/testsuite/cargo_add/build_prefer_existing_version/out",
2626
&project_root,
2727
);

tests/testsuite/cargo_add/change_rename_target/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/default_features/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

15-
snapbox::cmd::Command::cargo()
15+
snapbox::cmd::Command::cargo_ui()
1616
.arg("add")
1717
.arg_line("my-package1 [email protected] --default-features")
1818
.current_dir(cwd)
@@ -21,5 +21,5 @@ fn default_features() {
2121
.stdout_matches_path(curr_dir!().join("stdout.log"))
2222
.stderr_matches_path(curr_dir!().join("stderr.log"));
2323

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/deprecated_default_features/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/deprecated_section/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/detect_workspace_inherit/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

25-
assert().subset_matches(curr_dir!().join("out"), &project_root);
25+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2626
}

tests/testsuite/cargo_add/detect_workspace_inherit_features/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

25-
assert().subset_matches(curr_dir!().join("out"), &project_root);
25+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2626
}

tests/testsuite/cargo_add/detect_workspace_inherit_optional/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

25-
assert().subset_matches(curr_dir!().join("out"), &project_root);
25+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2626
}

tests/testsuite/cargo_add/dev/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

tests/testsuite/cargo_add/dev_build_conflict/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cargo_test_support::compare::assert;
1+
use cargo_test_support::compare::assert_ui;
22
use cargo_test_support::prelude::*;
33
use cargo_test_support::Project;
44

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

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

24-
assert().subset_matches(curr_dir!().join("out"), &project_root);
24+
assert_ui().subset_matches(curr_dir!().join("out"), &project_root);
2525
}

0 commit comments

Comments
 (0)