@@ -43,7 +43,7 @@ public JPackageOutputValidator() {
4343 }
4444
4545 public JPackageOutputValidator (JPackageOutputValidator other ) {
46- stdout = other .stdout ;
46+ stream = other .stream ;
4747 match = other .match ;
4848 matchTimestamps = other .matchTimestamps ;
4949 stripTimestamps = other .stripTimestamps ;
@@ -59,7 +59,7 @@ JPackageOutputValidator copy() {
5959 * @return this
6060 */
6161 public JPackageOutputValidator stdout () {
62- stdout = true ;
62+ stream = StdStream . OUT ;
6363 return this ;
6464 }
6565
@@ -68,7 +68,16 @@ public JPackageOutputValidator stdout() {
6868 * @return this
6969 */
7070 public JPackageOutputValidator stderr () {
71- stdout = false ;
71+ stream = StdStream .ERR ;
72+ return this ;
73+ }
74+
75+ /**
76+ * Configures this validator to validate both stdout and stderr.
77+ * @return this
78+ */
79+ public JPackageOutputValidator stdoutAndStderr () {
80+ stream = StdStream .OUT_AND_ERR ;
7281 return this ;
7382 }
7483
@@ -171,7 +180,7 @@ public JPackageOutputValidator add(JPackageOutputValidator other) {
171180 }
172181
173182 public JPackageOutputValidator compose (JPackageOutputValidator other ) {
174- if (stdout != other .stdout ) {
183+ if (stream != other .stream ) {
175184 throw new IllegalArgumentException ();
176185 }
177186 if (match != other .match ) {
@@ -188,7 +197,7 @@ public JPackageOutputValidator compose(JPackageOutputValidator other) {
188197
189198 private Optional <Consumer <Executor .Result >> toResultConsumer (JPackageCommand cmd ) {
190199 return toStringIteratorConsumer (cmd ).map (validator -> {
191- return toResultConsumer (validator , stdout , match , label ());
200+ return toResultConsumer (validator , stream , match , label ());
192201 });
193202 }
194203
@@ -244,7 +253,11 @@ private Optional<Consumer<Iterator<String>>> toStringIteratorConsumer(JPackageCo
244253 }
245254
246255 private String label () {
247- return stdout ? "'stdout'" : "'stderr'" ;
256+ return switch (stream ) {
257+ case OUT -> "'stdout'" ;
258+ case ERR -> "'stderr'" ;
259+ case OUT_AND_ERR -> "'stdout+stderr'" ;
260+ };
248261 }
249262
250263 private Consumer <Iterator <String >> decorate (TKit .TextStreamVerifier validator ) {
@@ -256,17 +269,16 @@ private Consumer<Iterator<String>> decorate(TKit.TextStreamVerifier validator) {
256269 }
257270
258271 private static Consumer <Executor .Result > toResultConsumer (
259- Consumer <Iterator <String >> validator , boolean stdout , boolean match , String label ) {
272+ Consumer <Iterator <String >> validator , StdStream stream , boolean match , String label ) {
260273 Objects .requireNonNull (validator );
261274 Objects .requireNonNull (label );
262275
263276 return result -> {
264- List <String > content ;
265- if (stdout ) {
266- content = result .stdout ();
267- } else {
268- content = result .stderr ();
269- }
277+ List <String > content = switch (stream ) {
278+ case OUT -> result .stdout ();
279+ case ERR -> result .stderr ();
280+ case OUT_AND_ERR -> result .getOutput ();
281+ };
270282
271283 if (match ) {
272284 TKit .trace (String .format ("Checking %s for exact match against defined validators..." , label ));
@@ -371,7 +383,14 @@ public void accept(Iterator<String> it) {
371383 }
372384 }
373385
374- boolean stdout = true ;
386+ private enum StdStream {
387+ OUT ,
388+ ERR ,
389+ OUT_AND_ERR ,
390+ ;
391+ }
392+
393+ StdStream stream = StdStream .OUT ;
375394 boolean match ;
376395 boolean matchTimestamps ;
377396 boolean stripTimestamps ;
0 commit comments