Something went wrong. Try again.
Backend environment for match hosting for lance.blue
Something went wrong. Try again.
Shell
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141#!/usr/bin/env bash# The test suite.## Runs inside the Docker `test` stage, which is what ./test.sh builds. Do not# expect it to work on a laptop directly - it wants the JDK, the extracted# MegaMek release and the patched jar the build stage produced:## MM_HOME extracted MegaMek release# PATCHED_JAR the jar megamek/apply-patches.sh produced# JAVA_HOME a JDK## ./scripts/test.sh from the repo root, the supported way# ./tests/run.sh lint one group, if you are already inside the stage## Groups, fastest first, so a break surfaces early:## lint shellcheck every shell script# syntax bash -n; the JSON and XML templates parse# unit the container's shell logic, against fixtures# compile javac against the stock MegaMek jar; patch verificationset -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"cd "$ROOT"
PASS=0FAIL=0SKIP=0
ok() { printf ' \033[32mok\033[0m %s\n' "$1"; PASS=$((PASS + 1)); }bad() { printf ' \033[31mFAIL\033[0m %s\n' "$1"; FAIL=$((FAIL + 1)); }skip() { printf ' \033[33mskip\033[0m %s (%s)\n' "$1" "$2"; SKIP=$((SKIP + 1)); }group() { printf '\n\033[1m%s\033[0m\n' "$1"; }
# check <name> <command...>check() { local name="$1"; shift if out="$("$@" 2>&1)"; then ok "$name" else bad "$name" printf '%s\n' "$out" | sed 's/^/ /' fi}
WANT="${1:-all}"want() { [ "$WANT" = "all" ] || [ "$WANT" = "$1" ]; }
# The build context has no .git, so file discovery is a plain find.mapfile -t SH < <(find . -name '*.sh' -not -path './.git/*' | sort)
# --- lint --------------------------------------------------------------------if want lint; then group "lint" if command -v shellcheck >/dev/null; then check "shellcheck" ./tests/shell/lint.sh else skip "shellcheck" "not installed" fifi
# --- syntax ------------------------------------------------------------------if want syntax; then group "syntax" for f in "${SH[@]}"; do check "bash -n $f" bash -n "$f" done
# The suramadu template is JSON with @PLACEHOLDER@ markers inside string # values, so it must parse as JSON even before substitution. check "suramadu.config.template parses" jq -e . suramadu/suramadu.config.template check "clientsettings.xml.template parses" \ python3 -c "import xml.etree.ElementTree as E; E.parse('megamek/clientsettings.xml.template')" # Not an XML parse - index.html is HTML5, with void elements that no XML # parser accepts. What matters is that our stylesheet is loaded after # upstream's, because the overrides win on order, not specificity. check "theme.css is linked after the war's style.css" bash -c ' s=$(grep -n "css/style.css" suramadu/web/index.html | cut -d: -f1) o=$(grep -n "\"theme.css\"" suramadu/web/index.html | cut -d: -f1) [ -n "$s" ] && [ -n "$o" ] && [ "$o" -gt "$s" ]' check "the FOUC guard is inline, before any stylesheet" bash -c ' i=$(grep -n "<style>" suramadu/web/index.html | cut -d: -f1) s=$(grep -n "css/style.css" suramadu/web/index.html | cut -d: -f1) [ -n "$i" ] && [ "$i" -lt "$s" ]' check "log4j2-quiet.xml parses" \ python3 -c "import xml.etree.ElementTree as E; E.parse('megamek/log4j2-quiet.xml')"fi
# --- unit --------------------------------------------------------------------if want unit; then group "unit" for t in tests/shell/test-*.sh; do [ -f "$t" ] || continue check "$(basename "$t" .sh)" bash "$t" donefi
# --- compile -----------------------------------------------------------------if want compile; then group "compile" if [ -n "${MM_HOME:-}" ] && [ -f "${MM_HOME}/MegaMek.jar" ]; then # Byte-compares the assembled tree against the repo files, so "the image # never got the skin/icons" is a test failure, not a screenshot debate. check "lance.blue skin and icons installed in the megamek tree" bash -c ' cmp -s "$MM_HOME/mmconf/skins/lanceBlueSkin.xml" megamek/skin/lanceBlueSkin.xml && cmp -s "$MM_HOME/data/images/widgets/lance/battlespace-hex.png" megamek/skin/battlespace-hex.png && cmp -s "$MM_HOME/data/images/widgets/lance/scrollpane.png" megamek/skin/scrollpane.png && for s in 16 32 48 256; do cmp -s "$MM_HOME/data/images/misc/megamek-icon-${s}x${s}.png" \ "megamek/skin/icons/megamek-icon-${s}x${s}.png" || exit 1 done' check "arena.jar compiles against stock MegaMek" \ env OUT_JAR=/tmp/arena-test.jar ./src/build-jar.sh check "benchmark harness compiles" ./tests/build.sh # After the jar, because it loads every scenario with it. One JVM for the # whole library: warming the unit cache costs far more than loading a # scenario does. check "every scenario in the image loads, or is known not to" \ env ARENA_JAR=/tmp/arena-test.jar ./tests/scenario-load.sh # Same jar, one scenario, damage applied by hand: the per-unit half of the # result document is read back for the damage that was put in. check "a damaged machine reports its damage" \ env ARENA_JAR=/tmp/arena-test.jar ./tests/unit-report.sh # Same jar again: a seat that left the game before the report was written # is still in the report. check "a seat that left is still reported" \ env ARENA_JAR=/tmp/arena-test.jar ./tests/roster.sh if [ -n "${PATCHED_JAR:-}" ] && [ -f "$PATCHED_JAR" ]; then check "patched jar differs from stock in exactly the patched classes" \ ./megamek/verify-patches.sh else skip "patch verification" "PATCHED_JAR not set" fi else skip "compile" "MM_HOME not set - run ./test.sh instead" fifi
printf '\n%d passed, %d failed, %d skipped\n' "$PASS" "$FAIL" "$SKIP"[ "$FAIL" -eq 0 ]