Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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.
22 changes: 22 additions & 0 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading