Skip to content

Commit b6a7267

Browse files
authored
Refactoring some utilities (#153)
* Refactoring some utilities * Update main.cpp * Update main.cpp * Update main.cpp
1 parent 1c0b74f commit b6a7267

File tree

4 files changed

+3
-88
lines changed

4 files changed

+3
-88
lines changed

include/xeus-cpp/xutils.hpp

-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ namespace xcpp
2424
XEUS_CPP_API
2525
void stop_handler(int sig);
2626

27-
XEUS_CPP_API
28-
bool should_print_version(int argc, char* argv[]);
29-
30-
XEUS_CPP_API
31-
std::string extract_filename(int &argc, char* argv[]);
32-
3327
XEUS_CPP_API
3428
interpreter_ptr build_interpreter(int argc, char** argv);
3529

src/main.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <unistd.h>
2020
#endif
2121

22+
#include "xeus/xhelper.hpp"
2223
#include <xeus/xkernel.hpp>
2324
#include <xeus/xkernel_configuration.hpp>
2425

@@ -31,7 +32,7 @@
3132

3233
int main(int argc, char* argv[])
3334
{
34-
if (xcpp::should_print_version(argc, argv))
35+
if (xeus::should_print_version(argc, argv))
3536
{
3637
std::clog << "xcpp " << XEUS_CPP_VERSION << std::endl;
3738
return 0;
@@ -57,10 +58,8 @@ int main(int argc, char* argv[])
5758
#endif
5859
signal(SIGINT, xcpp::stop_handler);
5960

60-
std::string file_name = xcpp::extract_filename(argc, argv);
61-
61+
std::string file_name = xeus::extract_filename(argc, argv);
6262
interpreter_ptr interpreter = xcpp::build_interpreter(argc, argv);
63-
6463
std::unique_ptr<xeus::xcontext> context = xeus::make_zmq_context();
6564

6665
if (!file_name.empty())

src/xutils.cpp

-31
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,6 @@ namespace xcpp
5050
exit(0);
5151
}
5252

53-
bool should_print_version(int argc, char* argv[])
54-
{
55-
for (int i = 0; i < argc; ++i)
56-
{
57-
if (std::string(argv[i]) == "--version")
58-
{
59-
return true;
60-
}
61-
}
62-
return false;
63-
}
64-
65-
std::string extract_filename(int &argc, char* argv[])
66-
{
67-
std::string res = "";
68-
for (int i = 0; i < argc; ++i)
69-
{
70-
if ((std::string(argv[i]) == "-f") && (i + 1 < argc))
71-
{
72-
res = argv[i + 1];
73-
for (int j = i; j < argc - 2; ++j)
74-
{
75-
argv[j] = argv[j + 2];
76-
}
77-
argc -= 2;
78-
break;
79-
}
80-
}
81-
return res;
82-
}
83-
8453
interpreter_ptr build_interpreter(int argc, char** argv)
8554
{
8655
std::vector<const char*> interpreter_argv(argc);

test/test_interpreter.cpp

-47
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,6 @@ TEST_SUITE("is_complete_request")
261261
}
262262
}
263263

264-
TEST_SUITE("extract_filename")
265-
{
266-
TEST_CASE("extract_filename_basic_test")
267-
{
268-
const char* arguments[] = {"argument1", "-f", "filename.txt", "argument4"};
269-
int argc = sizeof(arguments) / sizeof(arguments[0]);
270-
271-
std::string result = xcpp::extract_filename(argc, const_cast<char**>(arguments));
272-
REQUIRE(result == "filename.txt");
273-
REQUIRE(argc == 2);
274-
}
275-
}
276-
277264
TEST_SUITE("trim"){
278265

279266
TEST_CASE("trim_basic_test"){
@@ -314,40 +301,6 @@ TEST_SUITE("trim"){
314301

315302
}
316303

317-
TEST_SUITE("should_print_version")
318-
{
319-
// This test case checks if the function `should_print_version` correctly identifies
320-
// when the "--version" argument is passed. It sets up a scenario where "--version"
321-
// is one of the command line arguments and checks if the function returns true.
322-
TEST_CASE("should_print_version_with_version_arg")
323-
{
324-
char arg1[] = "program_name";
325-
char arg2[] = "--version";
326-
char* argv[] = {arg1, arg2};
327-
int argc = 2;
328-
329-
bool result = xcpp::should_print_version(argc, argv);
330-
331-
REQUIRE(result == true);
332-
}
333-
334-
// This test case checks if the function `should_print_version` correctly identifies
335-
// when the "--version" argument is not passed. It sets up a scenario where "--version"
336-
// is not one of the command line arguments and checks if the function returns false.
337-
TEST_CASE("should_print_version_without_version_arg")
338-
{
339-
char arg1[] = "program_name";
340-
char arg2[] = "-f";
341-
char arg3[] = "filename";
342-
char* argv[] = {arg1, arg2, arg3};
343-
int argc = 3;
344-
345-
bool result = xcpp::should_print_version(argc, argv);
346-
347-
REQUIRE(result == false);
348-
}
349-
}
350-
351304
TEST_SUITE("build_interpreter")
352305
{
353306
// This test case checks if the function `build_interpreter` returns a non-null pointer

0 commit comments

Comments
 (0)