Browse Source

Fix some tests for running in bazel

Some tests call out to external cgit. Those tests all failed for me
locally on Mac. Turned out that the reason was that the system git
config used by the git in the bazel run contained paths with ~/ but
somehow $HOME was not set. As a result the external git returned
with exit code 128.

Fix this by passing along $HOME explicitly. Also improve assertions
to make sure we do get the stderr of the external command in the
test log.

I hadn't noticed that until now because apparently the maven build
does pass along $HOME.

Change-Id: I7069676d5cc7b23a71e79a4866fe8acab5a405f4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.9
Thomas Wolf 7 years ago
parent
commit
c91c20f36f
  1. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java
  2. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java
  3. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/attributes/CGitAttributesTest.java

@ -125,11 +125,12 @@ public class CGitAttributesTest extends RepositoryTestCase {
ProcessBuilder builder = fs.runInShell("git",
new String[] { "check-attr", "--stdin", "--all" });
builder.directory(db.getWorkTree());
builder.environment().put("HOME", fs.userHome().getAbsolutePath());
ExecutionResult result = fs.execute(builder, new ByteArrayInputStream(
input.toString().getBytes(Constants.CHARSET)));
assertEquals("External git reported errors", "",
toString(result.getStderr()));
assertEquals("External git failed", 0, result.getRc());
String errorOut = toString(result.getStderr());
assertEquals("External git failed", "exit 0\n",
"exit " + result.getRc() + '\n' + errorOut);
LinkedHashMap<String, Attributes> map = new LinkedHashMap<>();
try (BufferedReader r = new BufferedReader(new InputStreamReader(
new BufferedInputStream(result.getStdout().openInputStream()),

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/ignore/CGitIgnoreTest.java

@ -105,11 +105,12 @@ public class CGitIgnoreTest extends RepositoryTestCase {
ProcessBuilder builder = fs.runInShell("git", new String[] { "ls-files",
"--ignored", "--exclude-standard", "-o" });
builder.directory(db.getWorkTree());
builder.environment().put("HOME", fs.userHome().getAbsolutePath());
ExecutionResult result = fs.execute(builder,
new ByteArrayInputStream(new byte[0]));
assertEquals("External git failed", 0, result.getRc());
assertEquals("External git reported errors", "",
toString(result.getStderr()));
String errorOut = toString(result.getStderr());
assertEquals("External git failed", "exit 0\n",
"exit " + result.getRc() + '\n' + errorOut);
try (BufferedReader r = new BufferedReader(new InputStreamReader(
new BufferedInputStream(result.getStdout().openInputStream()),
Constants.CHARSET))) {

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java

@ -142,7 +142,11 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase {
String[] cmd = { "/bin/sh", "./" + name + ".sh" };
int exitCode;
String stdErr;
Process process = Runtime.getRuntime().exec(cmd, null, testDir);
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.environment().put("HOME",
FS.DETECTED.userHome().getAbsolutePath());
builder.directory(testDir);
Process process = builder.start();
try (InputStream stdOutStream = process.getInputStream();
InputStream stdErrStream = process.getErrorStream();
OutputStream stdInStream = process.getOutputStream()) {

Loading…
Cancel
Save