Skip to content

[root.exe] Use non-zero exit status when invalid arguments are passed #19196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/rint/src/TRint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ TRint::TRint(const char *appClassName, Int_t *argc, char **argv, void *options,
std::cerr << "root: unrecognized option '" << argv[n] << "'\n";
}
std::cerr << "Try 'root --help' for more information.\n";
TApplication::Terminate(0);
TApplication::Terminate(2);
}

fNcmd = 0;
Expand Down
28 changes: 0 additions & 28 deletions core/rint/test/TRintTests.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,6 @@
using testing::internal::CaptureStderr;
using testing::internal::GetCapturedStderr;

TEST(TRint, ExitOnUnknownArgs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test removed?

Copy link
Member Author

@hageboeck hageboeck Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I cannot make it pass. Now that TApplication exits with status 2, the end of this test cannot be reached. It will always fail.

It is replaced by

 add_test(NAME root_exitStatus COMMAND $<TARGET_FILE:root.exe> "-e invalid")
 set_property(TEST root_exitStatus PROPERTY WILL_FAIL TRUE)

which admittedly doesn't test the error message, but it does test that root exits with != 0

{
// Create array of options.
// We need to create it as a dynamic array for the following reasons:
// - TRint constructor accepts a char** so we construct directly that type
// - TRint will modify this array, removing recognized options and leaving
// only unrecognized ones, so we can't create an std::vector and pass its
// data to TRint directly.
int argc{4};
char e1[]{"-q"};
char e2[]{"-z"};
char e3[]{"--nonexistingoption"};
char e4[]{"-b"};
char *argv[]{e1, e2, e3, e4};

CaptureStderr();
// Unrecognized options will be printed to stderr
TRint app{"App", &argc, argv, /*options*/ nullptr, /*numOptions*/ 0, /*noLogo*/ kTRUE, /*exitOnUnknownArgs*/
kTRUE};
std::string trinterr = GetCapturedStderr();

const std::string expected{"root: unrecognized option '-z'\n"
"root: unrecognized option '--nonexistingoption'\n"
"Try 'root --help' for more information.\n"};

EXPECT_EQ(trinterr, expected);
}

TEST(TRint, KeepUnknownArgs)
{
// Create array of options.
Expand Down
3 changes: 3 additions & 0 deletions roottest/root/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ ROOTTEST_ADD_TEST(execStatusBitsCheck
OUTCNV ../html/MakeIndex_convert.sh
OUTREF execStatusBitsCheck.ref
)

add_test(NAME root_exitStatus COMMAND $<TARGET_FILE:root.exe> "-e invalid")
set_property(TEST root_exitStatus PROPERTY WILL_FAIL TRUE)
Loading