Piszę program który testuje działanie innego programu, w tym wypadku napisanego w c.
Robię to przekazując mu jako wejście plik testowy zawierający 1<x<10^6 liczb, następnie odczytuję wyjście i porównuję z oczekiwanym wynikiem.
Niestety jeśli test zawiera >10 liczb odczyt z wyjścia jest pusty, co robię źle?
@Override
public Integer call() throws Exception {
ProcessBuilder pb = new ProcessBuilder(progPath);
pb.redirectInput(new File(testPath.toString()));
pb.redirectErrorStream(true);
Process proc = pb.start();
InputStream in = proc.getInputStream();
String output = readOutput(in);
proc.waitFor();
String answer = Files.lines(answerPath).collect(Collectors.joining(" "));
if (output.trim().equalsIgnoreCase(answer.trim())) {
System.out.println("OK: \"" + testPath.toString());
return 0;
} else {
System.out.println("WA: \"" + testPath.toString() + "\" \n" + output.trim() + "\n" + answer.trim());
return 1;
}
}
private String readOutput(InputStream is) {
Scanner s = new Scanner(is);
String str = "";
while (s.hasNext()) {
str += s.next() + " ";
}
s.close();
return str;
}