From 7b4a296a71d1b7f2555f5f63512ec964671464c0 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Sun, 18 Mar 2018 20:43:21 +0100 Subject: [PATCH 1/3] tests: Add note about test suite naming convention --- doc/developer-notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index a5468c3be..2724fe194 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -34,6 +34,8 @@ code. - Constant names are all uppercase, and use `_` to separate words. - Class names, function names and method names are UpperCamelCase (PascalCase). Do not prefix class names with `C`. + - Test suite naming convention: The Boost test suite in file + `src/test/foo_tests.cpp` should be named `foo_tests`. - **Miscellaneous** - `++i` is preferred over `i++`. From 5fd864fe8a3b7c6abcfec97980ccc8f57ffdd8ca Mon Sep 17 00:00:00 2001 From: practicalswift Date: Sun, 18 Mar 2018 18:52:30 +0100 Subject: [PATCH 2/3] tests: Rename test suits not following the test suite naming convention The name of the fixture test suite in `src/test/foo_tests.cpp` should be `foo_tests`. --- src/test/blockchain_tests.cpp | 2 +- src/test/prevector_tests.cpp | 2 +- src/wallet/crypter.h | 4 ++-- src/wallet/test/coinselector_tests.cpp | 2 +- src/wallet/test/crypto_tests.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/test/blockchain_tests.cpp b/src/test/blockchain_tests.cpp index 55fdd2c07..32b408838 100644 --- a/src/test/blockchain_tests.cpp +++ b/src/test/blockchain_tests.cpp @@ -54,7 +54,7 @@ void TestDifficulty(uint32_t nbits, double expected_difficulty) RejectDifficultyMismatch(difficulty, expected_difficulty); } -BOOST_FIXTURE_TEST_SUITE(blockchain_difficulty_tests, BasicTestingSetup) +BOOST_FIXTURE_TEST_SUITE(blockchain_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(get_difficulty_for_very_low_target) { diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index 01c3a6ced..fe6f10d84 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -13,7 +13,7 @@ #include -BOOST_FIXTURE_TEST_SUITE(PrevectorTests, TestingSetup) +BOOST_FIXTURE_TEST_SUITE(prevector_tests, TestingSetup) template class prevector_tester { diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h index f3ae7144b..fdeb4cfee 100644 --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -67,7 +67,7 @@ public: typedef std::vector > CKeyingMaterial; -namespace wallet_crypto +namespace crypto_tests { class TestCrypter; } @@ -75,7 +75,7 @@ namespace wallet_crypto /** Encryption/decryption context with key information */ class CCrypter { -friend class wallet_crypto::TestCrypter; // for test access to chKey/chIV +friend class crypto_tests::TestCrypter; // for test access to chKey/chIV private: std::vector> vchKey; std::vector> vchIV; diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index f05c81cd4..df47bc0bc 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -13,7 +13,7 @@ #include #include -BOOST_FIXTURE_TEST_SUITE(coin_selection_tests, WalletTestingSetup) +BOOST_FIXTURE_TEST_SUITE(coinselector_tests, WalletTestingSetup) // how many times to run all the tests to have a chance to catch errors that only show up with particular random shuffles #define RUN_TESTS 100 diff --git a/src/wallet/test/crypto_tests.cpp b/src/wallet/test/crypto_tests.cpp index 89b2c4e79..d8c0cdf0f 100644 --- a/src/wallet/test/crypto_tests.cpp +++ b/src/wallet/test/crypto_tests.cpp @@ -10,7 +10,7 @@ #include -BOOST_FIXTURE_TEST_SUITE(wallet_crypto, BasicTestingSetup) +BOOST_FIXTURE_TEST_SUITE(crypto_tests, BasicTestingSetup) class TestCrypter { From db983beba6fec910722bacc0d67c7ae98ba566fa Mon Sep 17 00:00:00 2001 From: practicalswift Date: Sun, 18 Mar 2018 19:17:34 +0100 Subject: [PATCH 3/3] tests: Add lint-tests.sh which checks the test suite naming convention --- contrib/devtools/lint-tests.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 contrib/devtools/lint-tests.sh diff --git a/contrib/devtools/lint-tests.sh b/contrib/devtools/lint-tests.sh new file mode 100755 index 000000000..dd1a3ebdc --- /dev/null +++ b/contrib/devtools/lint-tests.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Copyright (c) 2018 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +# +# Check the test suite naming convention + +NAMING_INCONSISTENCIES=$(git grep -E '^BOOST_FIXTURE_TEST_SUITE\(' -- \ + "src/test/**.cpp" "src/wallet/test/**.cpp" | \ + grep -vE '/(.*?)\.cpp:BOOST_FIXTURE_TEST_SUITE\(\1, .*\)$') +if [[ ${NAMING_INCONSISTENCIES} != "" ]]; then + echo "The test suite in file src/test/foo_tests.cpp should be named" + echo "\"foo_tests\". Please make sure the following test suites follow" + echo "that convention:" + echo + echo "${NAMING_INCONSISTENCIES}" + exit 1 +fi