Skip to content

Commit

Permalink
Updated unit tests to work with Catch2 v2 or v3
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Jul 2, 2024
1 parent 4d8270c commit 954563e
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
git checkout "v3.6.0"
mkdir build && cd build
cmake .. -DBUILD_TESTING=OFF
cmake --build . --target install
sudo cmake --build . --target install
- name: Set reusable strings
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ add_executable(unit_tests
test_timer.cpp
)

target_include_directories(unit_tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

if (Catch2_VERSION VERSION_LESS "3.0")
target_compile_definitions(unit_tests PUBLIC CATCH2_V2)
message(STATUS "catch2 version is less than in upstream")
endif()


# --- Link for executables ---

target_link_libraries(unit_tests
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/catch2_version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// catch2_version.h
//
// Header to figure out which Catch2 version we're using, and the proper
// header for that version.
//

/****************************************************************************
* BSD 3-Clause License
*
* Copyright (c) 2024, Frank Pagliughi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
***************************************************************************/

#ifdef CATCH2_V2
#include "catch2/catch.hpp"
#else
#include "catch2/catch_all.hpp"
#endif
2 changes: 1 addition & 1 deletion tests/unit/test_func_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//

#include "cooper/func_wrapper.h"
#include <catch2/catch.hpp>
#include "catch2_version.h"

using namespace cooper;

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_task_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/****************************************************************************
* BSD 3-Clause License
*
* Copyright (c) 2019, Frank Pagliughi
* Copyright (c) 2019-2024, Frank Pagliughi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -41,7 +41,7 @@
***************************************************************************/

#include "cooper/task_queue.h"
#include <catch2/catch.hpp>
#include "catch2_version.h"

using namespace std::chrono;
using namespace cooper;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
***************************************************************************/

#include "cooper/task_queue.h"
#include <catch2/catch.hpp>
#include "catch2_version.h"

#if 0
#include <iostream>
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/****************************************************************************
* BSD 3-Clause License
*
* Copyright (c) 2019, Frank Pagliughi
* Copyright (c) 2019-2024, Frank Pagliughi
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -41,7 +41,7 @@
***************************************************************************/

#include "cooper/work_thread.h"
#include <catch2/catch.hpp>
#include "catch2_version.h"

#if 0
#include <iostream>
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/unit_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// unit_tests.cpp
//
// Main for the Catch2 unit tests for the Paho MQTT C++ library.
// Main for the Catch2 unit tests for the cooper C++ actor library.
//

/*******************************************************************************
* Copyright (c) 2019 Frank Pagliughi <fpagliughi@mindspring.com>
* Copyright (c) 2019-2024 Frank Pagliughi <fpagliughi@mindspring.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
Expand All @@ -21,5 +21,5 @@

// This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"
#include "catch2_version.h"

0 comments on commit 954563e

Please sign in to comment.