Skip to content

Commit 554d190

Browse files
committed
Convert unit tests to Catch framework and fix compilation issues
We had some pre-Catch-era unit tests still lying around unmaintained and unused. Alas, they wouldn't even compile anymore. Compilation issues are now fixed and they are embedded in the Catch framework. Fixes: #879
1 parent 4fe3ade commit 554d190

File tree

17 files changed

+882
-666
lines changed

17 files changed

+882
-666
lines changed

unit/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ else()
4848
endif()
4949

5050
list(REMOVE_ITEM sources
51-
# Don't build
52-
${CMAKE_CURRENT_SOURCE_DIR}/elf_reader.cpp
53-
${CMAKE_CURRENT_SOURCE_DIR}/smt2_parser.cpp
54-
${CMAKE_CURRENT_SOURCE_DIR}/json.cpp
55-
${CMAKE_CURRENT_SOURCE_DIR}/cpp_parser.cpp
56-
${CMAKE_CURRENT_SOURCE_DIR}/osx_fat_reader.cpp
57-
${CMAKE_CURRENT_SOURCE_DIR}/wp.cpp
58-
${CMAKE_CURRENT_SOURCE_DIR}/cpp_scanner.cpp
59-
${CMAKE_CURRENT_SOURCE_DIR}/ieee_float.cpp
60-
6151
# Will be built into a separate library and linked
6252
${testing_utils}
6353

unit/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ SRC += analyses/ai/ai.cpp \
5353
ansi-c/type2name.cpp \
5454
ansi-c/c_typecheck_base.cpp \
5555
big-int/big-int.cpp \
56+
cpp/cpp_parser.cpp \
57+
cpp/cpp_scanner.cpp \
5658
compound_block_locations.cpp \
5759
get_goto_model_from_c_test.cpp \
5860
goto-cc/armcc_cmdline.cpp \
@@ -61,6 +63,7 @@ SRC += analyses/ai/ai.cpp \
6163
goto-instrument/cover_instrument.cpp \
6264
goto-instrument/cover/cover_only.cpp \
6365
goto-synthesizer/expr_enumerator/expr_enumerator.cpp \
66+
goto-programs/elf_reader.cpp \
6467
goto-programs/goto_program_assume.cpp \
6568
goto-programs/goto_program_dead.cpp \
6669
goto-programs/goto_program_declaration.cpp \
@@ -77,6 +80,7 @@ SRC += analyses/ai/ai.cpp \
7780
goto-programs/restrict_function_pointers.cpp \
7881
goto-programs/structured_trace_util.cpp \
7982
goto-programs/remove_returns.cpp \
83+
goto-programs/wp.cpp \
8084
goto-programs/xml_expr.cpp \
8185
goto-symex/apply_condition.cpp \
8286
goto-symex/complexity_limiter.cpp \
@@ -110,6 +114,7 @@ SRC += analyses/ai/ai.cpp \
110114
solvers/sat/satcheck_cadical.cpp \
111115
solvers/sat/satcheck_minisat2.cpp \
112116
solvers/smt2/smt2_conv.cpp \
117+
solvers/smt2/smt2_parser.cpp \
113118
solvers/smt2/smt2irep.cpp \
114119
solvers/smt2_incremental/ast/smt_commands.cpp \
115120
solvers/smt2_incremental/ast/smt_index.cpp \
@@ -173,6 +178,7 @@ SRC += analyses/ai/ai.cpp \
173178
util/irep.cpp \
174179
util/irep_sharing.cpp \
175180
util/invariant.cpp \
181+
util/json.cpp \
176182
util/json_array.cpp \
177183
util/json_object.cpp \
178184
util/lazy.cpp \

unit/cpp/cpp_parser.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for cpp_parser
4+
5+
Author: Daniel Kroening
6+
7+
\*******************************************************************/
8+
9+
#include <util/config.h>
10+
#include <util/tempfile.h>
11+
12+
#include <cpp/cpp_parser.h>
13+
#include <testing-utils/message.h>
14+
#include <testing-utils/use_catch.h>
15+
16+
#include <fstream>
17+
18+
TEST_CASE("Parse empty C++ file", "[core][cpp][cpp_parser]")
19+
{
20+
temporary_filet temp_file("empty_cpp_", ".cpp");
21+
std::ofstream out(temp_file().c_str());
22+
out << "";
23+
out.close();
24+
25+
config.ansi_c.set_ILP32();
26+
27+
std::ifstream in(temp_file().c_str());
28+
29+
cpp_parsert parser(null_message_handler);
30+
parser.in = &in;
31+
32+
REQUIRE(parser.parse() == false);
33+
}
34+
35+
TEST_CASE("Parse simple C++ code", "[core][cpp][cpp_parser]")
36+
{
37+
temporary_filet temp_file("simple_cpp_", ".cpp");
38+
std::ofstream out(temp_file().c_str());
39+
out << "int main() { return 0; }\n";
40+
out.close();
41+
42+
config.ansi_c.set_ILP32();
43+
44+
std::ifstream in(temp_file().c_str());
45+
46+
cpp_parsert parser(null_message_handler);
47+
parser.in = &in;
48+
49+
REQUIRE(parser.parse() == false);
50+
}
51+
52+
TEST_CASE("Parse C++ with class", "[core][cpp][cpp_parser]")
53+
{
54+
temporary_filet temp_file("class_cpp_", ".cpp");
55+
std::ofstream out(temp_file().c_str());
56+
out << "class MyClass { public: int x; };\n";
57+
out.close();
58+
59+
config.ansi_c.set_ILP32();
60+
61+
std::ifstream in(temp_file().c_str());
62+
63+
cpp_parsert parser(null_message_handler);
64+
parser.in = &in;
65+
66+
REQUIRE(parser.parse() == false);
67+
}

unit/cpp/cpp_scanner.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests for CPP lexer/scanner
4+
5+
Author: Daniel Kroening, 2015
6+
7+
\*******************************************************************/
8+
9+
#include <util/config.h>
10+
#include <util/tempfile.h>
11+
12+
#include <ansi-c/ansi_c_parser.h>
13+
#include <cpp/cpp_parser.h>
14+
#include <cpp/cpp_token_buffer.h>
15+
#include <testing-utils/message.h>
16+
#include <testing-utils/use_catch.h>
17+
18+
#include <fstream>
19+
#include <sstream>
20+
#include <vector>
21+
22+
TEST_CASE("Scan simple C++ tokens", "[core][cpp][cpp_scanner]")
23+
{
24+
temporary_filet temp_file("tokens_cpp_", ".cpp");
25+
std::ofstream out(temp_file().c_str());
26+
out << "int x = 42;\n";
27+
out.close();
28+
29+
std::ifstream in(temp_file().c_str());
30+
31+
config.ansi_c.set_ILP32();
32+
33+
ansi_c_scanner_init();
34+
ansi_c_parser.clear();
35+
ansi_c_parser.mode = ansi_c_parsert::GCC;
36+
ansi_c_parser.cpp98 = true;
37+
ansi_c_parser.cpp11 = false;
38+
ansi_c_parser.ts_18661_3_Floatn_types = false;
39+
ansi_c_parser.__float128_is_keyword = false;
40+
ansi_c_parser.float16_type = false;
41+
ansi_c_parser.bf16_type = false;
42+
ansi_c_parser.fp16_type = false;
43+
ansi_c_parser.in = &in;
44+
45+
cpp_parsert parser(null_message_handler);
46+
parser.in = &in;
47+
48+
cpp_tokent tk;
49+
std::vector<std::string> tokens;
50+
51+
while(parser.token_buffer.get_token(tk))
52+
tokens.push_back(tk.text);
53+
54+
REQUIRE(tokens.size() > 0);
55+
REQUIRE(tokens[0] == "int");
56+
}
57+
58+
TEST_CASE("Scan C++ keywords", "[core][cpp][cpp_scanner]")
59+
{
60+
temporary_filet temp_file("keywords_cpp_", ".cpp");
61+
std::ofstream out(temp_file().c_str());
62+
out << "class namespace public private\n";
63+
out.close();
64+
65+
std::ifstream in(temp_file().c_str());
66+
67+
config.ansi_c.set_ILP32();
68+
69+
ansi_c_scanner_init();
70+
ansi_c_parser.clear();
71+
ansi_c_parser.mode = ansi_c_parsert::GCC;
72+
ansi_c_parser.cpp98 = true;
73+
ansi_c_parser.cpp11 = false;
74+
ansi_c_parser.ts_18661_3_Floatn_types = false;
75+
ansi_c_parser.__float128_is_keyword = false;
76+
ansi_c_parser.float16_type = false;
77+
ansi_c_parser.bf16_type = false;
78+
ansi_c_parser.fp16_type = false;
79+
ansi_c_parser.in = &in;
80+
81+
cpp_parsert parser(null_message_handler);
82+
parser.in = &in;
83+
84+
cpp_tokent tk;
85+
std::vector<std::string> tokens;
86+
87+
while(parser.token_buffer.get_token(tk))
88+
tokens.push_back(tk.text);
89+
90+
REQUIRE(tokens.size() == 4);
91+
REQUIRE(tokens[0] == "class");
92+
REQUIRE(tokens[1] == "namespace");
93+
}

unit/cpp/module_dependencies.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
testing-utils
2+
cpp
3+
util

unit/cpp_parser.cpp

Lines changed: 0 additions & 31 deletions
This file was deleted.

unit/cpp_scanner.cpp

Lines changed: 0 additions & 57 deletions
This file was deleted.

unit/elf_reader.cpp

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)