summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/src/org
diff options
context:
space:
mode:
authorAndrey Loskutov <loskutov@gmx.de>2015-12-31 00:48:07 +0100
committerAndrey Loskutov <loskutov@gmx.de>2015-12-31 00:48:11 +0100
commit02ade82b345ea976d12c32547fb097e726fa44fb (patch)
tree6eb007ee3206b0b5cd0851e5c4aa1ade45ab5e3c /org.eclipse.jgit.pgm.test/src/org
parent3fc93f8a562e96d354546ad6ff8c9dd56709c5e5 (diff)
downloadjgit-02ade82b345ea976d12c32547fb097e726fa44fb.tar.gz
jgit-02ade82b345ea976d12c32547fb097e726fa44fb.zip
Make sure tests don't blindly continue if a command is "silently" failed
Make the default execute() function fail fast on first command printed "fatal: " to output. Introduced executeUnchecked() for few tests which wanted to test fatal output. Change-Id: I5b09aad9443515636811fc4d00bf8b8b9587a626 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/src/org')
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java51
1 files changed, 46 insertions, 5 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java
index 4bf9b43cbb..a72af9a1c4 100644
--- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java
+++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java
@@ -48,11 +48,13 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.pgm.CLIGitCommand;
+import org.eclipse.jgit.pgm.Die;
import org.junit.Before;
public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
@@ -79,7 +81,7 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
* @return command output
* @throws Exception
*/
- protected String[] execute(String... cmds) throws Exception {
+ protected String[] executeUnchecked(String... cmds) throws Exception {
List<String> result = new ArrayList<String>(cmds.length);
for (String cmd : cmds) {
result.addAll(CLIGitCommand.execute(cmd, db));
@@ -88,6 +90,28 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
}
/**
+ * Executes specified git commands (with arguments), throws exception and
+ * stops execution on first command which output contains a 'fatal:' error
+ *
+ * @param cmds
+ * each string argument must be a valid git command line, e.g.
+ * "git branch -h"
+ * @return command output
+ * @throws Exception
+ */
+ protected String[] execute(String... cmds) throws Exception {
+ List<String> result = new ArrayList<String>(cmds.length);
+ for (String cmd : cmds) {
+ List<String> out = CLIGitCommand.execute(cmd, db);
+ if (contains(out, "fatal: ")) {
+ throw new Die(toString(out));
+ }
+ result.addAll(out);
+ }
+ return result.toArray(new String[0]);
+ }
+
+ /**
* @param link
* the path of the symbolic link to create
* @param target
@@ -196,15 +220,32 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
}
protected void assertArrayOfLinesEquals(String[] expected, String[] actual) {
- assertEquals(toText(expected), toText(actual));
+ assertEquals(toString(expected), toString(actual));
+ }
+
+ public static String toString(String[] lines) {
+ return toString(Arrays.asList(lines));
}
- private static String toText(String[] lines) {
+ public static String toString(List<String> lines) {
StringBuilder b = new StringBuilder();
for (String s : lines) {
- b.append(s);
- b.append('\n');
+ if (s != null && !s.isEmpty()) {
+ b.append(s);
+ if (!s.endsWith("\n")) {
+ b.append('\n');
+ }
+ }
}
return b.toString();
}
+
+ public static boolean contains(List<String> lines, String str) {
+ for (String s : lines) {
+ if (s.contains(str)) {
+ return true;
+ }
+ }
+ return false;
+ }
}