Skip to content

Commit cf46e73

Browse files
committed
test: cover more exception test
1 parent 089cd94 commit cf46e73

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

test/fixtures/bad_file.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[sec1]
2+
3+
no_value

test/tests.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ TEST(INIReader, get_single_value) {
99
INIReader r{"./fixtures/config.ini"};
1010

1111
EXPECT_EQ(r.Get<std::string>("section1", "any"), std::string("1"));
12-
EXPECT_EQ(r.Get<int>("section1", "any"), int(1));
1312
EXPECT_EQ(r.Get<float>("section1", "any"), float(1.0));
1413
EXPECT_EQ(r.Get<double>("section1", "any"), double(1.0));
1514
EXPECT_EQ(r.Get<long>("section1", "any"), long(1));
@@ -69,11 +68,17 @@ TEST(INIReader, get_vector_with_default) {
6968

7069
TEST(INIReader, exception) {
7170

72-
// file not found
73-
EXPECT_THROW(INIReader{"QQ"}, std::runtime_error);
71+
72+
EXPECT_THROW(INIReader{"QQ"}, std::runtime_error); // file not found
73+
EXPECT_THROW(INIReader{"./fixtures/bad_file.ini"}, std::runtime_error); // parse error
7474

7575
INIReader r{"./fixtures/config.ini"};
7676

77+
// key not found error
78+
EXPECT_THROW(r.Get<int>("section1", "not_exist"), std::runtime_error);
79+
EXPECT_THROW(r.GetVector<int>("section1", "not_exist"), std::runtime_error);
80+
81+
// parse error
7782
EXPECT_THROW(r.Get<int>("section1", "not_int"), std::runtime_error);
7883
EXPECT_THROW(r.GetVector<int>("section1", "not_int_arr"), std::runtime_error);
7984

0 commit comments

Comments
 (0)