Page MenuHomePhabricator

sigcheckcount_tests: better macro
ClosedPublic

Authored by markblundeberg on Feb 4 2020, 14:16.

Details

Summary

I noticed flags & ~SCRIPT_REPORT_SIGCHECKS was not expanding in the
intended way (gcc was warning this, but not clang). Classic macro
mistake, also there are other macro gotchas - this would have been
classified as an 'unsafe macro'.

https://wiki.sei.cmu.edu/confluence/display/c/PRE01-C.+Use+parentheses+within+macros+around+parameter+names
https://wiki.sei.cmu.edu/confluence/display/c/PRE12-C.+Do+not+define+unsafe+macros

The reason for using macros here was to make sure the origin of a
test failure can be printed out, as it's quite annoying to have a
context-less failure in an inner function. Fortunately
BOOST_TEST_CONTEXT provides a much nicer and more generic way to
give context, and I use it to make a safe macro instead. Awesome!

https://www.boost.org/doc/libs/1_72_0/libs/test/doc/html/boost_test/test_output/test_tools_support_for_logging/contexts.html#boost_test.test_output.test_tools_support_for_logging.contexts.scope_bound_context

Test Plan

ninja check

Try changing the last test's 2 to a 1, you will then see:

../src/test/sigcheckcount_tests.cpp(328): error: in "sigcheckcount_tests/test_verifyscript": check metricsRet.nSigChecks == expected_sigchecks has failed [2 != 1]
Failure occurred in a following context:
    ../src/test/sigcheckcount_tests.cpp:365

*** 1 failure is detected in the test module "Bitcoin Test Suite"

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

(apparently this requires boost 1.59 and our minversion is 1.58)

support boost <= 1.58 which lack the BOOST_TEST_CONTEXT macro
(no context messages)

This revision is now accepted and ready to land.Feb 4 2020, 15:06