Skip to content

Commit c562025

Browse files
committed
Add unit test of prefix_in_list
To demonstrate that the refactored version works as expected.
1 parent 7855bad commit c562025

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

unit/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ target_link_libraries(
5151
testing-utils
5252
ansi-c
5353
solvers
54+
goto-cc-lib
5455
goto-checker
5556
goto-programs
5657
goto-instrument-lib

unit/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SRC += analyses/ai/ai.cpp \
1919
big-int/big-int.cpp \
2020
compound_block_locations.cpp \
2121
get_goto_model_from_c_test.cpp \
22+
goto-cc/armcc_cmdline.cpp \
2223
goto-checker/report_util/is_property_less_than.cpp \
2324
goto-instrument/cover_instrument.cpp \
2425
goto-instrument/cover/cover_only.cpp \
@@ -190,6 +191,7 @@ CPROVER_LIBS =../src/ansi-c/ansi-c$(LIBEXT) \
190191
../src/linking/linking$(LIBEXT) \
191192
../src/util/util$(LIBEXT) \
192193
../src/big-int/big-int$(LIBEXT) \
194+
../src/goto-cc/goto-cc$(LIBEXT) \
193195
../src/goto-checker/goto-checker$(LIBEXT) \
194196
../src/goto-programs/goto-programs$(LIBEXT) \
195197
../src/pointer-analysis/pointer-analysis$(LIBEXT) \

unit/goto-cc/armcc_cmdline.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2020 Diffblue Limited. All Rights Reserved.
2+
3+
#include <testing-utils/use_catch.h>
4+
5+
#include <util/optional.h>
6+
7+
#include <string>
8+
#include <vector>
9+
10+
optionalt<std::string>
11+
prefix_in_list(const std::string &option, const std::vector<std::string> &list);
12+
13+
static const std::vector<std::string> test_list{"spam", "eggs", "and", "ham"};
14+
15+
TEST_CASE("prefix_in_list exact match", "[core][armcc_cmdline][prefix_in_list]")
16+
{
17+
REQUIRE(*prefix_in_list("spam", test_list) == "spam");
18+
REQUIRE(*prefix_in_list("ham", test_list) == "ham");
19+
}
20+
21+
TEST_CASE(
22+
"prefix_in_list match prefix",
23+
"[core][armcc_cmdline][prefix_in_list]")
24+
{
25+
REQUIRE(*prefix_in_list("sp", test_list) == "spam");
26+
REQUIRE(*prefix_in_list("ha", test_list) == "ham");
27+
}
28+
29+
TEST_CASE("prefix_in_list unmatched", "[core][armcc_cmdline][prefix_in_list]")
30+
{
31+
REQUIRE_FALSE(prefix_in_list("foobar", test_list));
32+
}

0 commit comments

Comments
 (0)