|
| 1 | +package dev.robocode.tankroyale.bridge.conformance; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.DisplayName; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | + |
| 6 | +import java.nio.file.Path; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 10 | + |
| 11 | +/** |
| 12 | + * Acceptance evidence for FIO-001 and FIO-002 — a root-relative path a robot names is |
| 13 | + * redirected into its data directory, and {@code getDataFile} and {@code getDataDirectory} |
| 14 | + * agree about where that directory is. |
| 15 | + */ |
| 16 | +class FileRedirectionConformanceTest extends ConformanceTestBase { |
| 17 | + |
| 18 | + private static final String ROBOT = "conformance.probes.FileRedirectionProbe"; |
| 19 | + private static final Path SOURCE = ConformanceHarness.repoRoot().resolve(Path.of( |
| 20 | + "compat-test", "conformance-robots", "conformance", "probes", "FileRedirectionProbe.java")); |
| 21 | + |
| 22 | + @Test |
| 23 | + @DisplayName("FIO-001: a root-relative path is redirected into the data directory") |
| 24 | + void testFIO001_IntegrationPositive_RootRelativePathIsRedirectedIntoDataDirectory() { |
| 25 | + assertOnBothEngines(ROBOT, SOURCE, (outcome, engine) -> { |
| 26 | + assertTrue(outcome.anyConsoleContains("WriteSucceeded:/root-relative-name.txt:true"), |
| 27 | + () -> "the root-relative write did not succeed on " + engine |
| 28 | + + " (" + outcome.summary() + ")"); |
| 29 | + assertTrue(outcome.anyConsoleContains("DirectoryListing:root-relative-name.txt"), |
| 30 | + () -> "the redirected file did not land in the data directory on " + engine |
| 31 | + + " (" + outcome.summary() + ")"); |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + @DisplayName("FIO-001 negative: the redirected name is not written where it was named") |
| 37 | + void testFIO001_IntegrationNegative_NothingIsWrittenAtTheNamedPath() { |
| 38 | + assertOnBothEngines(ROBOT, SOURCE, (outcome, engine) -> { |
| 39 | + for (String console : outcome.consoles()) { |
| 40 | + for (String line : console.split("\\R")) { |
| 41 | + if (line.startsWith("Resolved:/root-relative-name.txt:")) { |
| 42 | + String resolved = line.substring("Resolved:/root-relative-name.txt:".length()); |
| 43 | + assertFalse(resolved.equals("/root-relative-name.txt") |
| 44 | + || resolved.equals("\\root-relative-name.txt"), |
| 45 | + () -> "the name resolved to the unredirected path on " + engine + ": " + line); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + @DisplayName("FIO-002: getDataFile and getDataDirectory resolve against the same place") |
| 54 | + void testFIO002_IntegrationPositive_DataFileAndDataDirectoryAgree() { |
| 55 | + assertOnBothEngines(ROBOT, SOURCE, (outcome, engine) -> { |
| 56 | + assertTrue(outcome.anyConsoleContains("WriteSucceeded:plain-name.txt:true"), |
| 57 | + () -> "the plain-name write did not succeed on " + engine |
| 58 | + + " (" + outcome.summary() + ")"); |
| 59 | + assertTrue(outcome.anyConsoleContains("DirectoryListing:plain-name.txt"), |
| 60 | + () -> "getDataDirectory's listing did not see what getDataFile wrote on " + engine |
| 61 | + + " (" + outcome.summary() + ")"); |
| 62 | + }); |
| 63 | + } |
| 64 | + |
| 65 | + @Test |
| 66 | + @DisplayName("FIO-002 negative: the directory listing reports no file the probe did not write") |
| 67 | + void testFIO002_IntegrationNegative_DirectoryListingReportsNoUnwrittenFile() { |
| 68 | + assertOnBothEngines(ROBOT, SOURCE, (outcome, engine) -> |
| 69 | + assertFalse(outcome.anyConsoleContains("DirectoryListing:none"), |
| 70 | + () -> "the data directory listing came back empty on " + engine |
| 71 | + + " (" + outcome.summary() + ")")); |
| 72 | + } |
| 73 | +} |
0 commit comments