make building tests optional:

* disable build specific commandline options when built without tests
This commit is contained in:
Richard Holland
2021-07-05 12:37:29 +02:00
committed by manojsdoshi
parent 90aa3c75a7
commit da26d11593
6 changed files with 480 additions and 411 deletions

View File

@@ -123,6 +123,25 @@ matrix:
- CMAKE_ADD="-Dcoverage=ON"
- TARGET=coverage_report
- SKIP_TESTS=true
# test-free builds
- <<: *linux
if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/
compiler: gcc-8
name: no-tests-unity, gcc-8
env:
- MATRIX_EVAL="CC=gcc-8 && CXX=g++-8"
- BUILD_TYPE=Debug
- CMAKE_ADD="-Dtests=OFF"
- SKIP_TESTS=true
- <<: *linux
if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/
compiler: clang-8
name: no-tests-non-unity, clang-8
env:
- MATRIX_EVAL="CC=clang-8 && CXX=clang++-8"
- BUILD_TYPE=Debug
- CMAKE_ADD="-Dtests=OFF -Dunity=OFF"
- SKIP_TESTS=true
# nounity
- <<: *linux
if: commit_message !~ /travis_run_/ OR commit_message =~ /travis_run_linux/ OR commit_message =~ /travis_run_nounity/

View File

@@ -292,6 +292,7 @@ install (
# WARNING!! -- horrible levelization ahead
# (these files should be isolated or moved...but
# unfortunately unit_test.h above creates this dependency)
if (tests)
install (
FILES
src/beast/extras/beast/unit_test/amount.hpp
@@ -311,7 +312,7 @@ install (
FILES
src/beast/extras/beast/unit_test/detail/const_container.hpp
DESTINATION include/beast/unit_test/detail)
endif () #tests
#[===================================================================[
rippled executable
#]===================================================================]
@@ -325,6 +326,9 @@ add_executable (rippled src/ripple/app/main/Application.h)
if (unity)
set_target_properties(rippled PROPERTIES UNITY_BUILD ON)
endif ()
if (tests)
target_compile_definitions(rippled PUBLIC ENABLE_TESTS)
endif()
target_sources (rippled PRIVATE
#[===============================[
main sources:
@@ -655,11 +659,14 @@ target_sources (rippled PRIVATE
src/ripple/shamap/impl/SHAMapNodeID.cpp
src/ripple/shamap/impl/SHAMapSync.cpp
src/ripple/shamap/impl/SHAMapTreeNode.cpp
src/ripple/shamap/impl/ShardFamily.cpp
src/ripple/shamap/impl/ShardFamily.cpp)
#[===============================[
test sources:
subdir: app
#]===============================]
if (tests)
target_sources (rippled PRIVATE
src/test/app/AccountDelete_test.cpp
src/test/app/AccountTxPaging_test.cpp
src/test/app/AmendmentTable_test.cpp
@@ -966,6 +973,8 @@ target_sources (rippled PRIVATE
subdir: unit_test
#]===============================]
src/test/unit_test/multi_runner.cpp)
endif () #tests
target_link_libraries (rippled
Ripple::boost
Ripple::opts
@@ -985,9 +994,11 @@ endif ()
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
# any files that don't play well with unity should be added here
if (tests)
set_source_files_properties(
# these two seem to produce conflicts in beast teardown template methods
src/test/rpc/ValidatorRPC_test.cpp
src/test/rpc/ShardArchiveHandler_test.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
endif () #tests
endif ()

View File

@@ -1,7 +1,7 @@
#[===================================================================[
docs target (optional)
#]===================================================================]
if (tests)
find_package (Doxygen)
if (NOT TARGET Doxygen::doxygen)
message (STATUS "doxygen executable not found -- skipping docs target")
@@ -76,3 +76,4 @@ add_custom_command (
add_custom_target (docs
DEPENDS "${doxygen_index_file}"
SOURCES "${dependencies}")
endif ()

View File

@@ -6,6 +6,8 @@ option (assert "Enables asserts, even in release builds" OFF)
option (reporting "Build rippled with reporting mode enabled" OFF)
option (tests "Build tests" ON)
option (unity "Creates a build using UNITY support in cmake. This is the default" ON)
if (unity)
if (CMAKE_VERSION VERSION_LESS 3.16)

View File

@@ -34,8 +34,10 @@
#include <ripple/resource/Fees.h>
#include <ripple/rpc/RPCHandler.h>
#ifdef ENABLE_TESTS
#include <beast/unit_test/match.hpp>
#include <test/unit_test/multi_runner.h>
#endif // ENABLE_TESTS
#include <google/protobuf/stubs/common.h>
@@ -184,6 +186,7 @@ printHelp(const po::options_description& desc)
//------------------------------------------------------------------------------
#ifdef ENABLE_TESTS
/* simple unit test selector that allows a comma separated list
* of selectors
*/
@@ -335,6 +338,7 @@ runUnitTests(
}
}
#endif // ENABLE_TESTS
//------------------------------------------------------------------------------
int
@@ -405,6 +409,7 @@ run(int argc, char** argv)
"DEPRECATED: include with rpc_ip instead. "
"Specify the port number for RPC command.");
#ifdef ENABLE_TESTS
po::options_description test("Unit Test Options");
test.add_options()(
"quiet,q",
@@ -433,6 +438,7 @@ run(int argc, char** argv)
"unittest-jobs",
po::value<std::size_t>(),
"Number of unittest jobs to run in parallel (child processes).");
#endif // ENABLE_TESTS
// These are hidden options, not intended to be shown in the usage/help
// message
@@ -443,20 +449,37 @@ run(int argc, char** argv)
"Specify rpc command and parameters. This option must be repeated "
"for each command/param. Positional parameters also serve this "
"purpose, "
"so this option is not needed for users")(
"unittest-child",
"For internal use only when spawning child unit test processes.")(
"fg", "Deprecated: server always in foreground mode.");
"so this option is not needed for users")
#ifdef ENABLE_TESTS
("unittest-child",
"For internal use only when spawning child unit test processes.")
#else
("unittest", "Disabled in this build.")(
"unittest-child", "Disabled in this build.")
#endif // ENABLE_TESTS
("fg", "Deprecated: server always in foreground mode.");
// Interpret positional arguments as --parameters.
po::positional_options_description p;
p.add("parameters", -1);
po::options_description all;
all.add(gen).add(rpc).add(data).add(test).add(hidden);
all.add(gen)
.add(rpc)
.add(data)
#ifdef ENABLE_TESTS
.add(test)
#endif // ENABLE_TESTS
.add(hidden);
po::options_description desc;
desc.add(gen).add(rpc).add(data).add(test);
desc.add(gen)
.add(rpc)
.add(data)
#ifdef ENABLE_TESTS
.add(test)
#endif // ENABLE_TESTS
;
// Parse options, if no error.
try
@@ -489,6 +512,14 @@ run(int argc, char** argv)
return 0;
}
#ifndef ENABLE_TESTS
if (vm.count("unittest") || vm.count("unittest-child"))
{
std::cerr << "rippled: Tests disabled in this build." << std::endl;
std::cerr << "Try 'rippled --help' for a list of options." << std::endl;
return 1;
}
#else
// Run the unit tests if requested.
// The unit tests will exit the application with an appropriate return code.
//
@@ -528,6 +559,7 @@ run(int argc, char** argv)
return 1;
}
}
#endif // ENABLE_TESTS
auto config = std::make_unique<Config>();

View File

@@ -31,9 +31,11 @@
#include <boost/filesystem.hpp>
namespace ripple {
#ifdef ENABLE_TESTS
namespace test {
class ShardArchiveHandler_test;
}
#endif // ENABLE_TESTS
namespace RPC {
/** Handles the download and import of one or more shard archives. */
@@ -42,7 +44,9 @@ class ShardArchiveHandler
public:
using TimerOpCounter =
ClosureCounter<void, boost::system::error_code const&>;
#ifdef ENABLE_TESTS
friend class test::ShardArchiveHandler_test;
#endif // ENABLE_TESTS
static boost::filesystem::path
getDownloadDirectory(Config const& config);