Skip to content

Commit

Permalink
Added some unit tests for config files not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwfncar committed Oct 25, 2023
1 parent ad21ac1 commit 0e3a4e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/micm/configure/camp_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ namespace micm
/// @return True for successful parsing
ConfigParseStatus Parse(const std::filesystem::path& config_file)
{
// Look for CAMP config file
if (!std::filesystem::exists(config_file))
{
std::string msg = "Invalid CAMP configuration file path";
Expand All @@ -122,9 +123,10 @@ namespace micm
// Extract configuration dir from configuration file path
std::filesystem::path config_dir = config_file.parent_path();

// The CAMP file list
std::vector<std::string> camp_files;

// Look for CAMP config file
// Load the CAMP file list JSON
json camp_data = json::parse(std::ifstream(config_file));
if (!camp_data.contains(CAMP_FILES))
return ConfigParseStatus::CAMPFilesSectionNotFound;
Expand All @@ -136,12 +138,13 @@ namespace micm
{
camp_files.push_back(camp_file);
}
// Error return here if CAMP files list has a missing file?
}

// No config files found
if (camp_files.size() < 1)
{
std::string msg = "No config files found";
std::string msg = "No CAMP list files found";
std::cerr << msg << std::endl;
return ConfigParseStatus::NoConfigFilesFound;
}
Expand Down
14 changes: 14 additions & 0 deletions test/unit/configure/test_camp_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

#include <micm/configure/camp_config.hpp>

TEST(SolverConfig, DetectsInvalidConfigFile)
{
micm::SolverConfig solverConfig{};
auto status = solverConfig.ReadAndParse("not_a_config_file");
EXPECT_EQ(micm::ConfigParseStatus::InvalidCAMPFilePath, status);
}

TEST(SolverConfig, NoConfigFilesFound)
{
micm::SolverConfig solverConfig{};
auto status = solverConfig.ReadAndParse("./unit_configs/CAMP/camp_invalid/config.json");
EXPECT_EQ(micm::ConfigParseStatus::NoConfigFilesFound, status);
}

TEST(SolverConfig, ReadAndParseCAMPFiles)
{
micm::SolverConfig solverConfig{};
Expand Down

0 comments on commit 0e3a4e4

Please sign in to comment.