Skip to content
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

Remove exit() from emulator #275

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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 src/chimera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int run(int argc, const char **argv)
std::cout << "Chimera " << CHIMERA_MAJOR_VERSION << "."
<< CHIMERA_MINOR_VERSION << "." << CHIMERA_PATCH_VERSION
<< "\n\n";
exit(0);
return 0;
}
}

Expand Down
30 changes: 10 additions & 20 deletions test/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Emulator::Emulator()
}

//==============================================================================
void Emulator::Run()
bool Emulator::Run()
{
std::vector<std::string> args;
args.push_back("");
Expand Down Expand Up @@ -92,62 +92,52 @@ void Emulator::Run()
}

std::vector<const char *> argv = convertArgs(args);
chimera::run(static_cast<int>(argv.size()), argv.data());

exit(0);
return chimera::run(static_cast<int>(argv.size()), argv.data()) == 0;
}

//==============================================================================
void Emulator::Run(const std::string &args)
bool Emulator::Run(const std::string &args)
{
std::vector<std::string> args_splits = split(args, " ");
std::vector<const char *> argv;
argv.push_back("");
for (auto &arg : args_splits)
argv.push_back(arg.data());

chimera::run(static_cast<int>(argv.size()), argv.data());

exit(0);
return chimera::run(static_cast<int>(argv.size()), argv.data()) == 0;
}

//==============================================================================
void Emulator::RunHelp()
bool Emulator::RunHelp()
{
int argc = 2;
std::vector<const char *> argv;
argv.push_back("");
argv.push_back("--help");

chimera::run(argc, argv.data());

exit(0);
return chimera::run(argc, argv.data()) == 0;
}

//==============================================================================
void Emulator::RunHelpList()
bool Emulator::RunHelpList()
{
int argc = 2;
std::vector<const char *> argv;
argv.push_back("");
argv.push_back("--help-list");

chimera::run(argc, argv.data());

exit(0);
return chimera::run(argc, argv.data()) == 0;
}

//==============================================================================
void Emulator::RunVersion()
bool Emulator::RunVersion()
{
int argc = 2;
std::vector<const char *> argv;
argv.push_back("");
argv.push_back("--version");

chimera::run(argc, argv.data());

exit(0);
return chimera::run(argc, argv.data()) == 0;
}

//==============================================================================
Expand Down
10 changes: 5 additions & 5 deletions test/emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class Emulator
public:
Emulator();

void Run();
bool Run();

static void Run(const std::string &args);
static bool Run(const std::string &args);

static void RunHelp();
static void RunHelpList();
static void RunVersion();
static bool RunHelp();
static bool RunHelpList();
static bool RunVersion();

void SetSource(const std::string &filename);
void SetSources(const std::vector<std::string> &filenames);
Expand Down
28 changes: 10 additions & 18 deletions test/test_emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ TEST(Emulator, GeneralOptions)
{
testing::internal::CaptureStdout();

// EXPECT_EXIT is used to continue running the rest of the tests. This is
// because ClangTool exits right after it prints help. Note that this makes
// the breakpoints don't work in executing the test s in EXPECT_EXIT.
EXPECT_EXIT(Emulator::RunHelp(), ::testing::ExitedWithCode(0), ".*");
EXPECT_EXIT(Emulator::Run("--help"), ::testing::ExitedWithCode(0), ".*");

EXPECT_EXIT(Emulator::RunHelpList(), ::testing::ExitedWithCode(0), ".*");
EXPECT_EXIT(Emulator::Run("--help-list"), ::testing::ExitedWithCode(0),
".*");

EXPECT_EXIT(Emulator::RunVersion(), ::testing::ExitedWithCode(0), ".*");
EXPECT_EXIT(Emulator::Run("--version"), ::testing::ExitedWithCode(0), ".*");
EXPECT_TRUE(Emulator::RunVersion());
EXPECT_TRUE(Emulator::Run("--version"));

std::string output = testing::internal::GetCapturedStdout();
}
Expand All @@ -30,9 +32,7 @@ TEST(Emulator, 01_Function)
e.SetConfigurationFile("01_function/function_pybind11.yaml");
e.SetBinding("pybind11");

// EXPECT_EXIT is necessary to continue to run subsequent tests, but it
// doesn't stop at the breakpoints. For debugging use e.Run() instead.
EXPECT_EXIT(e.Run(), ::testing::ExitedWithCode(0), ".*");
EXPECT_TRUE(e.Run());
}

//==============================================================================
Expand All @@ -43,9 +43,7 @@ TEST(Emulator, 02_Class)
e.SetConfigurationFile("02_class/class.yaml");
e.SetBinding("pybind11");

// EXPECT_EXIT is necessary to continue to run subsequent tests, but it
// doesn't stop at the breakpoints. For debugging use e.Run() instead.
EXPECT_EXIT(e.Run(), ::testing::ExitedWithCode(0), ".*");
EXPECT_TRUE(e.Run());
}

//==============================================================================
Expand All @@ -56,9 +54,7 @@ TEST(Emulator, 04_Enumeration)
e.SetConfigurationFile("04_enumeration/enumeration.yaml");
e.SetBinding("pybind11");

// EXPECT_EXIT is necessary to continue to run subsequent tests, but it
// doesn't stop at the breakpoints. For debugging use e.Run() instead.
EXPECT_EXIT(e.Run(), ::testing::ExitedWithCode(0), ".*");
EXPECT_TRUE(e.Run());
}

//==============================================================================
Expand All @@ -69,9 +65,7 @@ TEST(Emulator, 20_Eigen)
e.SetConfigurationFile("20_eigen/eigen_pybind11.yaml");
e.SetBinding("pybind11");

// EXPECT_EXIT is necessary to continue to run subsequent tests, but it
// doesn't stop at the breakpoints. For debugging use e.Run() instead.
EXPECT_EXIT(e.Run(), ::testing::ExitedWithCode(0), ".*");
EXPECT_TRUE(e.Run());
}

//==============================================================================
Expand All @@ -86,7 +80,5 @@ TEST(Emulator, issue228)
"issue228_template_type_alias_pybind11.yaml");
e.SetBinding("pybind11");

// EXPECT_EXIT is necessary to continue to run subsequent tests, but it
// doesn't stop at the breakpoints. For debugging use e.Run() instead.
EXPECT_EXIT(e.Run(), ::testing::ExitedWithCode(0), ".*");
EXPECT_TRUE(e.Run());
}