summaryrefslogtreecommitdiffstats
path: root/src/tools/linkchecker/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/linkchecker/tests')
-rw-r--r--src/tools/linkchecker/tests/basic_broken/foo.html5
-rw-r--r--src/tools/linkchecker/tests/broken_fragment_local/foo.html5
-rw-r--r--src/tools/linkchecker/tests/broken_fragment_remote/bar.html4
-rw-r--r--src/tools/linkchecker/tests/broken_fragment_remote/inner/foo.html5
-rw-r--r--src/tools/linkchecker/tests/broken_redir/foo.html5
-rw-r--r--src/tools/linkchecker/tests/broken_redir/redir-bad.html11
-rw-r--r--src/tools/linkchecker/tests/checks.rs113
-rw-r--r--src/tools/linkchecker/tests/directory_link/foo.html5
-rw-r--r--src/tools/linkchecker/tests/directory_link/somedir/index.html4
-rw-r--r--src/tools/linkchecker/tests/redirect_loop/foo.html5
-rw-r--r--src/tools/linkchecker/tests/redirect_loop/redir-bad.html11
-rw-r--r--src/tools/linkchecker/tests/valid/inner/bar.html7
-rw-r--r--src/tools/linkchecker/tests/valid/inner/foo.html14
-rw-r--r--src/tools/linkchecker/tests/valid/inner/redir-bad.html12
-rw-r--r--src/tools/linkchecker/tests/valid/inner/redir-target.html5
-rw-r--r--src/tools/linkchecker/tests/valid/inner/redir.html11
-rw-r--r--src/tools/linkchecker/tests/valid/outer.html5
17 files changed, 227 insertions, 0 deletions
diff --git a/src/tools/linkchecker/tests/basic_broken/foo.html b/src/tools/linkchecker/tests/basic_broken/foo.html
new file mode 100644
index 000000000..cb27c55c9
--- /dev/null
+++ b/src/tools/linkchecker/tests/basic_broken/foo.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a href="bar.html">test</a>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/broken_fragment_local/foo.html b/src/tools/linkchecker/tests/broken_fragment_local/foo.html
new file mode 100644
index 000000000..66c457ad0
--- /dev/null
+++ b/src/tools/linkchecker/tests/broken_fragment_local/foo.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a href="#somefrag">test</a>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/broken_fragment_remote/bar.html b/src/tools/linkchecker/tests/broken_fragment_remote/bar.html
new file mode 100644
index 000000000..7879e1ce9
--- /dev/null
+++ b/src/tools/linkchecker/tests/broken_fragment_remote/bar.html
@@ -0,0 +1,4 @@
+<html>
+<body>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/broken_fragment_remote/inner/foo.html b/src/tools/linkchecker/tests/broken_fragment_remote/inner/foo.html
new file mode 100644
index 000000000..7683060b3
--- /dev/null
+++ b/src/tools/linkchecker/tests/broken_fragment_remote/inner/foo.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a href="../bar.html#somefrag">test</a>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/broken_redir/foo.html b/src/tools/linkchecker/tests/broken_redir/foo.html
new file mode 100644
index 000000000..bd3e3ad33
--- /dev/null
+++ b/src/tools/linkchecker/tests/broken_redir/foo.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+ <a href="redir-bad.html">bad redir</a>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/broken_redir/redir-bad.html b/src/tools/linkchecker/tests/broken_redir/redir-bad.html
new file mode 100644
index 000000000..9c580d8e0
--- /dev/null
+++ b/src/tools/linkchecker/tests/broken_redir/redir-bad.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta http-equiv="refresh" content="0;URL=sometarget">
+ <title>Redirection</title>
+</head>
+<body>
+ <p>Redirecting to <a href="sometarget">sometarget</a>...</p>
+ <script>location.replace("sometarget" + location.search + location.hash);</script>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/checks.rs b/src/tools/linkchecker/tests/checks.rs
new file mode 100644
index 000000000..1a0b1b00e
--- /dev/null
+++ b/src/tools/linkchecker/tests/checks.rs
@@ -0,0 +1,113 @@
+use std::path::Path;
+use std::process::{Command, ExitStatus};
+
+fn run(dirname: &str) -> (ExitStatus, String, String) {
+ let output = Command::new(env!("CARGO_BIN_EXE_linkchecker"))
+ .current_dir(Path::new(env!("CARGO_MANIFEST_DIR")).join("tests"))
+ .arg(dirname)
+ .output()
+ .unwrap();
+ let stdout = String::from_utf8(output.stdout).unwrap();
+ let stderr = String::from_utf8(output.stderr).unwrap();
+ (output.status, stdout, stderr)
+}
+
+fn broken_test(dirname: &str, expected: &str) {
+ let (status, stdout, stderr) = run(dirname);
+ assert!(!status.success());
+ if !contains(expected, &stdout) {
+ panic!(
+ "stdout did not contain expected text: {}\n\
+ --- stdout:\n\
+ {}\n\
+ --- stderr:\n\
+ {}\n",
+ expected, stdout, stderr
+ );
+ }
+}
+
+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() {
+ panic!(
+ "test did not succeed as expected\n\
+ --- stdout:\n\
+ {}\n\
+ --- stderr:\n\
+ {}\n",
+ stdout, stderr
+ );
+ }
+}
+
+#[test]
+fn valid() {
+ valid_test("valid/inner");
+}
+
+#[test]
+fn basic_broken() {
+ broken_test("basic_broken", "foo.html:3: broken link - `bar.html`");
+}
+
+#[test]
+fn broken_fragment_local() {
+ 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",
+ "foo.html:3: broken link fragment `#somefrag` pointing to \
+ `[..]/broken_fragment_remote/bar.html`",
+ );
+}
+
+#[test]
+fn broken_redir() {
+ broken_test(
+ "broken_redir",
+ "foo.html:3: broken redirect from `redir-bad.html` to `sometarget`",
+ );
+}
+
+#[test]
+fn directory_link() {
+ 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",
+ "foo.html:3: redirect from `redir-bad.html` to `[..]redirect_loop/redir-bad.html` \
+ which is also a redirect (not supported)",
+ );
+}
diff --git a/src/tools/linkchecker/tests/directory_link/foo.html b/src/tools/linkchecker/tests/directory_link/foo.html
new file mode 100644
index 000000000..40a8461b8
--- /dev/null
+++ b/src/tools/linkchecker/tests/directory_link/foo.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+ <a href="somedir">dir link</a>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/directory_link/somedir/index.html b/src/tools/linkchecker/tests/directory_link/somedir/index.html
new file mode 100644
index 000000000..7879e1ce9
--- /dev/null
+++ b/src/tools/linkchecker/tests/directory_link/somedir/index.html
@@ -0,0 +1,4 @@
+<html>
+<body>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/redirect_loop/foo.html b/src/tools/linkchecker/tests/redirect_loop/foo.html
new file mode 100644
index 000000000..bee58b212
--- /dev/null
+++ b/src/tools/linkchecker/tests/redirect_loop/foo.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+ <a href="redir-bad.html">loop link</a>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/redirect_loop/redir-bad.html b/src/tools/linkchecker/tests/redirect_loop/redir-bad.html
new file mode 100644
index 000000000..bc567caa7
--- /dev/null
+++ b/src/tools/linkchecker/tests/redirect_loop/redir-bad.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta http-equiv="refresh" content="0;URL=redir-bad.html">
+ <title>Redirection</title>
+</head>
+<body>
+ <p>Redirecting to <a href="redir-bad.html">redir-bad.html</a>...</p>
+ <script>location.replace("redir-bad.html" + location.search + location.hash);</script>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/valid/inner/bar.html b/src/tools/linkchecker/tests/valid/inner/bar.html
new file mode 100644
index 000000000..4b500d78b
--- /dev/null
+++ b/src/tools/linkchecker/tests/valid/inner/bar.html
@@ -0,0 +1,7 @@
+<html>
+<body>
+
+ <h2 id="barfrag">Bar</h2>
+
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/valid/inner/foo.html b/src/tools/linkchecker/tests/valid/inner/foo.html
new file mode 100644
index 000000000..3c6a7483b
--- /dev/null
+++ b/src/tools/linkchecker/tests/valid/inner/foo.html
@@ -0,0 +1,14 @@
+<html>
+<body>
+ <a href="#localfrag">test local frag</a>
+ <a href="../outer.html">remote link</a>
+ <a href="../outer.html#somefrag">remote link with fragment</a>
+ <a href="bar.html">this book</a>
+ <a href="bar.html#barfrag">this book with fragment</a>
+ <a href="https://example.com/doesnotexist">external links not validated</a>
+ <a href="redir.html#redirfrag">Redirect</a>
+
+ <h2 id="localfrag">Local</h2>
+
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/valid/inner/redir-bad.html b/src/tools/linkchecker/tests/valid/inner/redir-bad.html
new file mode 100644
index 000000000..f32683efe
--- /dev/null
+++ b/src/tools/linkchecker/tests/valid/inner/redir-bad.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta http-equiv="refresh" content="0;URL=xxx">
+ <title>Redirection</title>
+</head>
+<body>
+ <p>Redirecting to <a href="xxx">xxx</a>...</p>
+ <script>location.replace("xxx" + location.search + location.hash);</script>
+ These files are skipped, but probably shouldn't be.
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/valid/inner/redir-target.html b/src/tools/linkchecker/tests/valid/inner/redir-target.html
new file mode 100644
index 000000000..bd59884a0
--- /dev/null
+++ b/src/tools/linkchecker/tests/valid/inner/redir-target.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+ <h2 id="redirfrag">Redir</h2>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/valid/inner/redir.html b/src/tools/linkchecker/tests/valid/inner/redir.html
new file mode 100644
index 000000000..3a52a8973
--- /dev/null
+++ b/src/tools/linkchecker/tests/valid/inner/redir.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta http-equiv="refresh" content="0;URL=redir-target.html">
+ <title>Redirection</title>
+</head>
+<body>
+ <p>Redirecting to <a href="redir-target.html">redir-target.html</a>...</p>
+ <script>location.replace("redir-target.html" + location.search + location.hash);</script>
+</body>
+</html>
diff --git a/src/tools/linkchecker/tests/valid/outer.html b/src/tools/linkchecker/tests/valid/outer.html
new file mode 100644
index 000000000..35f799f20
--- /dev/null
+++ b/src/tools/linkchecker/tests/valid/outer.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<a id="somefrag"></a>
+</body>
+</html>