From 4a4134b374dc8dbdbe06de42f5e6fc3d8622b64d Mon Sep 17 00:00:00 2001 From: adamw7 Date: Sun, 23 Aug 2026 09:48:48 +0000 Subject: [PATCH] test(data): make the file-source tests Windows-neutral The weekly maven-windows run failed on two assumptions that only hold on POSIX. AbstractFileSourceTest left the source of a failed read unclosed, and Windows refuses to delete a file a handle still holds, so @TempDir cleanup failed the test; the source is now closed in a try-with-resources. AllowedPathsTest expected validate() to answer a real path, which matches an absolute normalised one everywhere but Windows, where @TempDir hands back the short 8.3 form (RUNNER~1) that toRealPath() spells out; it now compares against the canonicalisation validate() documents. Co-authored-by: Claude Claude-Session: https://claude.ai/code/session_01XmRt9ZYYtKg7S2Ebfvih6g --- .../source/file/AbstractFileSourceTest.java | 22 +++++++++++-------- .../data/source/file/AllowedPathsTest.java | 6 ++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java b/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java index c5060cfa..5a3c3767 100644 --- a/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java +++ b/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java @@ -59,15 +59,19 @@ public void csvSourceFailsWhenTheReadBreaksMidFile() { @Test public void csvSourceNamesTheFileItFailedToRead(@TempDir Path directory) throws IOException { Path file = truncatedGzip(directory); - CSVDataSource source = new CSVDataSource(file.toString(), ",", 1, AllowedPaths.under(directory)); - source.open(); - - UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> readAll(source)); - - // A GZip member cut short ends with an unexpected EOF rather than a clean end of - // data; the message must name the file so the failure can be traced to it. - assertInstanceOf(EOFException.class, thrown.getCause()); - assertTrue(thrown.getMessage().contains(file.toString()), thrown.getMessage()); + // Closed even though the read failed: the failure leaves the descriptor open, and + // Windows refuses to delete a file some handle still holds, so an unclosed source + // fails @TempDir's cleanup rather than the assertions below. + try (CSVDataSource source = new CSVDataSource(file.toString(), ",", 1, AllowedPaths.under(directory))) { + source.open(); + + UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> readAll(source)); + + // A GZip member cut short ends with an unexpected EOF rather than a clean end of + // data; the message must name the file so the failure can be traced to it. + assertInstanceOf(EOFException.class, thrown.getCause()); + assertTrue(thrown.getMessage().contains(file.toString()), thrown.getMessage()); + } } @Test diff --git a/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java b/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java index 4299b68c..5d469d32 100644 --- a/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java +++ b/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java @@ -71,7 +71,11 @@ public void acceptsFileNameStartingWithTwoDots(@TempDir Path baseDir) throws IOE String validated = AllowedPaths.under(baseDir).validate(dotted.toString()); - assertEquals(dotted.toRealPath().toString(), validated); + // Compared against the canonicalisation validate() documents -- absolute and + // normalised -- rather than the real path: on Windows the temporary directory is + // handed over in its short 8.3 form (RUNNER~1), which toRealPath() spells out and + // validate() leaves exactly as it was given. + assertEquals(dotted.toAbsolutePath().normalize().toString(), validated); } @Test