Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit 18f4b31

Browse files
committed
add test for config files
1 parent c0c7bd5 commit 18f4b31

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ before_install:
130130
script:
131131
- mkdir build
132132
- cd build
133-
- cmake .. && make && ./example/popl_example && ./test/popl_test
133+
- cmake .. && make && ./example/popl_example && cd test && ./popl_test

test/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
66
# Make test executable
77
set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test_main.cpp)
88
add_executable(popl_test ${TEST_SOURCES})
9+
configure_file(test.conf ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
910
target_link_libraries(popl_test Catch)
10-

test/test.conf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
## test configuration file
3+
4+
[section]
5+
integer = 23
6+

test/test_main.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using namespace popl;
1414
using namespace std;
1515

16-
TEST_CASE("Main test")
16+
TEST_CASE("command line")
1717
{
1818
OptionParser op("Allowed options");
1919
std::vector<const char*> args = {"popl", "-h"};
@@ -34,3 +34,23 @@ TEST_CASE("Main test")
3434
cerr << "Exception: " << e.what() << "\n";
3535
}
3636
}
37+
38+
39+
TEST_CASE("config file")
40+
{
41+
OptionParser op("Allowed options");
42+
auto int_option = op.add<Value<int>>("i", "section.integer", "test for int value", 42);
43+
44+
try
45+
{
46+
op.parse("test.conf");
47+
REQUIRE(int_option->is_set() == true);
48+
REQUIRE(int_option->count() == 1);
49+
REQUIRE(int_option->value() == 23);
50+
}
51+
catch (const std::exception& e)
52+
{
53+
cerr << "Exception: " << e.what() << "\n";
54+
}
55+
}
56+

0 commit comments

Comments
 (0)