1{
2 runCommand,
3 testers,
4 emptyDirectory,
5}:
6let
7 sitePkg = runCommand "site" { } ''
8 dist=$out/dist
9 mkdir -p $dist
10 echo "<html><body><a href=\"https://example.com/foo\">foo</a></body></html>" > $dist/index.html
11 echo "<html><body></body></html>" > $dist/foo.html
12 '';
13 check = testers.lycheeLinkCheck {
14 site = sitePkg + "/dist";
15 remap = {
16 # Normally would recommend to append a subpath that hints why it's forbidden; see example in docs.
17 # However, we also want to test that a package is converted to a string *before*
18 # it's tested whether it's a store path. Mistake made during development caused:
19 # cannot check URI: InvalidUrlRemap("The remapping pattern must produce a valid URL, but it is not: /nix/store/4d0ix...empty-directory/foo
20 "https://example.com" = emptyDirectory;
21 };
22 };
23
24 failure = testers.testBuildFailure check;
25in
26runCommand "link-check-fail" { inherit failure; } ''
27 # The details of the message might change, but we have to make sure the
28 # correct error is reported, so that we know it's not something else that
29 # went wrong.
30 grep 'empty-directory/foo.*Cannot find file' $failure/testBuildFailure.log >/dev/null
31 touch $out
32''