diff --git a/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp b/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp index d65732b864..efe286508f 100644 --- a/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp +++ b/src/cpp/lpnamer/main/ProblemGenerationExeOptions.cpp @@ -23,6 +23,11 @@ ProblemGenerationExeOptions::ProblemGenerationExeOptions() void ProblemGenerationExeOptions::Parse(unsigned int argc, const char *const *argv) { OptionsParser::Parse(argc, argv); + if (XpansionOutputDir().empty() && ArchivePath().empty()) { + auto log_location = LOGLOCATION; + auto msg = "Both output directory and archive path are empty"; + throw ProblemGenerationOptions::MissingParameters(msg, log_location); + } } std::filesystem::path ProblemGenerationExeOptions::deduceArchivePathIfEmpty( @@ -57,8 +62,4 @@ std::filesystem::path ProblemGenerationExeOptions::deduceXpansionDirIfEmpty( return deduced_dir; } return xpansion_output_dir; -} - -ProblemGenerationExeOptions::MismatchedParameters::MismatchedParameters( - const std::string& err_message, const std::string& log_location) - : XpansionError(err_message, log_location) {} \ No newline at end of file +} \ No newline at end of file diff --git a/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h b/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h index e861cf8779..3fb34b841f 100644 --- a/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h +++ b/src/cpp/lpnamer/main/include/ProblemGenerationOptions.h @@ -30,6 +30,16 @@ class ProblemGenerationOptions { public: explicit MismatchedParameters(const std::string& err_message, - const std::string& log_location); + const std::string& log_location) + : XpansionError(err_message, log_location) {} }; -}; + + class MissingParameters : public LogUtils::XpansionError { + using LogUtils::XpansionError::XpansionError; + + public: + explicit MissingParameters(const std::string& err_message, + const std::string& log_location) + : XpansionError(err_message, log_location) {} + }; +}; \ No newline at end of file diff --git a/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp b/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp index 207caa1d75..eea39cf736 100644 --- a/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp +++ b/tests/cpp/lp_namer/ProblemGenerationExeOptionsTest.cpp @@ -39,17 +39,6 @@ class ProblemGenerationSpyAndMock : public ProblemGeneration { bool unnamed_problems_; }; -TEST_F(ProblemGenerationExeOptionsTest, WithoutArchiveOption) { - char argv = 'c'; - char* pargv = &argv; - char** ppargv = &pargv; - try { - problem_generation_options_parser_.Parse(1, ppargv); - } catch (const std::exception& e) { - EXPECT_EQ(e.what(), - std::string("the option '--archive' is required but missing")); - } -} TEST_F(ProblemGenerationExeOptionsTest, WithoutOutputOption) { const char argv0[] = "lp_namer.exe"; const char argv1[] = "--archive"; @@ -187,4 +176,17 @@ TEST_F( std::ifstream logfile(output_path / "lp" / "ProblemGenerationLog.txt"); EXPECT_TRUE(Constains( logfile, "Archive path is missing and output path does not contains")); +} + +TEST_F(ProblemGenerationExeOptionsTest, + OutputAndArchiveParameters_ErrorIfBothArchiveAndOutputAreMissing) { + auto test_root = + std::filesystem::temp_directory_path() / std::tmpnam(nullptr); + + const char argv0[] = "lp.exe "; + + std::vector ppargv = {argv0}; + + EXPECT_THROW(problem_generation_options_parser_.Parse(1, ppargv.data()), + ProblemGenerationOptions::MissingParameters); } \ No newline at end of file