1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
Import('env')
Import('mongo_tidy_module')
Import('base_toolchain_bin')
import sys
import os
import SCons
# multiple compilation databases is not supported by ninja
if env.GetOption('ninja') == 'disabled':
mongo_tidy_test_env = env.Clone()
mongo_tidy_test_env.Append(CPPPATH=[
'.',
'#src',
], )
# These test files will purposefully be error prone, so we can disable warnings any warnings we expect
# to see.
mongo_tidy_test_env.Append(CCFLAGS=[
'-Wno-unused-but-set-parameter',
], )
# This list represents the test source files, which should contain a single issue which will be flagged
# by a clang tidy check. The issue should be isolated in as minimal way as possible.
tests = [
'test_MongoHeaderBracketCheck.cpp',
'test_MongoVolatileCheck.cpp',
'test_MongoUninterruptibleLockGuardCheck.cpp',
'test_MongoCctypeCheck.cpp',
'test_MongoCxx20BannedIncludesCheck.cpp',
'test_MongoStdOptionalCheck.cpp',
'test_MongoTraceCheck.cpp',
'test_MongoStdAtomicCheck.cpp',
'test_MongoMutexCheck.cpp',
'test_MongoAssertCheck.cpp',
'test_MongoFCVConstantCheck.cpp',
'test_MongoUnstructuredLogCheck.cpp',
]
# So that we can do fast runs, we will generate a separate compilation database file for each
# unittest. To keep things simple we will name the compilation database file after the test.
# We need to create separate environments here because compilation database acts on the current
# environment.
test_objs = []
compilation_dbs = []
for test in tests:
test_env = mongo_tidy_test_env.Clone()
compilation_dbs += test_env.CompilationDatabase(
os.path.splitext(os.path.basename(test))[0] + "/compile_commands.json")
test_objs += test_env.Object(test)
# Building a program binary may not be necessary but it does validate the code and tie it together.
test_prog = mongo_tidy_test_env.Program(
target='MongoTidyCheck_test',
source=['MongoTidyCheckTestMain.cpp'] + test_objs,
LIBDEPS_NO_INHERIT=[
'$BUILD_DIR/third_party/shim_allocator',
],
)
# Here we setup the test execution. The test will pythons built in unittest framework
# to execute clang tidy for each test source file from the list above.
test = mongo_tidy_test_env.Command(
target='run_MongoTidyCheck_test',
source=[
'MongoTidyCheck_unittest.py',
str(base_toolchain_bin / 'clang-tidy'), mongo_tidy_module.abspath
] + compilation_dbs,
action=SCons.Action.Action(
' '.join([
sys.executable,
'${SOURCES[0]}',
'--clang-tidy-path=${SOURCES[1]}',
'--mongo-tidy-module=${SOURCES[2]}',
'${["--test-compiledbs=%s" % src for src in SOURCES[3:]]}',
f"{'' if mongo_tidy_test_env.Verbose() else '2> /dev/null'}",
]),
"" if mongo_tidy_test_env.Verbose() else "Runnning mongo tidy checks unittests.",
),
)
mongo_tidy_test_env.Alias('+mongo-tidy-tests', test)
mongo_tidy_test_env.Depends(test, test_prog)
|