diff --git a/test/blackbox-tests/setup-script.sh b/test/blackbox-tests/setup-script.sh index 346eea824fc..8aa910fb210 100644 --- a/test/blackbox-tests/setup-script.sh +++ b/test/blackbox-tests/setup-script.sh @@ -121,3 +121,9 @@ build () { file_status() { [ -e "$1" ] && echo "$1 exists" || echo "$1 missing" } + +strip_sandbox() { + # we want to substitute it to $SANDBOX + # shellcheck disable=SC2016 + dune_cmd subst '[^ ]*.sandbox[/\\][^/\\]+' '$SANDBOX' +} diff --git a/test/blackbox-tests/test-cases/cram/dune b/test/blackbox-tests/test-cases/cram/dune index d7e1aa35c05..55b7b61dec0 100644 --- a/test/blackbox-tests/test-cases/cram/dune +++ b/test/blackbox-tests/test-cases/cram/dune @@ -16,3 +16,9 @@ (cram (applies_to hg-access) (enabled_if %{bin-available:hg})) + +(cram + (applies_to junction-cleanup) + (enabled_if + (= %{os_type} Win32)) + (alias runtest-windows)) diff --git a/test/blackbox-tests/test-cases/cram/junction-cleanup.t b/test/blackbox-tests/test-cases/cram/junction-cleanup.t new file mode 100644 index 00000000000..ea596e63a9a --- /dev/null +++ b/test/blackbox-tests/test-cases/cram/junction-cleanup.t @@ -0,0 +1,32 @@ +On Windows, MSYS2 may create junctions (directory reparse points) instead of +proper symbolic links. OCaml's Unix.lstat returns ENOENT for junctions whose +targets are unreachable, which causes them to be invisible to directory cleanup. + +This test verifies that the cram test runner can clean up after a test that +creates junctions. + +This is currently not the case. + + $ trap 'cmd /c "rmdir /s /q _build" 2>/dev/null' EXIT + + $ cat > dune-project << EOF + > (lang dune 3.0) + > (cram enable) + > EOF + +Create a cram test that creates a junction inside its working directory: + + $ cat > junction.t <<'EOF' + > $ echo hi > file + > $ cmd /c "mklink /j junction file" > /dev/null + > EOF + + $ dune runtest 2>&1 | strip_sandbox + Error: failed to delete sandbox in + $SANDBOX + Reason: + $SANDBOX\default): Directory not empty + -> required by _build/default/.cram.junction.t/cram.out + -> required by alias junction + -> required by alias runtest + [1] diff --git a/test/blackbox-tests/test-cases/pkg/helpers.sh b/test/blackbox-tests/test-cases/pkg/helpers.sh index 42ed7fd1483..26318353a2c 100644 --- a/test/blackbox-tests/test-cases/pkg/helpers.sh +++ b/test/blackbox-tests/test-cases/pkg/helpers.sh @@ -55,12 +55,6 @@ show_pkg() { find "$prefix" | sort | dune_cmd subst "$prefix" "" } -strip_sandbox() { - # we want to substitute it to $SANDBOX - # shellcheck disable=SC2016 - dune_cmd subst '[^ ]*.sandbox/[^/]+' '$SANDBOX' -} - show_pkg_targets() { local pkg=$1 local prefix