1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-16 07:08:01 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Roman Proskuryakov
0acb371b92
Fix Wold-style-cast error (#2125)
* Add Wold-style-cast to cmake flags
* Fix old style cast in catch_stats.hpp
* Fix old style cast in catch_stats.cpp
2020-12-28 14:00:19 +01:00
Florian Berchtold
045feff834
Update cmake-integration.md (#2115)
* Update cmake-integration.md

CMake related, mainly more modern and provide an executable to be correct

Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
2020-12-28 13:41:55 +01:00
Martin Hořeňovský
965afc4b2e Split CATCH_CONFIG_ANDROID_LOGWRITE into its own header
Part of #2041
2020-12-28 12:53:52 +01:00
15 changed files with 51 additions and 19 deletions

View File

@ -63,6 +63,7 @@ function(add_warnings_to_targets targets)
"-Wdeprecated-register"
"-Wsuggest-override"
"-Wshadow"
"-Wold-style-cast"
)
foreach(warning ${CHECKED_WARNING_FLAGS})
add_cxx_flag_if_supported_to_targets(${warning} "${targets}")

View File

@ -25,7 +25,8 @@ This means that if Catch2 has been installed on the system, it should be
enough to do:
```cmake
find_package(Catch2 REQUIRED)
target_link_libraries(tests Catch2::Catch2)
add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
```
@ -33,7 +34,8 @@ This target is also provided when Catch2 is used as a subdirectory.
Assuming that Catch2 has been cloned to `lib/Catch2`:
```cmake
add_subdirectory(lib/Catch2)
target_link_libraries(tests Catch2::Catch2)
add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
```
Another possibility is to use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html):
@ -47,7 +49,8 @@ FetchContent_Declare(
FetchContent_MakeAvailable(Catch2)
target_link_libraries(tests Catch2::Catch2)
add_executable(tests test.cpp)
target_link_libraries(tests PRIVATE Catch2::Catch2)
```
## Automatic test registration
@ -78,7 +81,7 @@ project(baz LANGUAGES CXX VERSION 0.0.1)
find_package(Catch2 REQUIRED)
add_executable(foo test.cpp)
target_link_libraries(foo Catch2::Catch2)
target_link_libraries(foo PRIVATE Catch2::Catch2)
include(CTest)
include(Catch)
@ -191,7 +194,7 @@ project(baz LANGUAGES CXX VERSION 0.0.1)
find_package(Catch2 REQUIRED)
add_executable(foo test.cpp)
target_link_libraries(foo Catch2::Catch2)
target_link_libraries(foo PRIVATE Catch2::Catch2)
include(CTest)
include(ParseAndAddCatchTests)

View File

@ -51,6 +51,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/internal/catch_source_line_info.hpp
${SOURCES_DIR}/internal/catch_compiler_capabilities.hpp
${SOURCES_DIR}/catch_config.hpp
${SOURCES_DIR}/internal/catch_config_android_logwrite.hpp
${SOURCES_DIR}/internal/catch_config_uncaught_exceptions.hpp
${SOURCES_DIR}/internal/catch_console_colour.hpp
${SOURCES_DIR}/internal/catch_context.hpp

View File

@ -182,7 +182,7 @@ namespace Catch {
double k0 = -n * nd;
double k1 = sb2 - n * sg2 + nd;
double det = k1 * k1 - 4 * sg2 * k0;
return (int)(-2. * k0 / (k1 + std::sqrt(det)));
return static_cast<int>(-2. * k0 / (k1 + std::sqrt(det)));
};
auto var_out = [n, sb2, sg2](double c) {

View File

@ -102,7 +102,7 @@ namespace Catch {
double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
int n = static_cast<int>(resample.size());
double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / (double)n;
double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n);
// degenerate case with uniform samples
if (prob_n == 0) return { point, point, point, confidence_level };

View File

@ -50,6 +50,7 @@
#include <catch2/internal/catch_clara.hpp>
#include <catch2/internal/catch_commandline.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_config_android_logwrite.hpp>
#include <catch2/internal/catch_config_uncaught_exceptions.hpp>
#include <catch2/internal/catch_console_colour.hpp>
#include <catch2/internal/catch_console_width.hpp>

View File

@ -118,7 +118,6 @@
// Android somehow still does not support std::to_string
#if defined(__ANDROID__)
# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
#endif
////////////////////////////////////////////////////////////////////////////////
@ -320,10 +319,6 @@
# define CATCH_CONFIG_USE_ASYNC
#endif
#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE)
# define CATCH_CONFIG_ANDROID_LOGWRITE
#endif
#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
# define CATCH_CONFIG_GLOBAL_NEXTAFTER
#endif

View File

@ -0,0 +1,31 @@
// Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)
// SPDX-License-Identifier: BSL-1.0
/** \file
* Wrapper for ANDROID_LOGWRITE configuration option
*
* We want to default to enabling it when compiled for android, but
* users of the library should also be able to disable it if they want
* to.
*/
#ifndef CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
#define CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
#if defined(__ANDROID__)
# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
#endif
#if defined( CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE ) && \
!defined( CATCH_CONFIG_NO_ANDROID_LOGWRITE ) && \
!defined( CATCH_CONFIG_ANDROID_LOGWRITE )
# define CATCH_CONFIG_ANDROID_LOGWRITE
#endif
#endif // CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED

View File

@ -6,7 +6,7 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/internal/catch_debug_console.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_config_android_logwrite.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_platform.hpp>
#include <catch2/internal/catch_windows_h_proxy.hpp>

View File

@ -1342,7 +1342,7 @@ String.tests.cpp:<line number>: passed: s.data() == ss.data() for: "hello world!
String.tests.cpp:<line number>: passed: s.substr(s.size() + 1, 123).empty() for: true
String.tests.cpp:<line number>: passed: std::strcmp(ss.c_str(), "world!") == 0 for: 0 == 0
String.tests.cpp:<line number>: passed: s.substr(1'000'000, 1).empty() for: true
String.tests.cpp:<line number>: passed: (char*)buffer1 != (char*)buffer2 for: "Hello" != "Hello"
String.tests.cpp:<line number>: passed: reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) for: "Hello" != "Hello"
String.tests.cpp:<line number>: passed: left == right for: Hello == Hello
String.tests.cpp:<line number>: passed: left != left.substr(0, 3) for: Hello != Hel
String.tests.cpp:<line number>: passed: sr == "a standard string" for: a standard string == "a standard string"

View File

@ -9968,7 +9968,7 @@ String.tests.cpp:<line number>
...............................................................................
String.tests.cpp:<line number>: PASSED:
CHECK( (char*)buffer1 != (char*)buffer2 )
CHECK( reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) )
with expansion:
"Hello" != "Hello"

View File

@ -2598,7 +2598,7 @@ ok {test-number} - std::strcmp(ss.c_str(), "world!") == 0 for: 0 == 0
# StringRef
ok {test-number} - s.substr(1'000'000, 1).empty() for: true
# StringRef
ok {test-number} - (char*)buffer1 != (char*)buffer2 for: "Hello" != "Hello"
ok {test-number} - reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2) for: "Hello" != "Hello"
# StringRef
ok {test-number} - left == right for: Hello == Hello
# StringRef

View File

@ -12133,7 +12133,7 @@ Message from section two
<Section name="Comparisons are deep" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Expression success="true" type="CHECK" filename="tests/<exe-name>/IntrospectiveTests/String.tests.cpp" >
<Original>
(char*)buffer1 != (char*)buffer2
reinterpret_cast&lt;char*>(buffer1) != reinterpret_cast&lt;char*>(buffer2)
</Original>
<Expanded>
"Hello" != "Hello"

View File

@ -79,7 +79,7 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
SECTION( "Comparisons are deep" ) {
char buffer1[] = "Hello";
char buffer2[] = "Hello";
CHECK((char*)buffer1 != (char*)buffer2);
CHECK(reinterpret_cast<char*>(buffer1) != reinterpret_cast<char*>(buffer2));
StringRef left(buffer1), right(buffer2);
REQUIRE( left == right );

View File

@ -41,7 +41,7 @@ TEST_CASE( "XmlEncode", "[XML]" ) {
// Thanks to Peter Bindels (dascandy) for some of the tests
TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8][approvals]") {
#define ESC(lit) (char*)(lit)
#define ESC(lit) reinterpret_cast<const char*>(lit)
SECTION("Valid utf-8 strings") {
CHECK(encode(ESC(u8"Here be 👾")) == ESC(u8"Here be 👾"));
CHECK(encode(ESC(u8"šš")) == ESC(u8"šš"));