Skip to content

Commit

Permalink
Refactoring some utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
anutosh491 committed Jul 8, 2024
1 parent 4745f72 commit 953e8aa
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 86 deletions.
6 changes: 0 additions & 6 deletions include/xeus-cpp/xutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ namespace xcpp
XEUS_CPP_API
void stop_handler(int sig);

XEUS_CPP_API
bool should_print_version(int argc, char* argv[]);

XEUS_CPP_API
std::string extract_filename(int &argc, char* argv[]);

XEUS_CPP_API
interpreter_ptr build_interpreter(int argc, char** argv);

Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <xeus/xkernel.hpp>
#include <xeus/xkernel_configuration.hpp>
#include "xeus/xhelper.hpp"

#include "xeus-zmq/xzmq_context.hpp"
#include <xeus-zmq/xserver_zmq.hpp>
Expand All @@ -32,7 +33,7 @@

int main(int argc, char* argv[])
{
if (xcpp::should_print_version(argc, argv))
if (xeus::should_print_version(argc, argv))
{
std::clog << "xcpp " << XEUS_CPP_VERSION << std::endl;
return 0;
Expand All @@ -58,7 +59,7 @@ int main(int argc, char* argv[])
#endif
signal(SIGINT, xcpp::stop_handler);

std::string file_name = xcpp::extract_filename(argc, argv);
std::string file_name = xeus::extract_filename(argc, argv);

interpreter_ptr interpreter = xcpp::build_interpreter(argc, argv);

Expand Down
31 changes: 0 additions & 31 deletions src/xutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,6 @@ namespace xcpp
exit(0);
}

bool should_print_version(int argc, char* argv[])
{
for (int i = 0; i < argc; ++i)
{
if (std::string(argv[i]) == "--version")
{
return true;
}
}
return false;
}

std::string extract_filename(int &argc, char* argv[])
{
std::string res = "";
for (int i = 0; i < argc; ++i)
{
if ((std::string(argv[i]) == "-f") && (i + 1 < argc))
{
res = argv[i + 1];
for (int j = i; j < argc - 2; ++j)
{
argv[j] = argv[j + 2];
}
argc -= 2;
break;
}
}
return res;
}

interpreter_ptr build_interpreter(int argc, char** argv)
{
std::vector<const char*> interpreter_argv(argc);
Expand Down
47 changes: 0 additions & 47 deletions test/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,19 +260,6 @@ TEST_SUITE("is_complete_request")
}
}

TEST_SUITE("extract_filename")
{
TEST_CASE("extract_filename_basic_test")
{
const char* arguments[] = {"argument1", "-f", "filename.txt", "argument4"};
int argc = sizeof(arguments) / sizeof(arguments[0]);

std::string result = xcpp::extract_filename(argc, const_cast<char**>(arguments));
REQUIRE(result == "filename.txt");
REQUIRE(argc == 2);
}
}

TEST_SUITE("trim"){

TEST_CASE("trim_basic_test"){
Expand Down Expand Up @@ -313,40 +300,6 @@ TEST_SUITE("trim"){

}

TEST_SUITE("should_print_version")
{
// This test case checks if the function `should_print_version` correctly identifies
// when the "--version" argument is passed. It sets up a scenario where "--version"
// is one of the command line arguments and checks if the function returns true.
TEST_CASE("should_print_version_with_version_arg")
{
char arg1[] = "program_name";
char arg2[] = "--version";
char* argv[] = {arg1, arg2};
int argc = 2;

bool result = xcpp::should_print_version(argc, argv);

REQUIRE(result == true);
}

// This test case checks if the function `should_print_version` correctly identifies
// when the "--version" argument is not passed. It sets up a scenario where "--version"
// is not one of the command line arguments and checks if the function returns false.
TEST_CASE("should_print_version_without_version_arg")
{
char arg1[] = "program_name";
char arg2[] = "-f";
char arg3[] = "filename";
char* argv[] = {arg1, arg2, arg3};
int argc = 3;

bool result = xcpp::should_print_version(argc, argv);

REQUIRE(result == false);
}
}

TEST_SUITE("build_interpreter")
{
// This test case checks if the function `build_interpreter` returns a non-null pointer
Expand Down

0 comments on commit 953e8aa

Please sign in to comment.