118 *
119 * CDSTestUtils.run(args)
120 * .assertNormalExit(output -> output.shouldNotContain("this should not be printed")
121 * .assertNormalExit("should have this", "should have that");
122 *
123 * 4. [Rare use case] if a test sometimes exit normally, and sometimes abnormally:
124 *
125 * CDSTestUtils.run(args)
126 * .ifNormalExit("ths string is printed when exiting with 0")
127 * .ifAbNormalExit("ths string is printed when exiting with 1");
128 *
129 * NOTE: you usually don't want to write your test case like this -- it should always
130 * exit with the same exit code. (But I kept this API because some existing test cases
131 * behave this way -- need to revisit).
132 */
133 public static class Result {
134 private final OutputAnalyzer output;
135 private final CDSOptions options;
136 private final boolean hasNormalExit;
137 private final String CDS_DISABLED = "warning: CDS is disabled when the";
138
139 public Result(CDSOptions opts, OutputAnalyzer out) throws Exception {
140 checkMappingFailure(out);
141 this.options = opts;
142 this.output = out;
143 hasNormalExit = (output.getExitValue() == 0);
144
145 if (hasNormalExit) {
146 if ("on".equals(options.xShareMode) &&
147 output.getStderr().contains("java version") &&
148 !output.getStderr().contains(CDS_DISABLED)) {
149 // "-showversion" is always passed in the command-line by the execXXX methods.
150 // During normal exit, we require that the VM to show that sharing was enabled.
151 output.shouldContain("sharing");
152 }
153 }
154 }
155
156 public Result assertNormalExit(Checker checker) throws Exception {
157 checker.check(output);
158 output.shouldHaveExitValue(0);
|
118 *
119 * CDSTestUtils.run(args)
120 * .assertNormalExit(output -> output.shouldNotContain("this should not be printed")
121 * .assertNormalExit("should have this", "should have that");
122 *
123 * 4. [Rare use case] if a test sometimes exit normally, and sometimes abnormally:
124 *
125 * CDSTestUtils.run(args)
126 * .ifNormalExit("ths string is printed when exiting with 0")
127 * .ifAbNormalExit("ths string is printed when exiting with 1");
128 *
129 * NOTE: you usually don't want to write your test case like this -- it should always
130 * exit with the same exit code. (But I kept this API because some existing test cases
131 * behave this way -- need to revisit).
132 */
133 public static class Result {
134 private final OutputAnalyzer output;
135 private final CDSOptions options;
136 private final boolean hasNormalExit;
137 private final String CDS_DISABLED = "warning: CDS is disabled when the";
138 public Result(CDSOptions opts, OutputAnalyzer out) throws Exception {
139 checkMappingFailure(out);
140 this.options = opts;
141 this.output = out;
142 hasNormalExit = (output.getExitValue() == 0);
143
144 if (hasNormalExit) {
145 if ("on".equals(options.xShareMode) &&
146 output.getStderr().contains("java version") &&
147 !output.getStderr().contains(CDS_DISABLED)) {
148 // "-showversion" is always passed in the command-line by the execXXX methods.
149 // During normal exit, we require that the VM to show that sharing was enabled.
150 output.shouldContain("sharing");
151 }
152 }
153 }
154
155 public Result assertNormalExit(Checker checker) throws Exception {
156 checker.check(output);
157 output.shouldHaveExitValue(0);
|