39
40 public class JitTesterDriver {
41
42 public static void main(String[] args) {
43 if (args.length != 1) {
44 throw new IllegalArgumentException(
45 "[TESTBUG]: wrong number of argument : " + args.length
46 + ". Expected 1 argument -- jit-tester test name.");
47 }
48 OutputAnalyzer oa;
49 try {
50 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, args[0]);
51 oa = new OutputAnalyzer(pb.start());
52 } catch (Exception e) {
53 throw new Error("Unexpected exception on test jvm start :" + e, e);
54 }
55
56 Pattern splitOut = Pattern.compile("\\n"); // tests use \n only in stdout
57 Pattern splitErr = Pattern.compile("\\r?\\n"); // can handle both \r\n and \n
58 Path testDir = Paths.get(Utils.TEST_SRC);
59 String goldOut = formatOutput(streamGoldFile(testDir, args[0], "out"), s -> true);
60 String anlzOut = formatOutput(Arrays.stream(splitOut.split(oa.getStdout())), s -> true);
61 Asserts.assertEQ(anlzOut, goldOut, "Actual stdout isn't equal to golden one");
62 // TODO: add a comment why we skip such lines
63 Predicate<String> notStartWhitespaces = s -> !(s.startsWith("\t") || s.startsWith(" "));
64 String goldErr = formatOutput(streamGoldFile(testDir, args[0], "err"), notStartWhitespaces);
65 String anlzErr = formatOutput(Arrays.stream(splitErr.split(oa.getStderr())),
66 notStartWhitespaces);
67 Asserts.assertEQ(anlzErr, goldErr, "Actual stderr isn't equal to golden one");
68
69 int exitValue = Integer.parseInt(streamGoldFile(testDir, args[0], "exit").findFirst().get());
70 oa.shouldHaveExitValue(exitValue);
71 }
72
73 private static String formatOutput(Stream<String> stream, Predicate<String> predicate) {
74 String result = stream
75 .filter(predicate)
76 .collect(Collectors.joining(Utils.NEW_LINE));
77 if (result.length() > 0) {
78 result += Utils.NEW_LINE;
79 }
80 return result;
81 }
82
83 private static Stream<String> streamGoldFile(Path dir, String name, String suffix) {
84 try {
85 return Files.lines(dir.resolve(name + ".gold." + suffix));
86 } catch (IOException e) {
87 throw new Error(String.format("Can't read golden %s for %s : %s", suffix, name, e), e);
88 }
89 }
90 }
|
39
40 public class JitTesterDriver {
41
42 public static void main(String[] args) {
43 if (args.length != 1) {
44 throw new IllegalArgumentException(
45 "[TESTBUG]: wrong number of argument : " + args.length
46 + ". Expected 1 argument -- jit-tester test name.");
47 }
48 OutputAnalyzer oa;
49 try {
50 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, args[0]);
51 oa = new OutputAnalyzer(pb.start());
52 } catch (Exception e) {
53 throw new Error("Unexpected exception on test jvm start :" + e, e);
54 }
55
56 Pattern splitOut = Pattern.compile("\\n"); // tests use \n only in stdout
57 Pattern splitErr = Pattern.compile("\\r?\\n"); // can handle both \r\n and \n
58 Path testDir = Paths.get(Utils.TEST_SRC);
59 String goldOut = formatOutput(streamGoldFile(testDir, args[0], "out"));
60 String anlzOut = formatOutput(Arrays.stream(splitOut.split(oa.getStdout())));
61 Asserts.assertEQ(anlzOut, goldOut, "Actual stdout isn't equal to golden one");
62 String goldErr = formatOutput(streamGoldFile(testDir, args[0], "err"));
63 String anlzErr = formatOutput(Arrays.stream(splitErr.split(oa.getStderr())));
64 Asserts.assertEQ(anlzErr, goldErr, "Actual stderr isn't equal to golden one");
65
66 int exitValue = Integer.parseInt(streamGoldFile(testDir, args[0], "exit").findFirst().get());
67 oa.shouldHaveExitValue(exitValue);
68 }
69
70 private static String formatOutput(Stream<String> stream) {
71 String result = stream.collect(Collectors.joining(Utils.NEW_LINE));
72 if (result.length() > 0) {
73 result += Utils.NEW_LINE;
74 }
75 return result;
76 }
77
78 private static Stream<String> streamGoldFile(Path dir, String name, String suffix) {
79 try {
80 return Files.lines(dir.resolve(name + ".gold." + suffix));
81 } catch (IOException e) {
82 throw new Error(String.format("Can't read golden %s for %s : %s", suffix, name, e), e);
83 }
84 }
85 }
|