From e3434e831ed4d89efa7f34097e5bac23935e2d14 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 27 Sep 2026 19:09:21 +0100 Subject: Detect transient-0 example output directories instead of checking name --- .../zwobble/hobgoblin/compiler/ExampleTests.java | 42 +++++++++++----------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java index a51ec14..77248f7 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java @@ -34,28 +34,26 @@ public class ExampleTests { var rustOutputPath = verifyRustOutput(exampleSet); verifyTypescriptOutput(exampleSet); - // TODO: make detection more robust - if (exampleSet.name().contains("transient-0")) { - var transient0OutputDirs = Stream.of(javaOutputPath, rustOutputPath) - .map(outputPath -> outputPath.orElseThrow().resolve("transient-0")) - .toList(); - - var names = transient0OutputDirs.stream() - .flatMap(outputPath -> Arrays.stream(outputPath.toFile().listFiles()).map(file -> file.getName())) - .collect(Collectors.toSet()) - .stream() - .sorted() - .toList(); - - for (var name : names) { - var expectedBytes = Optional.empty(); - for (var transient0OutputDir : transient0OutputDirs) { - var actualBytes = Files.readAllBytes(transient0OutputDir.resolve(name)); - if (expectedBytes.isEmpty()) { - expectedBytes = Optional.of(actualBytes); - } else { - assertThat(Arrays.equals(actualBytes, expectedBytes.get()), equalTo(true)); - } + var transient0OutputDirs = Stream.of(javaOutputPath, rustOutputPath) + .map(outputPath -> outputPath.orElseThrow().resolve("transient-0")) + .filter(transient0OutputPath -> transient0OutputPath.toFile().exists()) + .toList(); + + var names = transient0OutputDirs.stream() + .flatMap(outputPath -> Arrays.stream(outputPath.toFile().listFiles()).map(file -> file.getName())) + .collect(Collectors.toSet()) + .stream() + .sorted() + .toList(); + + for (var name : names) { + var expectedBytes = Optional.empty(); + for (var transient0OutputDir : transient0OutputDirs) { + var actualBytes = Files.readAllBytes(transient0OutputDir.resolve(name)); + if (expectedBytes.isEmpty()) { + expectedBytes = Optional.of(actualBytes); + } else { + assertThat(Arrays.equals(actualBytes, expectedBytes.get()), equalTo(true)); } } } -- cgit v1.2.3