From a92baf30c84f56d93f13d9b30ad0ad86573b7d07 Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Fri, 7 Oct 2022 09:52:50 +0100 Subject: [PATCH] disable test tied to os specific behaviour --- .../tooling/DirectorySourceLocatorTest.java | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/DirectorySourceLocatorTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/DirectorySourceLocatorTest.java index bc44c4691..c216f3a60 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/DirectorySourceLocatorTest.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/tooling/DirectorySourceLocatorTest.java @@ -23,9 +23,11 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Collection; import java.util.Optional; import org.junit.Before; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -71,19 +73,26 @@ public void findsFileInPackageBeforeOneAtRoot() throws Exception { @Test public void findsFileInCorrectPackageBeforeWronglyPackagedOnes() throws Exception { - createFile(root.resolve("com/example/correct/Foo.java"), "this one"); - createFile(root.resolve("Foo.java"), "not this one"); - createFile(root.resolve("com/example/Foo.java"), "not this one"); + createFile(root.resolve("com/example/correct/Foo.java"), "correct"); + createFile(root.resolve("Foo.java"), "in package default"); + createFile(root.resolve("com/example/Foo.java"), "example"); createFile(root.resolve("com/example/wrong/Foo.java"), "not this one"); createFile(root.resolve("com/example/correct/wrong/Foo.java"), "not this one"); - Optional actual = testee.locate(singletonList("com.example.correct.Foo"), "Foo.java"); - assertThat(content(actual)).isEqualTo("this one"); + + assertThat(findFor("com.example.correct.Foo", "Foo.java")).isEqualTo("correct"); + assertThat(findFor("Foo", "Foo.java")).isEqualTo("in package default"); + assertThat(findFor("com.example.Foo", "Foo.java")).isEqualTo("example"); } @Test - public void findsFileInRootBeforeOneInWrongPackage() throws Exception { - createFile(root.resolve("com/example/other/Foo.java"), "not this one"); - createFile(root.resolve("Foo.java"), "this one"); + @Ignore + // Docs suggest that Files.walk/find should search depth first, but behaviour seems + // to be OS dependent in practice. Windows ci on azure looks to search depth first, linux + // and mac find the root file. Fortunately we don't actually care about the behaviour in this case + // either file might be the one the user intended + public void findsFileInWrongPackageBeforeRoot() throws Exception { + createFile(root.resolve("com/example/other/Foo.java"), "this one"); + createFile(root.resolve("Foo.java"), "not this one"); Optional actual = testee.locate(singletonList("com.example.Foo"), "Foo.java"); assertThat(content(actual)).isEqualTo("this one"); } @@ -111,6 +120,16 @@ public void doesNotErrorWhenRootDoesNotExist() { .doesNotThrowAnyException(); } + private String findFor(String clazz, String file) throws Exception { + return findFor(singletonList(clazz), file); + } + + private String findFor(Collection classes, String file) throws Exception { + Optional actual = testee.locate(classes, file); + return content(actual); + } + + private void createFile(Path file, String content) throws IOException { if (file.getParent() != null) { Files.createDirectories(file.getParent());