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>
This commit is contained in:
Andrey Loskutov 2015-10-10 22:02:24 +03:00
parent 50d6fbcdae
commit eec37d2334
3 changed files with 34 additions and 18 deletions

View File

@ -722,18 +722,23 @@ public void testRecordRemoteBranch() throws Exception {
.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"));
}
}
}

View File

@ -63,6 +63,7 @@
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 void testLeadingSpaces() throws IOException {
@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 ", "");

View File

@ -92,9 +92,11 @@ public void testFailedCommitMsgHookBlocksCommit() throws Exception {
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 void testCommitMsgHookReceivesCorrectParameter() throws Exception {
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 void testRunHook() throws Exception {
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 void testFailedPreCommitHookBlockCommit() throws Exception {
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());
}
}