Skip to content

Commit

Permalink
PR #12257 from Eran: Catch2 v3.4 as static lib; U22 in GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
maloel authored Oct 5, 2023
2 parents 9b66e93 + ae54bc3 commit 25b4b59
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 17,792 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/buildsCI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ jobs:
#--------------------------------------------------------------------------------
U20_ST_Py_EX_CfU_LiveTest: # Ubuntu 2020, Static, Python, Examples & Tools, Check for Updates, Legacy Live-Tests
runs-on: ubuntu-20.04
U22_ST_Py_EX_CfU_LiveTest: # Ubuntu 2022, Static, Python, Examples & Tools, Check for Updates, Legacy Live-Tests
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
Expand All @@ -267,9 +267,6 @@ jobs:
sudo apt-get install -qq libusb-1.0-0-dev;
sudo apt-get install -qq libgtk-3-dev;
sudo apt-get install libglfw3-dev libglfw3;
# We force compiling with GCC 7 because the default installed GCC 9 compiled with LTO and gives an internal compiler error
sudo apt-get install gcc-7 g++-7;
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7;
- name: Build
shell: bash
Expand Down Expand Up @@ -399,8 +396,8 @@ jobs:

#--------------------------------------------------------------------------------
U20_SH_RSUSB_LiveTest: # Ubuntu 2020, Shared, Legacy live-tests
runs-on: ubuntu-20.04
U22_SH_RSUSB_LiveTest: # Ubuntu 2022, Shared, Legacy live-tests
runs-on: ubuntu-22.04
timeout-minutes: 60
env:
LRS_BUILD_NODEJS: true
Expand All @@ -426,9 +423,6 @@ jobs:
sudo apt-get install -qq libusb-1.0-0-dev;
sudo apt-get install -qq libgtk-3-dev;
sudo apt-get install libglfw3-dev libglfw3;
# We force compiling with GCC 7 because the default installed GCC 9 compiled with LTO and gives an internal compiler error
sudo apt-get install gcc-7 g++-7;
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 --slave /usr/bin/g++ g++ /usr/bin/g++-7;
- name: Build
shell: bash
Expand Down
19 changes: 19 additions & 0 deletions CMake/catch2-download.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.6)
project(catch2-download NONE)

include(ExternalProject)
ExternalProject_Add(
catch2
PREFIX .
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0
GIT_CONFIG advice.detachedHead=false # otherwise we'll get "You are in 'detached HEAD' state..."
SOURCE_DIR "${CMAKE_BINARY_DIR}/third-party/catch2"
GIT_SHALLOW 1 # No history needed (requires cmake 3.6)
# Override default steps with no action, we just want the clone step.
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)


51 changes: 51 additions & 0 deletions CMake/external_catch2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cmake_minimum_required(VERSION 3.10)
include(ExternalProject)


# We use a function to enforce a scoped variables creation only for the build
# (i.e turn off BUILD_SHARED_LIBS which is used on LRS build as well)
function(get_catch2)

message( STATUS "Fetching Catch2..." )

# We want to clone the repo and build it here, during configuration, so we can use it.
# But ExternalProject_add is limited in that it only does its magic during build.
# This is possible in CMake 3.12+ with FetchContent and FetchContent_MakeAvailable in 3.14+ (meaning Ubuntu 20)
# but we need to adhere to CMake 3.10 (Ubuntu 18).
# So instead, we invoke a new CMake project just to download it:
configure_file( CMake/catch2-download.cmake.in
${CMAKE_BINARY_DIR}/external-projects/catch2-download/CMakeLists.txt )
execute_process( COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/catch2-download"
OUTPUT_QUIET
RESULT_VARIABLE configure_ret )
execute_process( COMMAND "${CMAKE_COMMAND}" --build .
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/catch2-download"
OUTPUT_QUIET
RESULT_VARIABLE build_ret )

if( configure_ret OR build_ret )
message( FATAL_ERROR "Failed to download catchorg/catch2" )
endif()

# We use cached variables so the default parameter inside the sub directory will not override the required values
# We add "FORCE" so that is a previous cached value is set our assignment will override it.
set( CATCH_INSTALL_DOCS OFF CACHE INTERNAL "" FORCE )
set( CATCH_INSTALL_EXTRAS OFF CACHE INTERNAL "" FORCE )

add_subdirectory( "${CMAKE_BINARY_DIR}/third-party/catch2"
"${CMAKE_BINARY_DIR}/third-party/catch2/build" )

# place libraries with other 3rd-party projects
set_target_properties( Catch2 Catch2WithMain PROPERTIES
FOLDER "ExternalProjectTargets/catch2" )

message( STATUS "Fetching Catch2 - Done" )

endfunction()


get_catch2()
3 changes: 0 additions & 3 deletions CMake/external_json.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ function(get_nlohmann_json)
${CMAKE_BINARY_DIR}/external-projects/json-download/CMakeLists.txt )
execute_process( COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_CXX_STANDARD_LIBRARIES=${CMAKE_CXX_STANDARD_LIBRARIES}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DANDROID_ABI=${ANDROID_ABI}
-DANDROID_STL=${ANDROID_STL}
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/external-projects/json-download"
OUTPUT_QUIET
RESULT_VARIABLE configure_ret )
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ elseif(BUILD_TOOLS)
endif()

if(BUILD_UNIT_TESTS OR BUILD_LEGACY_LIVE_TEST)
include( CMake/external_catch2.cmake )
add_subdirectory(unit-tests)
endif()

Expand Down
8 changes: 4 additions & 4 deletions unit-tests/approx.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ We provide our own functions to do approximate comparison:
// Custom version of Approx, ==> better replaced by matchers <== for more control,
// but provides LRS defaults that should closely (but not exactly) match them
template< typename F >
inline Approx approx( F f )
inline Catch::Approx approx( F f )
{
return Approx( f )
return Catch::Approx( f )
.margin( __approx_margin< F >::value() )
.epsilon( __approx_epsilon< F >::value() );
}
Expand Down Expand Up @@ -138,9 +138,9 @@ Or, with the Catch matchers, even more:
These matchers are type-sensitive (float vs. double).
*/
#define approx_abs(D) \
Catch::WithinAbs( (D), approx_margin((D)) )
Catch::Matchers::WithinAbs( (D), approx_margin((D)) )
#define approx_rel(D) \
Catch::WithinRel( (D), approx_epsilon((D)) )
Catch::Matchers::WithinRel( (D), approx_epsilon((D)) )
#define approx_equals(D) \
( approx_abs(D) || approx_rel(D) )

Expand Down
64 changes: 1 addition & 63 deletions unit-tests/catch.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,66 +14,4 @@
#error CATCH_CONFIG_MAIN must not be defined: to run your own main(), use CATCH_CONFIG_RUNNER with #cmake:custom-main
#endif

#include "catch/catch.hpp"

#if defined(CATCH_CONFIG_RUNNER)

namespace Catch
{

// Allow custom test-cases on the fly
class CustomRunContext : public RunContext
{
public:
CustomRunContext( CustomRunContext const& ) = delete;
CustomRunContext & operator=( CustomRunContext const& ) = delete;

// RunContext ctor, but you need to give details...
explicit CustomRunContext( IStreamingReporterPtr&& reporter, IConfigPtr const& cfg )
: RunContext( cfg, std::move( reporter ))
{
}

// Easy way to instantiate, using the compact reporter by default
explicit CustomRunContext( std::string const & reporter_type = "compact", IConfigPtr const & cfg = IConfigPtr( new Config ) )
: CustomRunContext( getRegistryHub().getReporterRegistry().create( reporter_type, cfg ), cfg )
{
}

// Easy way to instantiate, using config data first
explicit CustomRunContext( Catch::ConfigData const & cfg, std::string const & reporter_type = "compact" )
: CustomRunContext( reporter_type, IConfigPtr( new Config( cfg ) ) )
{
}

// Allow changing the redirection for the reporter by force (the compact reporter does
// not allow changing via the Config's verbosity)
void set_redirection( bool on )
{
auto r = dynamic_cast<Catch::CompactReporter *>(&reporter());
if( r )
r->m_reporterPrefs.shouldRedirectStdOut = on;
}

template< class T >
Totals run_test( std::string const & name, T test )
{
struct invoker : ITestInvoker
{
T _test;
invoker( T t ) : _test( t ) {}
void invoke() const override
{
_test();
}
};
TestCase test_case( new invoker( test ),
TestCaseInfo( name, {}, {}, {}, {"",0} )
);
return runTest( test_case );
}
};

} // namespace Catch

#endif // CATCH_CONFIG_RUNNER
#include <catch2/catch_all.hpp>
Loading

0 comments on commit 25b4b59

Please sign in to comment.