diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..9081e0e --- /dev/null +++ b/tests/README.md @@ -0,0 +1,28 @@ +# pbr tests + +| Script | Purpose | Runs where | +| --- | --- | --- | +| `tests/run_tests.sh` | Functional suite: runs `files/lib/pbr` against the mocks in `tests/lib` and `tests/mocks`, then syntax-checks the shell scripts | Development machine and CI, on current ucode | +| `tests/check-ucode-syntax.sh` | Compiles every `.uc` file to catch syntax too new for the oldest supported ucode. Uses no mocks | CI through `ucode-syntax.yml`, or from `run_tests.sh` when given an interpreter | +| `test-version.sh` | Checks that the installed package reports the expected version | OpenWrt package CI, on the installed package | + +## Functional tests + +```sh +bash tests/run_tests.sh # everything +bash tests/run_tests.sh tests/02_config/01_x # selected tests +``` + +The script must run from the top of the source tree. It exits with the number of failures. + +## Syntax compatibility + +`check-ucode-syntax.sh` must run on the ucode of the oldest supported OpenWrt release, because compiling on a newer one proves nothing about those routers. On a newer interpreter it refuses to run and exits 2. `UCODE_REF` in `.github/workflows/ucode-syntax.yml` names that version, and moves only when the oldest supported release moves. + +To include it in a local run, point `PBR_UCODE_OLDEST` at an interpreter built from that commit: + +```sh +PBR_UCODE_OLDEST=/path/to/ucode bash tests/run_tests.sh +``` + +Without it, `run_tests.sh` reports the check as skipped. The functional suite itself deliberately follows ucode master in CI, as early warning of upstream changes. diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 23408c8..902bb05 100644 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -328,5 +328,27 @@ for shellscript in \ fi done +# ── ucode syntax compatibility ──────────────────────────── +# +# check-ucode-syntax.sh only means something on the oldest ucode pbr supports, and +# refuses a newer one, while this suite runs on any ucode. So it takes its own +# interpreter, and is skipped when none is given. + +printf "\n##\n## Checking syntax against the oldest supported ucode\n##\n\n" +name="check-ucode-syntax.sh" +printf "%s %s " "$name" "${line:${#name}}" +if [ -z "$PBR_UCODE_OLDEST" ]; then + printf "SKIP (PBR_UCODE_OLDEST not set)\n" +else + n_tests=$((n_tests + 1)) + if tests/check-ucode-syntax.sh "$PBR_UCODE_OLDEST" >/dev/null 2>&1; then + printf "OK\n" + else + printf "FAILED\n" + tests/check-ucode-syntax.sh "$PBR_UCODE_OLDEST" # run again to show output + n_fails=$((n_fails + 1)) + fi +fi + printf "\nRan %d tests, %d okay, %d failures\n" $n_tests $((n_tests - n_fails)) $n_fails exit $n_fails