}
fn lines_match(expected: &str, mut actual: &str) -> bool {
- for part in expected.split("[..]") {
+ for (i, part) in expected.split("[..]").enumerate() {
match actual.find(part) {
- Some(i) => actual = &actual[i + part.len()..],
+ Some(j) => {
+ if i == 0 && j != 0 {
+ return false
+ }
+ actual = &actual[j + part.len()..];
+ }
None => {
return false
}
actual.is_empty() || expected.ends_with("[..]")
}
+#[test]
+fn lines_match_works() {
+ assert!(lines_match("a b", "a b"));
+ assert!(lines_match("a[..]b", "a b"));
+ assert!(lines_match("a[..]", "a b"));
+ assert!(lines_match("[..]", "a b"));
+ assert!(lines_match("[..]b", "a b"));
+
+ assert!(!lines_match("[..]b", "c"));
+ assert!(!lines_match("b", "c"));
+ assert!(!lines_match("b", "cb"));
+}
+
// Compares JSON object for approximate equality.
// You can use `[..]` wildcard in strings (useful for OS dependent things such as paths).
// Arrays are sorted before comparison.
execs().with_status(101)
.with_stderr("no such subcommand
-Did you mean `build`?
+<tab>Did you mean `build`?
"));
});
.arg("-p").arg("foo"),
execs().with_status(0)
.with_stdout(&format!("\
-Updating git repository `{}`
-", foo.url())));
+{updating} git repository `{}`
+", foo.url(), updating = UPDATING)));
});
test!(switch_deps_does_not_update_transitive {
assert_that(p.cargo("build"),
execs().with_status(0)
.with_stdout(&format!("\
-Updating git repository `{}`
-Updating git repository `{}`
+{updating} git repository `{}`
+{updating} git repository `{}`
{compiling} transitive [..]
{compiling} dep [..]
{compiling} project [..]
-", dep1.url(), transitive.url(), compiling = COMPILING)));
+", dep1.url(), transitive.url(), compiling = COMPILING, updating = UPDATING)));
// Update the dependency to point to the second repository, but this
// shouldn't update the transitive dependency which is the same.
assert_that(p.cargo("build"),
execs().with_status(0)
.with_stdout(&format!("\
-Updating git repository `{}`
+{updating} git repository `{}`
{compiling} dep [..]
{compiling} project [..]
-", dep2.url(), compiling = COMPILING)));
+", dep2.url(), compiling = COMPILING, updating = UPDATING)));
});
test!(update_one_source_updates_all_packages_in_that_git_source {
assert_that(p.cargo("test"),
execs().with_status(0)
.with_stdout(&format!("\
-{} [..] v0.5.0 ({})
-{} [..] v0.5.0 ({})
-Running target[..]foo-[..]
+{compiling} [..] v0.5.0 ({url})
+{compiling} [..] v0.5.0 ({url})
+{running} target[..]foo-[..]
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
-", COMPILING, p.url(), COMPILING, p.url())));
+", url = p.url(), compiling = COMPILING, running = RUNNING)));
});
test!(custom_target_no_rebuild {
assert_that(cargo_process("foo"),
execs().with_status(0).with_stdout("bar\n"));
assert_that(cargo_process("--list"),
- execs().with_status(0).with_stdout_contains(" foo\n"));
+ execs().with_status(0).with_stdout_contains(" foo\n"));
});
test!(installs_from_cwd_by_default {
assert_that(p.cargo_process("build").arg("--release"),
execs().with_status(0));
assert_that(cargo_process("install").arg("--path").arg(p.root()),
- execs().with_status(0).with_stdout("\
- Installing [..]
-").with_stderr("\
+ execs().with_status(0).with_stdout(&format!("\
+{installing} [..]
+", installing = INSTALLING)).with_stderr("\
be sure to add `[..]` to your PATH to be able to run the installed binaries
"));
assert_that(cargo_process("install").arg("cargo-fail"),
execs().with_status(0));
assert_that(cargo_process("--list"),
- execs().with_status(0).with_stdout_contains(" fail\n"));
+ execs().with_status(0).with_stdout_contains(" fail\n"));
assert_that(cargo_process("fail"),
execs().with_status(101).with_stderr_contains("\
thread '<main>' panicked at 'explicit panic', [..]