Skip to content

Commit 69a5076

Browse files
committed
Meson: add target 'cppcheck'.
1 parent 3c69279 commit 69a5076

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

meson.build

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ simulator = static_library('simulator',
4141
'cosy.cpp',
4242
],
4343
cpp_args: [
44+
'-Werror',
4445
'-Wshadow',
4546
'-DVERSION_STRING="' + meson.project_version() + '.' + revcount + '-' + hash + '"'
4647
]
@@ -69,5 +70,23 @@ install_data([
6970
install_mode: 'r--r--r--',
7071
)
7172

73+
#
74+
# Run cppcheck
75+
#
76+
run_target('cppcheck', command: [
77+
'cppcheck',
78+
'--project=' + join_paths(meson.project_build_root(), 'compile_commands.json'),
79+
'--std=c++17',
80+
'--enable=style',
81+
'--check-level=exhaustive',
82+
'--error-exitcode=1', # Fail on any issues
83+
'--inline-suppr', # Enable inline control like // cppcheck-suppress 'id'
84+
'--quiet', # No progress report messages
85+
'--suppress=badBitmaskCheck', # Allow redundant zero operands
86+
'--suppress=*:*/gtest/*', # Ignore issues in Googletest
87+
'--library=' + join_paths(meson.source_root(), 'tests/googletest.xml'), # Parse TEST() macro properly
88+
]
89+
)
90+
7291
# Tests are defined in 'tests/meson.build' file
7392
subdir('tests')

tests/cli_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ TEST(cli, trace_end_file)
102102
auto trace = file_contents_split(trace_filename);
103103

104104
// Check output.
105-
ASSERT_GE(trace.size(), 4);
105+
ASSERT_GE(trace.size(), 4u);
106106
EXPECT_TRUE(starts_with(trace[0], "Dubna Simulator Version"));
107107
EXPECT_STREQ(trace[1].c_str(), "02010 R: 00 070 3002 *70 3002");
108108
EXPECT_STREQ(trace[2].c_str(), " Drum 21 PhysRead [00000-00377] = Zone 1 Sector 2");

tests/fixture_machine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ class dubna_machine : public ::testing::Test {
9696
void test_cernlib(unsigned lib_num, const std::string &file_base)
9797
{
9898
std::string job_filename = get_test_name() + ".dub";
99-
std::string input_dir = (lib_num == 1) ? (TEST_DIR "/lib1/") : (TEST_DIR "/lib2/");
99+
std::string lib1_dir = std::string(TEST_DIR "/lib1/");
100+
std::string lib2_dir = std::string(TEST_DIR "/lib2/");
101+
std::string input_dir = (lib_num == 1) ? lib1_dir : lib2_dir;
100102
std::string input_filename = input_dir + file_base + ".f";
101103
std::string expect_filename = input_dir + "/expect_" + file_base + ".txt";
102104
std::string prolog = "*name " + file_base + "\n" +

tests/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ unit_tests = executable('unit_tests',
2424
include_directories: '..',
2525
link_with: simulator,
2626
cpp_args: [
27+
'-Werror',
2728
'-Wshadow',
2829
'-DTEST_DIR="' + meson.current_source_dir() + '"',
29-
'-DBUILD_DIR="' + meson.build_root() + '"',
30+
'-DBUILD_DIR="' + meson.project_build_root() + '"',
3031
],
3132
build_by_default: false
3233
)

0 commit comments

Comments
 (0)