diff --git a/.ci-scripts/test-runner-isolation.py b/.ci-scripts/test-runner-isolation.py new file mode 100644 index 0000000..e8890f9 --- /dev/null +++ b/.ci-scripts/test-runner-isolation.py @@ -0,0 +1,31 @@ +import subprocess +import sys +import tempfile +from pathlib import Path + + +def check_isolation(runner, workdir): + fixture_test = "--only=optional binaries - present" + subprocess.run([runner, fixture_test], cwd=workdir, check=True) + fixtures = workdir / ".pony_test" + locks = list(fixtures.rglob(".lock")) + if len(locks) != 1: + raise AssertionError(f"{fixture_test} produced {len(locks)} lockfiles, expected one") + first = locks[0] + marker = first.parent / "other-runner" + marker.write_text("in use") + + subprocess.run([runner, "--list"], cwd=workdir, check=True) + if not marker.is_file(): + raise AssertionError("Listing tests removed another runner's fixture") + + subprocess.run([runner, fixture_test], cwd=workdir, check=True) + if not marker.is_file() or not first.is_file(): + raise AssertionError("Running the same test removed the first fixture") + if not any(lock != first for lock in fixtures.rglob(".lock")): + raise AssertionError("Two executions of the same test shared a fixture") + + +if __name__ == "__main__": + with tempfile.TemporaryDirectory() as workdir: + check_isolation(Path(sys.argv[1]).resolve(), Path(workdir)) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 6696584..ae0a6b4 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -92,6 +92,8 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} run: make test + - name: Check test runner isolation + run: python3 .ci-scripts/test-runner-isolation.py build/release/test arm64-macos: name: arm64 MacOS tests diff --git a/Makefile b/Makefile index e6885bb..9f469f7 100644 --- a/Makefile +++ b/Makefile @@ -102,7 +102,9 @@ SOURCE_FILES := $(shell find cmd -name \*.pony) test: $(binary) $(GET_DEPENDENCIES_WITH) $(COMPILE_WITH) $(PONYC_FLAGS) $(LINKER) test -o $(BUILD_DIR) -b test - $(BUILD_DIR)/test --sequential --shuffle + @set -e; workdir=$$(mktemp -d "$(abspath $(BUILD_DIR))/test.XXXXXXXX"); \ + trap 'rm -rf "$$workdir"' 0; \ + (cd "$$workdir" && "$(abspath $(BUILD_DIR))/test" --sequential --shuffle) clean: $(CLEAN_DEPENDENCIES_WITH) diff --git a/README.md b/README.md index ac158cd..0e780e7 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,8 @@ From there the team can either point you at an existing platform identifier or a Building from source requires ponyc 0.79.0 or later. +Run the tests with `make test` on Linux or macOS, or `.\make.ps1 test` on Windows. These commands remove their test files when the runner exits. To inspect the files, run the compiled test binary directly. It keeps each test’s packages and lockfile in a separate directory under `.pony_test` in your working directory. + ### Vendored LibreSSL macOS builds statically link against vendored LibreSSL libraries in `lib/`. This eliminates the runtime dependency on Homebrew's LibreSSL, which would break when Homebrew updates to a newer version. diff --git a/make.ps1 b/make.ps1 index cda598d..f487127 100644 --- a/make.ps1 +++ b/make.ps1 @@ -204,8 +204,18 @@ switch ($Command.ToLower()) { $testFile = (BuildTest)[-1] Write-Host "$testFile --sequential --shuffle" - & "$testFile" --sequential --shuffle - if ($LastExitCode -ne 0) { throw "Error" } + $workDir = New-Item -ItemType Directory -Path (Join-Path $buildDir ([guid]::NewGuid())) + try { + Push-Location -LiteralPath $workDir.FullName + try { + & "$testFile" --sequential --shuffle + if ($LastExitCode -ne 0) { throw "Error" } + } finally { + Pop-Location + } + } finally { + Remove-Item -LiteralPath $workDir.FullName -Recurse -Force + } break } diff --git a/test/main.pony b/test/main.pony index 2730cc3..c3b95cd 100644 --- a/test/main.pony +++ b/test/main.pony @@ -5,9 +5,6 @@ use "../cmd" actor \nodoc\ Main is TestList new create(env: Env) => - let test_dir = - FilePath(FileAuth(env.root), _TestDir.base()) - if test_dir.exists() then test_dir.remove() end PonyTest(env, this) fun tag tests(test: PonyTest) => @@ -437,7 +434,7 @@ actor \nodoc\ _SyncTester is PonyupNotify _application.name() + "/" + pkg.channel end let root = - _TestDir.root(FileAuth(_auth), name) + _TestDir.root(FileAuth(_auth), name)? _root = root let lockfile = recover @@ -532,7 +529,7 @@ actor \nodoc\ _SelectTester is PonyupNotify _pkg_a = pkg_a _pkg_b = pkg_b let root = - _TestDir.root(FileAuth(h.env.root), "select") + _TestDir.root(FileAuth(h.env.root), "select")? _root = root let lockfile = recover @@ -669,7 +666,7 @@ actor \nodoc\ _RemoveTester is PonyupNotify _pkg_a = pkg_a _pkg_b = pkg_b let root = - _TestDir.root(FileAuth(h.env.root), "remove") + _TestDir.root(FileAuth(h.env.root), "remove")? _root = root let lockfile = recover @@ -782,7 +779,7 @@ actor \nodoc\ _RetryNotFoundTester is PonyupNotify target)? let root = _TestDir.root( - FileAuth(h.env.root), "retry-not-found") + FileAuth(h.env.root), "retry-not-found")? let lockfile = recover CreateFile(root.join(".lock")?) as File @@ -906,7 +903,7 @@ actor \nodoc\ _OptionalBinariesPresentTester let root = _TestDir.root( FileAuth(h.env.root), - "optional-binaries-present") + "optional-binaries-present")? _root = root let staged = recover Array[String] end let parts = @@ -998,7 +995,7 @@ actor \nodoc\ _OptionalBinariesAbsentTester let root = _TestDir.root( FileAuth(h.env.root), - "optional-binaries-absent") + "optional-binaries-absent")? _root = root let parts = _TestPonyup.partition_binaries( @@ -1082,7 +1079,7 @@ actor \nodoc\ _OptionalBinariesPartialTester let root = _TestDir.root( FileAuth(h.env.root), - "optional-binaries-partial") + "optional-binaries-partial")? _root = root let parts = _TestPonyup.partition_binaries( @@ -1164,13 +1161,13 @@ actor \nodoc\ _OptionalBinariesPartialTester _h.log(str) primitive \nodoc\ _TestDir - fun base(): String => "./.pony_test" - - fun root(auth: FileAuth, name: String): FilePath => - let dir = - FilePath( - auth, base() + "/" + name + "/ponyup") - if not dir.exists() then dir.mkdir() end + fun root(auth: FileAuth, name: String): FilePath ? => + let prefix = ".pony_test/" + name + "-" + var dir = FilePath(auth, prefix + Path.random()) + while not dir.mkdir(true) do + if not dir.exists() then error end + dir = FilePath(auth, prefix + Path.random()) + end dir primitive _TestPonyup