Skip to content

Commit ca1a093

Browse files
Add regression test: Don't assert(...) with side effects
1 parent 4c3c9c3 commit ca1a093

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/lint/lint-assertions.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2018 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Check for assertions with obvious side effects.
8+
9+
export LC_ALL=C
10+
11+
EXIT_CODE=0
12+
13+
# PRE31-C (SEI CERT C Coding Standard):
14+
# "Assertions should not contain assignments, increment, or decrement operators."
15+
OUTPUT=$(git grep -E '[^_]assert\(.*(\+\+|\-\-|[^=!<>]=[^=!<>]).*\);' -- "*.cpp" "*.h")
16+
if [[ ${OUTPUT} != "" ]]; then
17+
echo "Assertions should not have side effects:"
18+
echo
19+
echo "${OUTPUT}"
20+
EXIT_CODE=1
21+
fi
22+
23+
exit ${EXIT_CODE}

0 commit comments

Comments
 (0)