Files
lean4/tests/pkg/user_plugin/run_test.sh
Garmelon 49715fe63c chore: improve how test suite interacts with stages (#12913)
The tests need to run with certain environment variables set that only
cmake really knows and that differ between stages. Cmake could just set
the variables directly when running the tests and benchmarks, but that
would leave no good way to manually run a single benchmark. So cmake
generates some stage-specific scripts instead that set the required
environment variables.

Previously, those scripts were sourced directly by the individual
`run_*` scripts, so the env scripts of different stages would overwrite
each other. This PR changes the setup so they can instead be generated
next to each other. This also simplifies the `run_*` scripts themselves
a bit, and makes `tests/bench/build` less of a hack.
2026-03-16 15:20:03 +00:00

58 lines
1.5 KiB
Bash

set -euo pipefail
# Deermine shared library extension
if [ "${OS:-}" = Windows_NT ]; then
LIB_PREFIX=
SHLIB_EXT=dll
elif [ "`uname`" = Darwin ]; then
LIB_PREFIX=lib
SHLIB_EXT=dylib
else
LIB_PREFIX=lib
SHLIB_EXT=so
fi
# Reset test
./clean.sh
lake update -q
# Build plugins
lake build
PKG=user__plugin # mangled
LIB_DIR=.lake/build/lib
check_plugin () {
plugin=$1
shlib=$LIB_DIR/${LIB_PREFIX}${PKG}_$plugin.$SHLIB_EXT
test -f $shlib || {
echo "$plugin library not found; $LIB_DIR contains:"
ls $LIB_DIR
exit 1
}
}
check_plugin UserPlugin
check_plugin UserEnvPlugin
PLUGIN=$LIB_DIR/${LIB_PREFIX}${PKG}_UserPlugin.$SHLIB_EXT
ENV_PLUGIN=$LIB_DIR/${LIB_PREFIX}${PKG}_UserEnvPlugin.$SHLIB_EXT
# Expected test output
EXPECTED_OUT="Ran builtin initializer"
ENV_EXPECTED_OUT="Builtin value"
# Test plugins at elaboration-time via `lean` CLI
echo "Testing plugin load with lean CLI ..."
echo | lean --plugin=$PLUGIN --stdin 2>&1 | diff <(echo "$EXPECTED_OUT") -
lake env lean --plugin=$ENV_PLUGIN testEnvUse.lean 2>&1 | diff <(echo "$ENV_EXPECTED_OUT") -
# Test plugins at runtime via `Lean.loadPlugin`
echo "Testing plugin load with Lean.loadPlugin ..."
lean --run test.lean $PLUGIN 2>&1 | diff <(echo "$EXPECTED_OUT") -
lake env lean --run testEnv.lean $ENV_PLUGIN 2>&1 | diff <(echo "$ENV_EXPECTED_OUT") -
# Test failure to load environment plugin without `withImporting`
lean --run test.lean $ENV_PLUGIN >/dev/null 2>&1 && {
fail "Loading environment plugin without importing succeeded unexpectedly."
} || true
# Print success
echo "Tests completed successfully."