Change the linkchecker self-tests to validate more output.
This commit is contained in:
parent
bbd0532163
commit
dbc8a1c25a
1 changed files with 42 additions and 7 deletions
|
|
@ -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)",
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue