Allow commandline tests to use raw output
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
This commit is contained in:
parent
fa5231191d
commit
789ca39ade
|
@ -70,6 +70,16 @@ public List<String> getArguments() {
|
||||||
|
|
||||||
public static List<String> execute(String str, Repository db)
|
public static List<String> execute(String str, Repository db)
|
||||||
throws Exception {
|
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);
|
String[] args = split(str);
|
||||||
if (!args[0].equalsIgnoreCase("git") || args.length < 2)
|
if (!args[0].equalsIgnoreCase("git") || args.length < 2)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -91,14 +101,11 @@ public static List<String> execute(String str, Repository db)
|
||||||
try {
|
try {
|
||||||
cmd.execute(bean.getArguments().toArray(
|
cmd.execute(bean.getArguments().toArray(
|
||||||
new String[bean.getArguments().size()]));
|
new String[bean.getArguments().size()]));
|
||||||
} catch (Die e) {
|
|
||||||
return IO.readLines(MessageFormat.format(CLIText.get().fatalError,
|
|
||||||
e.getMessage()));
|
|
||||||
} finally {
|
} finally {
|
||||||
if (cmd.outw != null)
|
if (cmd.outw != null)
|
||||||
cmd.outw.flush();
|
cmd.outw.flush();
|
||||||
}
|
}
|
||||||
return IO.readLines(baos.toString());
|
return baos.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue