Skip to content

Commit 69647a3

Browse files
committed
add clang-analyze
1 parent 6a7743d commit 69647a3

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: clang-analyze
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'README.md'
7+
- 'doc/**'
8+
pull_request:
9+
paths-ignore:
10+
- 'README.md'
11+
- 'doc/**'
12+
13+
jobs:
14+
clang-analyze:
15+
runs-on: ubuntu-latest
16+
env:
17+
SB: scan-build-15
18+
19+
steps:
20+
- uses: actions/checkout@v4
21+
- run: sudo apt-get update -yq
22+
- run: sudo apt-get install -yq clang-tools-15
23+
- run: ${SB} cmake -E make_directory build
24+
- working-directory: build/
25+
run: ${SB} cmake -DLIBEXT_TESTS=ON -DLIBEXT_TESTS_NO_TIME_CRITICAL=ON -DLIBEXT_EXAMPLES=ON -DEXT_DOWNLOAD=ON -DCLANG_ANALYZE=ON $GITHUB_WORKSPACE
26+
- working-directory: build/
27+
run: ${SB} cmake --build .

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ jobs:
5454
working-directory: ${{github.workspace}}/build
5555
# Execute tests defined by the CMake configuration.
5656
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
57-
run: ctest -VV -C ${{ env.build_type }}
57+
run: ctest -VV -C ${{ matrix.build_type }}

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ option(EXT_WRITE_VERSION "write version.hpp" OFF)
1212
option(LIBEXT_EXAMPLES "build examples" OFF)
1313
option(LIBEXT_TESTS "build tests" OFF)
1414
option(LIBEXT_TESTS_NO_TIME_CRITICAL "disable time critical tests" OFF)
15+
option(CLANG_ANALYZE "clang analyze build" OFF)
1516

1617
### configure defer
1718
option(LIBEXT_WARNINGS "enable warnings" ON)
@@ -29,6 +30,7 @@ set(ext_basics_compile_definitions
2930
$<$<BOOL:${LIBEXT_TESTS_NO_TIME_CRITICAL}>:EXT_TESTS_NO_TIME_CRITICAL=1>
3031
$<$<BOOL:${EXT_DEFER_NON_NOTHROW}>:EXT_DEFER_ALLOW_NON_NOTHROW_INVOCABLE=1>
3132
$<$<BOOL:${EXT_DEFER_MOVE_ASSIGN}>:EXT_DEFER_ENABLE_MOVE_ASSIGN=1>
33+
$<$<BOOL:${CLANG_ANALYZE}>:CLANG_ANALYZE>
3234
)
3335

3436
find_package(Threads REQUIRED)

examples/show.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ int main(/*int argc, const char *argv[]*/) {
2828
// prefer this!
2929
std::cout << vec << std::endl;
3030

31+
#ifndef CLANG_ANALYZE
3132
// a bit more magic
3233
std::cout << vec_of_maps << std::endl;
3334

3435
// prefer this!
3536
std::cout << vec2 << std::endl;
37+
#endif
3638

3739
return 0;
3840
}

tests/algorithm_longest_common_subsequence.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ class algorithm_longest_common_subsequence : public ::testing::Test {
1212
auto lenght = lsc_get_length(matrix);
1313
auto common = lcs_get_sequence(matrix, test_string_pair.first);
1414

15-
EXPECT_TRUE(expected_lenght == lenght && expected_common == common)
16-
<< "\n input: '" << test_string_pair.first << "' and '" << test_string_pair.second << "'"
17-
<< "\n result: " << lenght << " -- " << common
18-
<< "\n expected: " << expected_lenght << " -- " << expected_common
19-
<< "\n" << ext::util::pretty::fmt(matrix)
20-
<< "\n\n";
15+
EXPECT_TRUE(expected_lenght == lenght && expected_common == common)
16+
<< "\n input: '" << test_string_pair.first << "' and '" << test_string_pair.second << "'"
17+
<< "\n result: " << lenght << " -- " << common << "\n expected: " << expected_lenght << " -- "
18+
<< expected_common << "\n"
19+
#ifndef CLANG_ANALYZE
20+
<< ext::util::pretty::fmt(matrix) << "\n\n";
21+
#else
22+
<< "\n";
23+
#endif
2124
}
2225
};
2326

tests/util_show.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ TEST(util_pretty, map_int_str) {
4444
}
4545

4646
TEST(util_pretty, vec_map_vec_int_str) {
47+
#ifndef CLANG_ANALYZE
4748
using Map = std::map<std::vector<int>, std::string>;
4849
Map item{{std::vector{1, 2}, "foo"s}, {std::vector{3}, "bar"s}};
4950
std::vector<Map> out = {item, item};
@@ -52,6 +53,7 @@ TEST(util_pretty, vec_map_vec_int_str) {
5253
using eu::operator<<;
5354
ss << out;
5455
ASSERT_EQ(ss.str(), "[{[1, 2]:\"foo\", [3]:\"bar\"}, {[1, 2]:\"foo\", [3]:\"bar\"}]");
56+
#endif
5557
}
5658

5759
TEST(util_pretty, set_int) {

0 commit comments

Comments
 (0)