From: Thomas Wolf Date: Mon, 31 Jan 2022 07:25:44 +0000 (+0100) Subject: [test] RepoCommandTest: guard tests for executable files X-Git-Tag: v6.1.0.202202221755-m3~31 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fbe7f9c2912e058b419848af5e45ca8c7ff4b601;p=jgit.git [test] RepoCommandTest: guard tests for executable files On Windows, java.io.File.canExecute is always true. Guard assertions testing the executable bit with FS.DETECTED.supportsExecute(). Bug: 550111 Change-Id: I2704d122f5b1086d01a0503a8c047a02ecbc1d4a Signed-off-by: Thomas Wolf --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java index 509adc2cb2..3e6d13a67e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java @@ -15,6 +15,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.BufferedReader; import java.io.ByteArrayInputStream; @@ -546,24 +547,29 @@ public class RepoCommandTest extends RepositoryTestCase { // The original file should exist File hello = new File(localDb.getWorkTree(), "foo/hello.txt"); assertTrue("The original file should exist", hello.exists()); - assertFalse("The original file should not be executable", - hello.canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertFalse("The original file should not be executable", + FS.DETECTED.canExecute(hello)); + } assertContents(hello.toPath(), "master world"); // The dest file should also exist hello = new File(localDb.getWorkTree(), "Hello"); assertTrue("The destination file should exist", hello.exists()); - assertFalse("The destination file should not be executable", - hello.canExecute()); + if (FS.DETECTED.supportsExecute()) { + assertFalse("The destination file should not be executable", + FS.DETECTED.canExecute(hello)); + } assertContents(hello.toPath(), "master world"); } @Test public void testRepoManifestCopyFile_executable() throws Exception { + assumeTrue(FS.DETECTED.supportsExecute()); try (Git git = new Git(defaultDb)) { git.checkout().setName("master").call(); File f = JGitTestUtil.writeTrashFile(defaultDb, "hello.sh", "content of the executable file"); - f.setExecutable(true); + FS.DETECTED.setExecute(f, true); git.add().addFilepattern("hello.sh").call(); git.commit().setMessage("Add binary file").call(); } @@ -588,7 +594,8 @@ public class RepoCommandTest extends RepositoryTestCase { // The original file should exist and be an executable File hello = new File(localDb.getWorkTree(), "foo/hello.sh"); assertTrue("The original file should exist", hello.exists()); - assertTrue("The original file must be executable", hello.canExecute()); + assertTrue("The original file must be executable", + FS.DETECTED.canExecute(hello)); try (BufferedReader reader = Files.newBufferedReader(hello.toPath(), UTF_8)) { String content = reader.readLine(); @@ -600,7 +607,7 @@ public class RepoCommandTest extends RepositoryTestCase { hello = new File(localDb.getWorkTree(), "copy-hello.sh"); assertTrue("The destination file should exist", hello.exists()); assertTrue("The destination file must be executable", - hello.canExecute()); + FS.DETECTED.canExecute(hello)); try (BufferedReader reader = Files.newBufferedReader(hello.toPath(), UTF_8)) { String content = reader.readLine();