diff options
| author | Eric Huss <eric@huss.org> | 2021-06-08 16:23:19 -0700 |
|---|---|---|
| committer | Eric Huss <eric@huss.org> | 2021-06-09 08:02:14 -0700 |
| commit | dbc8a1c25a79fa5ce1f1343b0d9c2ede161eb467 (patch) | |
| tree | f3b55e01a2a775ceaff1d6373b34af4f04fcda9e /src | |
| parent | bbd053216341cd3843b8f12da791f533e4480b8d (diff) | |
| download | rust-dbc8a1c25a79fa5ce1f1343b0d9c2ede161eb467.tar.gz rust-dbc8a1c25a79fa5ce1f1343b0d9c2ede161eb467.zip | |
Change the linkchecker self-tests to validate more output.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/linkchecker/tests/checks.rs | 49 |
1 files changed, 42 insertions, 7 deletions
diff --git a/src/tools/linkchecker/tests/checks.rs b/src/tools/linkchecker/tests/checks.rs index c6ec999e5cf..531c323a9bc 100644 --- a/src/tools/linkchecker/tests/checks.rs +++ b/src/tools/linkchecker/tests/checks.rs @@ -15,7 +15,7 @@ fn run(dirname: &str) -> (ExitStatus, String, String) { fn broken_test(dirname: &str, expected: &str) { let (status, stdout, stderr) = run(dirname); assert!(!status.success()); - if !stdout.contains(expected) { + if !contains(expected, &stdout) { panic!( "stdout did not contain expected text: {}\n\ --- stdout:\n\ @@ -27,6 +27,25 @@ fn broken_test(dirname: &str, expected: &str) { } } +fn contains(expected: &str, actual: &str) -> bool { + // Normalize for Windows paths. + let actual = actual.replace('\\', "/"); + actual.lines().any(|mut line| { + for (i, part) in expected.split("[..]").enumerate() { + match line.find(part) { + Some(j) => { + if i == 0 && j != 0 { + return false; + } + line = &line[j + part.len()..]; + } + None => return false, + } + } + line.is_empty() || expected.ends_with("[..]") + }) +} + fn valid_test(dirname: &str) { let (status, stdout, stderr) = run(dirname); if !status.success() { @@ -48,30 +67,46 @@ fn valid() { #[test] fn basic_broken() { - broken_test("basic_broken", "bar.html"); + broken_test("basic_broken", "foo.html:3: broken link - `bar.html`"); } #[test] fn broken_fragment_local() { - broken_test("broken_fragment_local", "#somefrag"); + broken_test( + "broken_fragment_local", + "foo.html:3: broken link fragment `#somefrag` pointing to `foo.html`", + ); } #[test] fn broken_fragment_remote() { - broken_test("broken_fragment_remote/inner", "#somefrag"); + broken_test( + "broken_fragment_remote/inner", + "foo.html:3: broken link fragment `#somefrag` pointing to `foo.html`", + ); } #[test] fn broken_redir() { - broken_test("broken_redir", "sometarget"); + broken_test( + "broken_redir", + "foo.html:3: broken redirect from `redir-bad.html` to `sometarget`", + ); } #[test] fn directory_link() { - broken_test("directory_link", "somedir"); + broken_test( + "directory_link", + "foo.html:3: directory link to `somedir` (directory links should use index.html instead)", + ); } #[test] fn redirect_loop() { - broken_test("redirect_loop", "redir-bad.html"); + broken_test( + "redirect_loop", + "foo.html:3: redirect from `redir-bad.html` to `[..]redirect_loop/redir-bad.html` \ + which is also a redirect (not supported)", + ); } |
