Skip to content

Commit

Permalink
Merge #15943: tests: Fail if RPC has been added without tests
Browse files Browse the repository at this point in the history
fad0ce59e9 tests: Fail if RPC has been added without tests (MarcoFalke)

Need to be run with --coverage

Backport of Core [PR15943](bitcoin/bitcoin#15943)

Test Plan:
```
test_runner.py --coverage --extended
```

Verify `All RPC commands covered.` is printed to the console.

Differential Revision: https://reviews.bitcoinabc.org/D5743
  • Loading branch information
MarcoFalke authored and dagurval committed Jul 2, 2020
1 parent 380d1e6 commit f0d275e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions test/functional/rpc_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def run_test(self):
assert_raises_rpc_error(-8, "unknown mode foobar",
node.getmemoryinfo, mode="foobar")

self.log.info("test logging")
assert_equal(node.logging()['qt'], True)
node.logging(exclude=['qt'])
assert_equal(node.logging()['qt'], False)
node.logging(include=['qt'])
assert_equal(node.logging()['qt'], True)


if __name__ == '__main__':
RpcMiscTest().main()
10 changes: 7 additions & 3 deletions test/functional/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,19 @@ def run_tests(test_list, build_dir, tests_dir, junitoutput, tmpdir, num_jobs, te
build_timings.save_timings(test_results)

if coverage:
coverage.report_rpc_coverage()
coverage_passed = coverage.report_rpc_coverage()

logging.debug("Cleaning up coverage data")
coverage.cleanup()
else:
coverage_passed = True

# Clear up the temp directory if all subdirectories are gone
if not os.listdir(tmpdir):
os.rmdir(tmpdir)

all_passed = all(
map(lambda test_result: test_result.was_successful, test_results))
all_passed = all(map(
lambda test_result: test_result.was_successful, test_results)) and coverage_passed

sys.exit(not all_passed)

Expand Down Expand Up @@ -692,8 +694,10 @@ def report_rpc_coverage(self):
if uncovered:
print("Uncovered RPC commands:")
print("".join((" - {}\n".format(i)) for i in sorted(uncovered)))
return False
else:
print("All RPC commands covered.")
return True

def cleanup(self):
return shutil.rmtree(self.dir)
Expand Down

0 comments on commit f0d275e

Please sign in to comment.