fix: harden demo lifecycle and scanner
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd -P)
|
||||
TEST_ROOT=$(mktemp -d /tmp/uups-bank-scan-test.XXXXXX)
|
||||
fixture_name='ANVIL_''TEST_PHRASE'
|
||||
fixture_value='test test test test test test test test test test test junk'
|
||||
|
||||
cleanup() {
|
||||
rm -f -- "$TEST_ROOT/script/lib/DemoScript.sol" "$TEST_ROOT/tools/scan-project.sh" "$TEST_ROOT/duplicate.sh" \
|
||||
"$TEST_ROOT/.git/index" "$TEST_ROOT/.git/HEAD" "$TEST_ROOT/.git/config" "$TEST_ROOT/.git/description" "$TEST_ROOT/.git/info/exclude"
|
||||
rmdir -- "$TEST_ROOT/.git/objects/pack" "$TEST_ROOT/.git/objects/info" "$TEST_ROOT/.git/objects" \
|
||||
"$TEST_ROOT/.git/refs/tags" "$TEST_ROOT/.git/refs/heads" "$TEST_ROOT/.git/refs" \
|
||||
"$TEST_ROOT/.git/branches" "$TEST_ROOT/.git/hooks" "$TEST_ROOT/.git/info" "$TEST_ROOT/.git" \
|
||||
"$TEST_ROOT/script/lib" "$TEST_ROOT/script" "$TEST_ROOT/tools" "$TEST_ROOT" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT
|
||||
fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; }
|
||||
|
||||
mkdir -p "$TEST_ROOT/script/lib" "$TEST_ROOT/tools"
|
||||
cp "$ROOT/tools/scan-project.sh" "$TEST_ROOT/tools/scan-project.sh"
|
||||
git -C "$TEST_ROOT" init -q --template=
|
||||
printf ' string internal constant %s = "%s";\n' "$fixture_name" "$fixture_value" >"$TEST_ROOT/script/lib/DemoScript.sol"
|
||||
git -C "$TEST_ROOT" add script/lib/DemoScript.sol tools/scan-project.sh
|
||||
(cd "$TEST_ROOT" && bash tools/scan-project.sh >/dev/null) || fail 'exact intended fixture assignment was rejected'
|
||||
|
||||
# Catches accepting the known phrase assignment in a duplicate tracked path.
|
||||
printf '%s="%s"\n' "$fixture_name" "$fixture_value" >"$TEST_ROOT/duplicate.sh"
|
||||
git -C "$TEST_ROOT" add duplicate.sh
|
||||
if (cd "$TEST_ROOT" && bash tools/scan-project.sh >/dev/null 2>&1); then fail 'duplicate fixture assignment was accepted'; fi
|
||||
git -C "$TEST_ROOT" rm -q --cached duplicate.sh
|
||||
rm -f -- "$TEST_ROOT/duplicate.sh"
|
||||
|
||||
# Catches substring matching that accepts appended content on the intended line.
|
||||
printf ' string internal constant %s = "%s"; appended\n' "$fixture_name" "$fixture_value" >"$TEST_ROOT/script/lib/DemoScript.sol"
|
||||
if (cd "$TEST_ROOT" && bash tools/scan-project.sh >/dev/null 2>&1); then fail 'appended fixture assignment was accepted'; fi
|
||||
|
||||
printf '%s\n' 'PASS: scanner fixture exception is exact, unique, and path-anchored'
|
||||
Reference in New Issue
Block a user