]> source.dussan.org Git - jgit.git/commitdiff
Fixed jgit test failures on Windows 25/57925/2
authorAndrey Loskutov <loskutov@gmx.de>
Sat, 10 Oct 2015 19:02:24 +0000 (22:02 +0300)
committerAndrey Loskutov <loskutov@gmx.de>
Mon, 12 Oct 2015 10:03:39 +0000 (06:03 -0400)
RepoCommandTest was failing because of open file handle left.
IgnoreNodeTest was failing because of problems with creation of files
with trailing spaces on Windows.
HookTest was failing because of wrong line delimiter.

Change-Id: I34f074ac447eb4c3ada8b250309bb568b426189d
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java

index c6c7ea0eb923614903e20dff3e7ed991f02963f1..b6649b3f0510931ccb070aae577702ee8524b2c2 100644 (file)
@@ -722,18 +722,23 @@ public class RepoCommandTest extends RepositoryTestCase {
                                .call();
                        // Clone it
                        File directory = createTempDirectory("testBareRepo");
-                       Repository localDb = Git.cloneRepository().setDirectory(directory)
+                       try (Repository localDb = Git.cloneRepository()
+                                       .setDirectory(directory)
                                        .setURI(remoteDb.getDirectory().toURI().toString()).call()
-                                       .getRepository();
-                       // The .gitmodules file should exist
-                       File gitmodules = new File(localDb.getWorkTree(), ".gitmodules");
-                       assertTrue("The .gitmodules file should exist", gitmodules.exists());
-                       FileBasedConfig c = new FileBasedConfig(gitmodules, FS.DETECTED);
-                       c.load();
-                       assertEquals("standard branches work", "master",
-                               c.getString("submodule", "with-branch", "branch"));
-                       assertEquals("long branches work", "refs/heads/master",
-                               c.getString("submodule", "with-long-branch", "branch"));
+                                       .getRepository();) {
+                               // The .gitmodules file should exist
+                               File gitmodules = new File(localDb.getWorkTree(),
+                                               ".gitmodules");
+                               assertTrue("The .gitmodules file should exist",
+                                               gitmodules.exists());
+                               FileBasedConfig c = new FileBasedConfig(gitmodules,
+                                               FS.DETECTED);
+                               c.load();
+                               assertEquals("standard branches work", "master",
+                                               c.getString("submodule", "with-branch", "branch"));
+                               assertEquals("long branches work", "refs/heads/master",
+                                               c.getString("submodule", "with-long-branch", "branch"));
+                       }
                }
        }
 
index 9722ac67501110937804bf094cfd42e097dafbf6..5893d8c4077f630fe5853f1c5bbb1d1af6b6b6f3 100644 (file)
@@ -63,6 +63,7 @@ import org.eclipse.jgit.treewalk.FileTreeIterator;
 import org.eclipse.jgit.treewalk.TreeWalk;
 import org.eclipse.jgit.treewalk.WorkingTreeIterator;
 import org.eclipse.jgit.util.FileUtils;
+import org.eclipse.jgit.util.SystemReader;
 import org.junit.Test;
 
 /**
@@ -468,6 +469,9 @@ public class IgnoreNodeTest extends RepositoryTestCase {
 
        @Test
        public void testTrailingSpaces() throws IOException {
+               // Windows can't create files with trailing spaces
+               // If this assumption fails the test is halted and ignored.
+               org.junit.Assume.assumeFalse(SystemReader.getInstance().isWindows());
                writeTrashFile("a  /a", "");
                writeTrashFile("a  /a ", "");
                writeTrashFile("a  /a  ", "");
index b14a9bf2fad667a2b470196e3c3f8c802df90111..8aa14c5218368888e0d270dc8d2e410406baed25 100644 (file)
@@ -92,9 +92,11 @@ public class HookTest extends RepositoryTestCase {
                        fail("expected commit-msg hook to abort commit");
                } catch (AbortedByHookException e) {
                        assertEquals("unexpected error message from commit-msg hook",
-                                       "Rejected by \"commit-msg\" hook.\nstderr\n",
+                                       "Rejected by \"commit-msg\" hook.\nstderr"
+                                                       + System.lineSeparator(),
                                        e.getMessage());
-                       assertEquals("unexpected output from commit-msg hook", "test\n",
+                       assertEquals("unexpected output from commit-msg hook",
+                                       "test" + System.lineSeparator(),
                                        out.toString());
                }
        }
@@ -112,7 +114,8 @@ public class HookTest extends RepositoryTestCase {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                git.commit().setMessage("commit")
                                .setHookOutputStream(new PrintStream(out)).call();
-               assertEquals(".git/COMMIT_EDITMSG\n", out.toString("UTF-8"));
+               assertEquals(".git/COMMIT_EDITMSG" + System.lineSeparator(),
+                               out.toString("UTF-8"));
        }
 
        @Test
@@ -144,9 +147,11 @@ public class HookTest extends RepositoryTestCase {
                                new String[] {
                                "arg1", "arg2" },
                                new PrintStream(out), new PrintStream(err), "stdin");
-               assertEquals("unexpected hook output", "test arg1 arg2\nstdin\n",
+               assertEquals("unexpected hook output", "test arg1 arg2"
+                               + System.lineSeparator() + "stdin" + System.lineSeparator(),
                                out.toString("UTF-8"));
-               assertEquals("unexpected output on stderr stream", "stderr\n",
+               assertEquals("unexpected output on stderr stream",
+                               "stderr" + System.lineSeparator(),
                                err.toString("UTF-8"));
                assertEquals("unexpected exit code", 0, res.getExitCode());
                assertEquals("unexpected process status", ProcessResult.Status.OK,
@@ -170,9 +175,11 @@ public class HookTest extends RepositoryTestCase {
                        fail("expected pre-commit hook to abort commit");
                } catch (AbortedByHookException e) {
                        assertEquals("unexpected error message from pre-commit hook",
-                                       "Rejected by \"pre-commit\" hook.\nstderr\n",
+                                       "Rejected by \"pre-commit\" hook.\nstderr"
+                                                       + System.lineSeparator(),
                                        e.getMessage());
-                       assertEquals("unexpected output from pre-commit hook", "test\n",
+                       assertEquals("unexpected output from pre-commit hook",
+                                       "test" + System.lineSeparator(),
                                        out.toString());
                }
        }