Browse Source

Fixed jgit test failures on Windows

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>
stable-4.2
Andrey Loskutov 9 years ago
parent
commit
eec37d2334
  1. 27
      org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
  2. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java
  3. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java

27
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java

@ -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"));
}
}
}

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/IgnoreNodeTest.java

@ -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 ", "");

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/util/HookTest.java

@ -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());
}
}

Loading…
Cancel
Save