Skip to content

Commit c60dff6

Browse files
authored
chore: make test snapshots opt-in (#14188)
There may be some remaining rebuild/consistency issues which I'll have to come back to
1 parent 29db757 commit c60dff6

2 files changed

Lines changed: 25 additions & 17 deletions

File tree

tests/CMakeLists.txt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ string(APPEND TEST_VARS " LEANC_OPTS='${LEANC_OPTS}'")
3939
# LEANC_OPTS in CXX is necessary for macOS c++ to find its headers
4040
string(APPEND TEST_VARS " CXX='${CMAKE_CXX_COMPILER} ${LEANC_OPTS}'")
4141

42-
# Pre-elaborated header snapshots reused by tests with matching imports. The
43-
# `_lean` snapshot is for tests whose only import is `Lean`; the `_init`
44-
# snapshot is for tests with no imports at all (auto-imports `Init`). Built by
45-
# the `build_lean_header_snapshots.sh` fixture below; absent for manual
46-
# `run_test.sh` runs, where `maybe_use_lean_header_snapshot` skips them.
47-
string(APPEND TEST_VARS " LEAN_HEADER_SNAPSHOT_LEAN='${MANGLED_CURRENT_BINARY_DIR}/lean_header_lean.snap'")
48-
string(APPEND TEST_VARS " LEAN_HEADER_SNAPSHOT_INIT='${MANGLED_CURRENT_BINARY_DIR}/lean_header_init.snap'")
42+
# Pre-elaborated header snapshots reused by tests with matching imports, gated
43+
# by the `LEAN_HEADER_SNAPSHOTS` option. The `_lean` snapshot is for tests whose
44+
# only import is `Lean`; the `_init` snapshot is for tests with no imports at
45+
# all (auto-imports `Init`). Built by the `build_lean_header_snapshots.sh`
46+
# fixture below; absent for manual `run_test.sh` runs, where
47+
# `maybe_use_lean_header_snapshot` skips them.
48+
option(LEAN_HEADER_SNAPSHOTS "Pre-elaborate Lean/Init header snapshots to speed up the elab test suites" OFF)
49+
if(LEAN_HEADER_SNAPSHOTS)
50+
string(APPEND TEST_VARS " LEAN_HEADER_SNAPSHOT_LEAN='${MANGLED_CURRENT_BINARY_DIR}/lean_header_lean.snap'")
51+
string(APPEND TEST_VARS " LEAN_HEADER_SNAPSHOT_INIT='${MANGLED_CURRENT_BINARY_DIR}/lean_header_init.snap'")
52+
endif()
4953

5054
set(WITH_TEST_ENV "${CMAKE_CURRENT_SOURCE_DIR}/with_stage${STAGE}_test_env.sh")
5155
set(WITH_BENCH_ENV "${CMAKE_CURRENT_SOURCE_DIR}/with_stage${STAGE}_bench_env.sh")
@@ -257,11 +261,14 @@ endfunction()
257261
# fixture (not in `ALL`) so it runs only after `lean` is built, never blocking
258262
# `make`. The script itself skips the rebuild unless `lean` is newer than the
259263
# snapshots, keeping single-test runs cheap.
260-
add_test(
261-
NAME build_lean_header_snapshots.sh
262-
COMMAND bash "${WITH_TEST_ENV}" "${CMAKE_CURRENT_SOURCE_DIR}/build_lean_header_snapshots.sh"
263-
)
264-
set_tests_properties(build_lean_header_snapshots.sh PROPERTIES FIXTURES_SETUP lean_header_snapshot)
264+
if(LEAN_HEADER_SNAPSHOTS)
265+
add_test(
266+
NAME build_lean_header_snapshots.sh
267+
COMMAND bash "${WITH_TEST_ENV}" "${CMAKE_CURRENT_SOURCE_DIR}/build_lean_header_snapshots.sh"
268+
)
269+
set_tests_properties(build_lean_header_snapshots.sh PROPERTIES FIXTURES_SETUP lean_header_snapshot)
270+
set(ELAB_FIXTURES FIXTURES_REQUIRED lean_header_snapshot)
271+
endif()
265272

266273
# Benchmarks are split into two parts which should be roughly equal in total runtime.
267274
# In radar, each part is run on a different runner.
@@ -314,10 +321,10 @@ add_test_pile(
314321
EXCEPT
315322
async_select_channel.lean # Flaky
316323
sync_mutex.lean # Flaky
317-
FIXTURES_REQUIRED lean_header_snapshot
324+
${ELAB_FIXTURES}
318325
)
319-
add_test_pile(elab_bench *.lean BENCH PART2 FIXTURES_REQUIRED lean_header_snapshot)
320-
add_test_pile(elab_fail *.lean FIXTURES_REQUIRED lean_header_snapshot)
326+
add_test_pile(elab_bench *.lean BENCH PART2 ${ELAB_FIXTURES})
327+
add_test_pile(elab_fail *.lean ${ELAB_FIXTURES})
321328
add_test_pile(misc *.sh)
322329
add_test_pile(misc_bench *.sh BENCH PART2)
323330
add_test_pile(server *.lean)

tests/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,9 @@ These bash variables (set via `<file>.init.sh`) are used by the run script:
250250
When set to `nonzero` instead of a numerical value, the exit code must not be 0.
251251

252252
For performance reasons, elab tests can use prebuilt header snapshots.
253-
Use of the snapshots is controlled by `LEAN_HEADER_SNAPSHOTS`:
254-
set it to `0` to force them off, or to `1` to force them on.
253+
Building the snapshots and wiring them into the ctest suite (as the `build_lean_header_snapshots.sh` setup fixture) is gated by the `LEAN_HEADER_SNAPSHOTS` CMake option, which currently defaults to `OFF`.
254+
Use of the snapshots at runtime is further controlled by the `LEAN_HEADER_SNAPSHOTS` environment variable:
255+
set it to `0` to force them off, or to `1` to force them on (if enabled at build time).
255256
By default, they are turned on only when running under ctest.
256257
To use the pre-built snapshots when manually running tests,
257258
run `tests/with_stage1_test_env.sh tests/build_lean_header_snapshots.sh`

0 commit comments

Comments
 (0)