Skip to content

Commit dbc8a1c

Browse files
committed
Change the linkchecker self-tests to validate more output.
1 parent bbd0532 commit dbc8a1c

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/tools/linkchecker/tests/checks.rs

+42-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn run(dirname: &str) -> (ExitStatus, String, String) {
1515
fn broken_test(dirname: &str, expected: &str) {
1616
let (status, stdout, stderr) = run(dirname);
1717
assert!(!status.success());
18-
if !stdout.contains(expected) {
18+
if !contains(expected, &stdout) {
1919
panic!(
2020
"stdout did not contain expected text: {}\n\
2121
--- stdout:\n\
@@ -27,6 +27,25 @@ fn broken_test(dirname: &str, expected: &str) {
2727
}
2828
}
2929

30+
fn contains(expected: &str, actual: &str) -> bool {
31+
// Normalize for Windows paths.
32+
let actual = actual.replace('\\', "/");
33+
actual.lines().any(|mut line| {
34+
for (i, part) in expected.split("[..]").enumerate() {
35+
match line.find(part) {
36+
Some(j) => {
37+
if i == 0 && j != 0 {
38+
return false;
39+
}
40+
line = &line[j + part.len()..];
41+
}
42+
None => return false,
43+
}
44+
}
45+
line.is_empty() || expected.ends_with("[..]")
46+
})
47+
}
48+
3049
fn valid_test(dirname: &str) {
3150
let (status, stdout, stderr) = run(dirname);
3251
if !status.success() {
@@ -48,30 +67,46 @@ fn valid() {
4867

4968
#[test]
5069
fn basic_broken() {
51-
broken_test("basic_broken", "bar.html");
70+
broken_test("basic_broken", "foo.html:3: broken link - `bar.html`");
5271
}
5372

5473
#[test]
5574
fn broken_fragment_local() {
56-
broken_test("broken_fragment_local", "#somefrag");
75+
broken_test(
76+
"broken_fragment_local",
77+
"foo.html:3: broken link fragment `#somefrag` pointing to `foo.html`",
78+
);
5779
}
5880

5981
#[test]
6082
fn broken_fragment_remote() {
61-
broken_test("broken_fragment_remote/inner", "#somefrag");
83+
broken_test(
84+
"broken_fragment_remote/inner",
85+
"foo.html:3: broken link fragment `#somefrag` pointing to `foo.html`",
86+
);
6287
}
6388

6489
#[test]
6590
fn broken_redir() {
66-
broken_test("broken_redir", "sometarget");
91+
broken_test(
92+
"broken_redir",
93+
"foo.html:3: broken redirect from `redir-bad.html` to `sometarget`",
94+
);
6795
}
6896

6997
#[test]
7098
fn directory_link() {
71-
broken_test("directory_link", "somedir");
99+
broken_test(
100+
"directory_link",
101+
"foo.html:3: directory link to `somedir` (directory links should use index.html instead)",
102+
);
72103
}
73104

74105
#[test]
75106
fn redirect_loop() {
76-
broken_test("redirect_loop", "redir-bad.html");
107+
broken_test(
108+
"redirect_loop",
109+
"foo.html:3: redirect from `redir-bad.html` to `[..]redirect_loop/redir-bad.html` \
110+
which is also a redirect (not supported)",
111+
);
77112
}

0 commit comments

Comments
 (0)