Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions scripts/check-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -uo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT" || exit 1
WORK_DIR="$ROOT/.linkcheck-work"
USER_AGENT="hivecommons-link-checker/1.0 (+https://hivecommons.dev)"
EXTERNAL_WARN=0
Expand Down Expand Up @@ -83,6 +84,11 @@ extract_redirect_targets >> "$WORK_DIR/links.tsv"

sort -u "$WORK_DIR/links.tsv" > "$WORK_DIR/links.dedup.tsv"

if [[ ! -s "$WORK_DIR/links.dedup.tsv" ]]; then
echo "ERROR no links found under $ROOT; refusing to pass without checking anything"
exit 1
fi

internal_errors=0
external_errors=0
checked=0
Expand Down
14 changes: 14 additions & 0 deletions scripts/check-links.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ run_checker "$root"
expect_rc 0 "dedup site passes"
expect_out 'Checked 1 unique links\.' "three identical links counted once"

echo "case: result does not depend on the caller's cwd"
root="$(new_site other-cwd)"
echo '<a href="/nope">x</a>' > "$root/index.html"
OUT="$(cd "$TMP" && PATH="$TMP/bin:$PATH" bash "$root/scripts/check-links.sh" 2>&1)"; RC=$?
expect_rc 1 "broken link still fails when run from another directory"
expect_out 'ERROR internal target missing: index\.html -> /nope' "page links are extracted from outside the root"
expect_no_out 'No such file' "no grep path errors"

echo "case: a site with no links to check fails closed"
root="$(new_site empty)"
run_checker "$root"
expect_rc 1 "no pages/links is an error, not a pass"
expect_out 'no links found' "explains why"

echo
echo "check-links self-test: $passes passed, $failures failed"
(( failures == 0 ))
Loading