80 }
81
82 protected static class JImageResult {
83 final int exitCode;
84 final String output;
85
86 JImageResult(int exitCode, String output) {
87 this.exitCode = exitCode;
88 this.output = output;
89 }
90
91 JImageResult assertSuccess() { assertTrue(exitCode == 0, output); return this; }
92 JImageResult assertFailure() { assertFalse(exitCode == 0, output); return this; }
93
94 // a helper to ensure the error output doesn't exhibit implementation details
95 JImageResult assertShowsError() {
96 assertTrue(output.contains("Error"),
97 String.format("Output contains error, output=[%s]\n", output));
98 assertFalse(output.contains("Exception"),
99 String.format("Output doesn't contain a stacktrace, output=[%s]\n", output));
100 return this;
101 }
102
103 JImageResult resultChecker(Consumer<JImageResult> r) { r.accept(this); return this; }
104 }
105
106 protected final void runTests() throws Throwable {
107 if (getImagePath() != null) {
108 for (Method m : getClass().getDeclaredMethods()) {
109 if (m.getName().startsWith("test")) {
110 System.out.printf("Invoking %s\n", m.getName());
111 m.invoke(this);
112 }
113 }
114 } else {
115 System.out.println("This is not an image build. Skipping.");
116 }
117 }
118
119 }
120
|
80 }
81
82 protected static class JImageResult {
83 final int exitCode;
84 final String output;
85
86 JImageResult(int exitCode, String output) {
87 this.exitCode = exitCode;
88 this.output = output;
89 }
90
91 JImageResult assertSuccess() { assertTrue(exitCode == 0, output); return this; }
92 JImageResult assertFailure() { assertFalse(exitCode == 0, output); return this; }
93
94 // a helper to ensure the error output doesn't exhibit implementation details
95 JImageResult assertShowsError() {
96 assertTrue(output.contains("Error"),
97 String.format("Output contains error, output=[%s]\n", output));
98 assertFalse(output.contains("Exception"),
99 String.format("Output doesn't contain a stacktrace, output=[%s]\n", output));
100 System.out.print(output);
101 return this;
102 }
103
104 JImageResult resultChecker(Consumer<JImageResult> r) { r.accept(this); return this; }
105 }
106
107 protected final void runTests() throws Throwable {
108 if (getImagePath() != null) {
109 Method beforeTestMethod = getClass().getDeclaredMethod("beforeTest");
110 for (Method m : getClass().getDeclaredMethods()) {
111 if (m.getName().startsWith("test")) {
112 if (beforeTestMethod != null) {
113 System.out.printf("Invoking %s\n", beforeTestMethod.getName());
114 beforeTestMethod.invoke(this);
115 }
116 System.out.printf("Invoking %s\n", m.getName());
117 m.invoke(this);
118 System.out.println();
119 }
120 }
121 } else {
122 System.out.println("This is not an image build. Skipping.");
123 }
124 }
125
126 }
127
|