| 1 |
#include <pbcopper/cli2/Interface.h> |
| 2 |
|
| 3 |
#include <exception> |
| 4 |
#include <stdexcept> |
| 5 |
#include "pbcopper/cli2/Option.h" |
| 6 |
|
| 7 |
#include <gtest/gtest.h> |
| 8 |
|
| 9 |
using namespace PacBio; |
| 10 |
|
| 11 |
TEST(CLI2_Interface, throws_on_empty_application_name) |
| 12 |
{ |
| 13 |
const auto ShouldThrowSetupError = [](const std::string& name, const std::string& description, |
| 14 |
const std::string& version) { |
| 15 |
try { |
| 16 |
const CLI_v2::Interface i{name, description, version}; |
| 17 |
EXPECT_FALSE("got here"); |
| 18 |
} catch (const std::exception& e) { |
| 19 |
EXPECT_NE(std::string{e.what()}.find("command line interface setup ERROR"), |
| 20 |
std::string::npos); |
| 21 |
} |
| 22 |
}; |
| 23 |
|
| 24 |
ShouldThrowSetupError("", "", ""); |
| 25 |
ShouldThrowSetupError("", "", "version"); |
| 26 |
ShouldThrowSetupError("", "description", ""); |
| 27 |
ShouldThrowSetupError("", "description", "version"); |
| 28 |
} |
| 29 |
|
| 30 |
TEST(CLI2_Interface, throws_on_duplicate_option_name) |
| 31 |
{ |
| 32 |
// clang-format off |
| 33 |
const PacBio::CLI_v2::Option Method |
| 34 |
{ |
| 35 |
R"({ |
| 36 |
"names" : ["m", "method"], |
| 37 |
"description" : "Test", |
| 38 |
"type" : "string", |
| 39 |
"default" : "standard" |
| 40 |
})" |
| 41 |
}; |
| 42 |
const PacBio::CLI_v2::Option Min |
| 43 |
{ |
| 44 |
R"({ |
| 45 |
"names" : ["m"], |
| 46 |
"description" : "Minimum thing", |
| 47 |
"type" : "int", |
| 48 |
"default" : 10 |
| 49 |
})" |
| 50 |
}; |
| 51 |
// clang-format on |
| 52 |
|
| 53 |
CLI_v2::Interface i{"app", "description", "version"}; |
| 54 |
i.AddOption(Method); |
| 55 |
try { |
| 56 |
i.AddOption(Min); |
| 57 |
EXPECT_FALSE("got here"); |
| 58 |
} catch (const std::exception& e) { |
| 59 |
EXPECT_NE(std::string{e.what()}.find("command line interface setup ERROR"), |
| 60 |
std::string::npos); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
TEST(CLI2_Interface, throws_on_duplicate_option_group_name) |
| 65 |
{ |
| 66 |
CLI_v2::Interface i{"app", "description", "version"}; |
| 67 |
try { |
| 68 |
i.AddOptionGroup("group1", {}); |
| 69 |
i.AddOptionGroup("group1", {}); |
| 70 |
EXPECT_FALSE("got here"); |
| 71 |
} catch (const std::exception& e) { |
| 72 |
EXPECT_NE(std::string{e.what()}.find("command line interface setup ERROR"), |
| 73 |
std::string::npos); |
| 74 |
} |
| 75 |
} |