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
31 changes: 31 additions & 0 deletions .ci-scripts/test-runner-isolation.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 12 additions & 2 deletions make.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
31 changes: 14 additions & 17 deletions test/main.pony
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Loading