aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Nieder2012-11-16 18:16:18 (EST)
committerJonathan Nieder2012-11-16 18:45:52 (EST)
commit789ca39adeb794ee63c7e5b6484f521de5b1f29d (patch)
tree076f3fe46ba671e8101f1607d5be7dde19d1e2b6
parentfa5231191d530afb24810080e89990913c8e8054 (diff)
downloadjgit-789ca39adeb794ee63c7e5b6484f521de5b1f29d.zip
jgit-789ca39adeb794ee63c7e5b6484f521de5b1f29d.tar.gz
jgit-789ca39adeb794ee63c7e5b6484f521de5b1f29d.tar.bz2
Allow commandline tests to use raw outputrefs/changes/46/8746/2
Introduce a new CLIGitCommand.rawExecute() helper that behaves just like execute() except that instead of processing its output it returns it raw. So now you can do final byte[] expect = { 0, 1, 2, 3 }; final byte[] actual = CLIGitCommand.rawExecute( "git show HEAD:goo.raw", db); assertArrayEquals(expect, actual); to test the output from "git show HEAD:goo.raw" without being distracted by encoding issues. Noticed while writing tests for a new "jgit archive" command that writes its output in ZIP format. Change-Id: I2fe6020a537975d0ccf414b7125d85d6cd86898c
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
index 982aa95..78706da 100644
--- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
+++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/pgm/CLIGitCommand.java
@@ -70,6 +70,16 @@ public class CLIGitCommand {
public static List<String> execute(String str, Repository db)
throws Exception {
+ try {
+ return IO.readLines(new String(rawExecute(str, db)));
+ } catch (Die e) {
+ return IO.readLines(MessageFormat.format(CLIText.get().fatalError,
+ e.getMessage()));
+ }
+ }
+
+ public static byte[] rawExecute(String str, Repository db)
+ throws Exception {
String[] args = split(str);
if (!args[0].equalsIgnoreCase("git") || args.length < 2)
throw new IllegalArgumentException(
@@ -91,14 +101,11 @@ public class CLIGitCommand {
try {
cmd.execute(bean.getArguments().toArray(
new String[bean.getArguments().size()]));
- } catch (Die e) {
- return IO.readLines(MessageFormat.format(CLIText.get().fatalError,
- e.getMessage()));
} finally {
if (cmd.outw != null)
cmd.outw.flush();
}
- return IO.readLines(baos.toString());
+ return baos.toByteArray();
}
/**