test/lint/lint-assertions.sh
to test/lint/lint-assertions.py
. It’s an item of #24783.
test/lint/lint-assertions.sh
to test/lint/lint-assertions.py
. It’s an item of #24783.
37+ ], "Assertions should not have side effects:")
38+
39+ # Macro CHECK_NONFATAL(condition) should be used instead of assert for RPC code, where it
40+ # is undesirable to crash the whole program. See: src/util/check.h
41+ # src/rpc/server.cpp is excluded from this check since it's mostly meta-code.
42+ exit_code += exec_cmd([
0 exit_code |= exec_cmd([
6+#
7+# Check for assertions with obvious side effects.
8+
9+import sys
10+
11+from subprocess import check_output, CalledProcessError
subprocess.check_output
and so on.
15+ output = subprocess.check_output(command, universal_newlines=True, encoding="utf8")
16+ print(error_msg)
17+ print(output)
18+ return 1
19+ except subprocess.CalledProcessError as ex1:
20+ if ex1.returncode > 1:
except
and let a CalledProcessError
escalate. This only hapens if git fails.
$()
, that will get only output ignoring the exit code.
The idea here is expect the CalledProcessError.returncode
equal 1 to have sure if command output is empty.
OK, that makes sense. Do you know if this behavior of git grep
is documented anywhere? The manual page doesn’t mention anything about return codes.
Edit: apparently this is expected behavior because grep
does it:
0EXIT STATUS
1 Normally the exit status is 0 if a line is selected, 1 if no lines were selected, and 2 if an error occurred.
2 However, if the -q or --quiet or --silent is used and a line is selected, the exit status is 0 even if an
3 error occurred.
10+import subprocess
11+
12+
13+def exec_cmd(command: [], error_msg: ""):
14+ try:
15+ output = subprocess.check_output(command, universal_newlines=True, encoding="utf8")
8+
9+import sys
10+import subprocess
11+
12+
13+def exec_cmd(command: [], error_msg: ""):
subprocess.check_output
directly below where relevant. The amount of shared code is minimal, no need to define a function.
git grep
. It makes sense to make it a git_grep
wrapper specifically.
Tested ACK 1e0a9ad1cedafe10a1e8743a4eda1d64cef5fe2c
Before:
0Assertions should not have side effects:
1
2src/addrman.cpp: assert(--nIds != nNew); // this means nNew was wrong, oh ow
3src/bench/ccoins_caching.cpp: assert(success = 2);
4src/bench/checkblock.cpp: assert(rewound ++);
5src/bench/verify_script.cpp: assert(success += 1);
6src/node/coin.cpp: assert(node.mempool -= 1);
7CHECK_NONFATAL(condition) should be used instead of assert for RPC code.
8
9src/rpc/blockchain.cpp:77: assert(blockindex);
10src/rpc/rawtransaction.cpp:469: assert(false);
After:
0Assertions should not have side effects:
1src/addrman.cpp: assert(--nIds != nNew); // this means nNew was wrong, oh ow
2src/bench/ccoins_caching.cpp: assert(success = 2);
3src/bench/checkblock.cpp: assert(rewound ++);
4src/bench/verify_script.cpp: assert(success += 1);
5src/node/coin.cpp: assert(node.mempool -= 1);
6
7CHECK_NONFATAL(condition) should be used instead of assert for RPC code.
8src/rpc/blockchain.cpp:77: assert(blockindex);
9src/rpc/rawtransaction.cpp:469: assert(false);