#!/usr/bin/env bats # Seam: script syntax. # Every shell script in scripts/ must pass `bash -n`. When shellcheck is # available it must pass with no errors (warnings tolerated in this repo). load helpers @test "all scripts pass bash -n" { local any=0 while IFS= read -r s; do any=1 bash -n "$s" || { echo "syntax error in $s"; return 1; } done < <(find "$REPO_ROOT/scripts" -name '*.sh' -type f 2>/dev/null | sort) [ "$any" -eq 1 ] || skip "no scripts yet" } @test "scripts are executable" { while IFS= read -r s; do [ -x "$s" ] || { echo "$s is not executable"; return 1; } done < <(find "$REPO_ROOT/scripts" -name '*.sh' -type f 2>/dev/null | sort) } @test "shellcheck passes when available" { if command -v shellcheck >/dev/null 2>&1; then while IFS= read -r s; do shellcheck -S error "$s" || { echo "shellcheck errors in $s"; return 1; } done < <(find "$REPO_ROOT/scripts" -name '*.sh' -type f 2>/dev/null | sort) else skip "shellcheck not installed locally" fi } @test "every python script in scripts/ compiles" { # The shell half of this seam covered scripts/*.sh; the python half was only # covered where a test happened to reference a specific file, so a syntax # error in a committed harness could ship unnoticed until someone ran it # during an incident. local any=0 while IFS= read -r p; do any=1 python3 -m py_compile "$p" || { echo "syntax error in $p"; return 1; } done < <(find "$REPO_ROOT/scripts" -name '*.py' -type f 2>/dev/null | sort) [ "$any" -eq 1 ] || skip "no python scripts yet" }