File tree Expand file tree Collapse file tree 6 files changed +60
-36
lines changed
documentation/src/docs/asciidoc/user-guide
junit-platform-console/src/main/java/org/junit/platform/console/command Expand file tree Collapse file tree 6 files changed +60
-36
lines changed Original file line number Diff line number Diff line change @@ -748,10 +748,12 @@ include::{consoleLauncherDiscoverOptionsFile}[]
748748===== Executing tests
749749
750750.Exit Code
751- NOTE: The `{ConsoleLauncher}` exits with a status code of `1` if any containers or tests
752- failed. If no tests are discovered and the `--fail-if-no-tests` command-line option is
753- supplied, the `ConsoleLauncher` exits with a status code of `2`. Otherwise, the exit code
754- is `0`.
751+ NOTE: On successful runs, the `{ConsoleLauncher}` exits with a status code of `0`.
752+ All non-zero codes indicate an error of some sort. For example, status code `1`
753+ is returned if any containers or tests failed. If no tests are discovered and the
754+ `--fail-if-no-tests` command-line option is supplied, the `ConsoleLauncher` exits
755+ with a status code of `2`. Unexpected or invalid user input yields a status code
756+ of `3`. An exit code of `-1` indicates an unspecified error condition.
755757
756758----
757759include::{consoleLauncherExecuteOptionsFile}[]
Original file line number Diff line number Diff line change @@ -59,14 +59,14 @@ static CommandLine initialize(CommandLine commandLine) {
5959 return commandLine //
6060 .setParameterExceptionHandler ((ex , args ) -> {
6161 defaultParameterExceptionHandler .handleParseException (ex , args );
62- return CommandResult . FAILURE ;
62+ return ExitCode . ANY_ERROR ;
6363 }) //
6464 .setExecutionExceptionHandler ((ex , cmd , __ ) -> {
6565 commandLine .getErr ().println (cmd .getColorScheme ().richStackTraceString (ex ));
6666 commandLine .getErr ().println ();
6767 commandLine .getErr ().flush ();
6868 cmd .usage (commandLine .getOut ());
69- return CommandResult . FAILURE ;
69+ return ExitCode . ANY_ERROR ;
7070 }) //
7171 .setCaseInsensitiveEnumValuesAllowed (true ) //
7272 .setAtFileCommentChar (null );
Original file line number Diff line number Diff line change 2222 */
2323@ API (status = INTERNAL , since = "1.10" )
2424public class CommandResult <T > {
25-
26- /**
27- * Exit code indicating successful execution.
28- */
29- public static final int SUCCESS = 0 ;
30-
31- /**
32- * Exit code indicating any failure(s).
33- */
34- protected static final int FAILURE = -1 ;
35-
3625 public static <T > CommandResult <T > success () {
37- return create (SUCCESS , null );
38- }
39-
40- public static <T > CommandResult <T > failure () {
41- return create (FAILURE , null );
26+ return create (ExitCode .SUCCESS , null );
4227 }
4328
4429 public static <T > CommandResult <T > create (int exitCode , @ Nullable T value ) {
Original file line number Diff line number Diff line change 1010
1111package org .junit .platform .console .command ;
1212
13- import static org .junit .platform .console .command .CommandResult .SUCCESS ;
13+ import static org .junit .platform .console .command .ExitCode .NO_TESTS_FOUND ;
14+ import static org .junit .platform .console .command .ExitCode .SUCCESS ;
15+ import static org .junit .platform .console .command .ExitCode .TEST_FAILED ;
1416
1517import java .io .PrintWriter ;
1618import java .nio .file .Path ;
3436 description = "Execute tests" //
3537)
3638class ExecuteTestsCommand extends BaseCommand <TestExecutionSummary > implements CommandLine .IExitCodeGenerator {
37-
38- /**
39- * Exit code indicating test failure(s)
40- */
41- private static final int TEST_FAILED = 1 ;
42-
43- /**
44- * Exit code indicating no tests found
45- */
46- private static final int NO_TESTS_FOUND = 2 ;
47-
4839 private final ConsoleTestExecutor .Factory consoleTestExecutorFactory ;
4940
5041 @ Mixin
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2015-2025 the original author or authors.
3+ *
4+ * All rights reserved. This program and the accompanying materials are
5+ * made available under the terms of the Eclipse Public License v2.0 which
6+ * accompanies this distribution and is available at
7+ *
8+ * https://www.eclipse.org/legal/epl-v20.html
9+ */
10+
11+ package org .junit .platform .console .command ;
12+
13+ /**
14+ * Well-known exit codes of the {@code junit} tool.
15+ *
16+ * @since 6.0.1
17+ */
18+ final class ExitCode {
19+ /**
20+ * Exit code indicating a successful tool run.
21+ */
22+ public static final int SUCCESS = 0 ;
23+
24+ /**
25+ * Exit code indicating an unsuccessful run.
26+ */
27+ public static final int ANY_ERROR = -1 ;
28+
29+ /**
30+ * Exit code indicating test failure(s).
31+ */
32+ public static final int TEST_FAILED = 1 ;
33+
34+ /**
35+ * Exit code indicating no tests found.
36+ */
37+ public static final int NO_TESTS_FOUND = 2 ;
38+
39+ /**
40+ * Exit code indicating invalid user input.
41+ */
42+ public static final int INVALID_INPUT = 3 ;
43+
44+ private ExitCode () {
45+ }
46+ }
Original file line number Diff line number Diff line change 3939 footer = "For more information, please refer to the JUnit User Guide at%n" //
4040 + "@|underline https://docs.junit.org/${junit.docs.version}/user-guide/|@" , //
4141 scope = CommandLine .ScopeType .INHERIT , //
42- exitCodeOnInvalidInput = CommandResult . FAILURE , //
43- exitCodeOnExecutionException = CommandResult . FAILURE , //
42+ exitCodeOnInvalidInput = ExitCode . INVALID_INPUT , //
43+ exitCodeOnExecutionException = ExitCode . ANY_ERROR , //
4444 versionProvider = ManifestVersionProvider .class //
4545)
4646class MainCommand implements Runnable , IExitCodeGenerator {
You can’t perform that action at this time.
0 commit comments