#!/usr/bin/env bash # Tests inline_scripts (scripts/lib-inline-script.sh) against HTML as the admin page looks. Run: bash scripts/test-inline-script-check.sh set -u here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=lib-inline-script.sh . "$here/lib-inline-script.sh" failures=0 expect() { # description expected(clean|inline) html local found; found="$(printf '%s' "$3" | inline_scripts)" if [ "$2" = "clean" ] && [ -z "$found" ]; then echo "ok $1" elif [ "$2" = "inline" ] && [ -n "$found" ]; then echo "ok $1" else echo "FAIL $1 (expected $2, found: ${found:-nothing})"; failures=$((failures + 1)); fi } expect "the built admin page (module script with crossorigin before src)" clean '
' expect "src in the middle of the tag, single quotes, defer" clean "" expect "a tag over several lines" clean '' expect "an empty script" clean '' expect "a JSON data block" clean '' expect "a JSON-LD block and an import map" clean '' expect "the old inline theme script" inline '' expect "an inline module script" inline '' expect "an inline script after good ones" inline '
' expect "an inline script that starts with a comparison" inline '' expect "text that only mentions the word script" clean '

Use a script tag with a src attribute.

' if [ "$failures" -ne 0 ]; then echo "$failures check(s) failed"; exit 1; fi echo "all checks passed"