Skip to content

Commit b6ba7e1

Browse files
committed
Auto merge of #2433 - alexcrichton:fix-lines-match, r=alexcrichton
Right now we only match a suffix of the line, assuming all lines start with `[..]`. Instead this ensures that the first match is anchored at the start.
2 parents bb0f4ae + 1a1d8f8 commit b6ba7e1

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

tests/support/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,14 @@ impl Execs {
440440
}
441441

442442
fn lines_match(expected: &str, mut actual: &str) -> bool {
443-
for part in expected.split("[..]") {
443+
for (i, part) in expected.split("[..]").enumerate() {
444444
match actual.find(part) {
445-
Some(i) => actual = &actual[i + part.len()..],
445+
Some(j) => {
446+
if i == 0 && j != 0 {
447+
return false
448+
}
449+
actual = &actual[j + part.len()..];
450+
}
446451
None => {
447452
return false
448453
}
@@ -451,6 +456,19 @@ fn lines_match(expected: &str, mut actual: &str) -> bool {
451456
actual.is_empty() || expected.ends_with("[..]")
452457
}
453458

459+
#[test]
460+
fn lines_match_works() {
461+
assert!(lines_match("a b", "a b"));
462+
assert!(lines_match("a[..]b", "a b"));
463+
assert!(lines_match("a[..]", "a b"));
464+
assert!(lines_match("[..]", "a b"));
465+
assert!(lines_match("[..]b", "a b"));
466+
467+
assert!(!lines_match("[..]b", "c"));
468+
assert!(!lines_match("b", "c"));
469+
assert!(!lines_match("b", "cb"));
470+
}
471+
454472
// Compares JSON object for approximate equality.
455473
// You can use `[..]` wildcard in strings (useful for OS dependent things such as paths).
456474
// Arrays are sorted before comparison.

tests/test_cargo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ test!(find_closest_biuld_to_build {
6363
execs().with_status(101)
6464
.with_stderr("no such subcommand
6565
66-
Did you mean `build`?
66+
<tab>Did you mean `build`?
6767
6868
"));
6969
});

tests/test_cargo_compile_git_deps.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,8 @@ test!(update_one_dep_in_repo_with_many_deps {
14011401
.arg("-p").arg("foo"),
14021402
execs().with_status(0)
14031403
.with_stdout(&format!("\
1404-
Updating git repository `{}`
1405-
", foo.url())));
1404+
{updating} git repository `{}`
1405+
", foo.url(), updating = UPDATING)));
14061406
});
14071407

14081408
test!(switch_deps_does_not_update_transitive {
@@ -1455,12 +1455,12 @@ test!(switch_deps_does_not_update_transitive {
14551455
assert_that(p.cargo("build"),
14561456
execs().with_status(0)
14571457
.with_stdout(&format!("\
1458-
Updating git repository `{}`
1459-
Updating git repository `{}`
1458+
{updating} git repository `{}`
1459+
{updating} git repository `{}`
14601460
{compiling} transitive [..]
14611461
{compiling} dep [..]
14621462
{compiling} project [..]
1463-
", dep1.url(), transitive.url(), compiling = COMPILING)));
1463+
", dep1.url(), transitive.url(), compiling = COMPILING, updating = UPDATING)));
14641464

14651465
// Update the dependency to point to the second repository, but this
14661466
// shouldn't update the transitive dependency which is the same.
@@ -1476,10 +1476,10 @@ Updating git repository `{}`
14761476
assert_that(p.cargo("build"),
14771477
execs().with_status(0)
14781478
.with_stdout(&format!("\
1479-
Updating git repository `{}`
1479+
{updating} git repository `{}`
14801480
{compiling} dep [..]
14811481
{compiling} project [..]
1482-
", dep2.url(), compiling = COMPILING)));
1482+
", dep2.url(), compiling = COMPILING, updating = UPDATING)));
14831483
});
14841484

14851485
test!(update_one_source_updates_all_packages_in_that_git_source {

tests/test_cargo_compile_path_deps.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,15 +741,15 @@ test!(dev_deps_no_rebuild_lib {
741741
assert_that(p.cargo("test"),
742742
execs().with_status(0)
743743
.with_stdout(&format!("\
744-
{} [..] v0.5.0 ({})
745-
{} [..] v0.5.0 ({})
746-
Running target[..]foo-[..]
744+
{compiling} [..] v0.5.0 ({url})
745+
{compiling} [..] v0.5.0 ({url})
746+
{running} target[..]foo-[..]
747747
748748
running 0 tests
749749
750750
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
751751
752-
", COMPILING, p.url(), COMPILING, p.url())));
752+
", url = p.url(), compiling = COMPILING, running = RUNNING)));
753753
});
754754

755755
test!(custom_target_no_rebuild {

tests/test_cargo_install.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ test!(subcommand_works_out_of_the_box {
527527
assert_that(cargo_process("foo"),
528528
execs().with_status(0).with_stdout("bar\n"));
529529
assert_that(cargo_process("--list"),
530-
execs().with_status(0).with_stdout_contains(" foo\n"));
530+
execs().with_status(0).with_stdout_contains(" foo\n"));
531531
});
532532

533533
test!(installs_from_cwd_by_default {
@@ -558,9 +558,9 @@ test!(do_not_rebuilds_on_local_install {
558558
assert_that(p.cargo_process("build").arg("--release"),
559559
execs().with_status(0));
560560
assert_that(cargo_process("install").arg("--path").arg(p.root()),
561-
execs().with_status(0).with_stdout("\
562-
Installing [..]
563-
").with_stderr("\
561+
execs().with_status(0).with_stdout(&format!("\
562+
{installing} [..]
563+
", installing = INSTALLING)).with_stderr("\
564564
be sure to add `[..]` to your PATH to be able to run the installed binaries
565565
"));
566566

@@ -580,7 +580,7 @@ test!(reports_unsuccessful_subcommand_result {
580580
assert_that(cargo_process("install").arg("cargo-fail"),
581581
execs().with_status(0));
582582
assert_that(cargo_process("--list"),
583-
execs().with_status(0).with_stdout_contains(" fail\n"));
583+
execs().with_status(0).with_stdout_contains(" fail\n"));
584584
assert_that(cargo_process("fail"),
585585
execs().with_status(101).with_stderr_contains("\
586586
thread '<main>' panicked at 'explicit panic', [..]

0 commit comments

Comments
 (0)