Skip to content

Commit ae4cd1e

Browse files
committed
Corresponding code changes
1 parent 781c7a8 commit ae4cd1e

14 files changed

+60
-55
lines changed

lib/catch2/CMakeLists.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# catch2 is distributed as a standalone header.
1+
# catch2 is distributed as a standalone header / source amalgamation.
22
#
33
# Downloaded from:
44
#
5-
# https://github.com/catchorg/Catch2/releases/download/v2.13.9/catch.hpp
5+
# https://github.com/catchorg/Catch2/releases/tag/v3.6.0
66
#
77
# The following changes were made to always print in microseconds, fixed format:
88
#
@@ -12,6 +12,7 @@
1212
# - return os << duration.value() << ' ' << duration.unitsAsString();
1313
# + return os << std::fixed << duration.value() << ' ' << duration.unitsAsString();
1414

15-
add_library(catch2 INTERFACE)
15+
add_library(catch2 STATIC catch_amalgamated.cpp)
16+
target_compile_definitions(catch2 PRIVATE CATCH_CONFIG_NOSTDOUT CATCH_AMALGAMATED_CUSTOM_MAIN)
1617
add_library(Catch2::Catch2 ALIAS catch2)
1718
target_include_directories(catch2 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")

lib/catch2/catch_amalgamated.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8952,7 +8952,7 @@ class Duration {
89528952
Unit m_units;
89538953

89548954
public:
8955-
explicit Duration(double inNanoseconds, Unit units = Unit::Auto)
8955+
explicit Duration(double inNanoseconds, Unit units = Unit::Microseconds)
89568956
: m_inNanoseconds(inNanoseconds),
89578957
m_units(units) {
89588958
if (m_units == Unit::Auto) {
@@ -9002,7 +9002,7 @@ class Duration {
90029002

90039003
}
90049004
friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& {
9005-
return os << duration.value() << ' ' << duration.unitsAsString();
9005+
return os << std::fixed << duration.value() << ' ' << duration.unitsAsString();
90069006
}
90079007
};
90089008
} // end anon namespace

src/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,10 @@ if(BUILD_BENCHMARKS)
474474
set(common_SRCS ${common_SRCS} ${BENCHMARK_SRCS})
475475
endif()
476476

477+
if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
478+
set(common_SRCS ${common_SRCS} catch.cpp)
479+
endif()
480+
477481
# This gives us the icon and file version information
478482
if(WIN32)
479483
set(WINRESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../misc/winresource.rc")

src/benchmark/benchmark.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#include "benchmark/benchmark.h"
2121

22-
// This must be set in just this file
23-
#define CATCH_CONFIG_RUNNER
24-
#include "benchmark_setup.h"
22+
#define CATCH_CONFIG_ENABLE_BENCHMARKING
23+
#include "catch.h"
2524

2625
bool run_benchmarks(const char *arg)
2726
{

src/benchmark/benchmark_activeobjectmgr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Minetest
22
// SPDX-License-Identifier: LGPL-2.1-or-later
33

4-
#include "benchmark_setup.h"
4+
#include "catch.h"
55
#include "server/activeobjectmgr.h"
66
#include "util/numeric.h"
77

src/benchmark/benchmark_lighting.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
1919

20-
#include "benchmark_setup.h"
20+
#include "catch.h"
2121
#include "voxelalgorithms.h"
2222
#include "dummygamedef.h"
2323
#include "dummymap.h"

src/benchmark/benchmark_mapblock.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
1919

20-
#include "benchmark_setup.h"
20+
#include "catch.h"
2121
#include "mapblock.h"
2222
#include <vector>
2323

src/benchmark/benchmark_mapmodify.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
1919

20-
#include "benchmark_setup.h"
20+
#include "catch.h"
2121
#include "util/container.h"
2222

2323
// Testing the standard library is not useful except to compare

src/benchmark/benchmark_serialize.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
1919

20-
#include "benchmark_setup.h"
20+
#include "catch.h"
2121
#include "util/serialize.h"
2222
#include <sstream>
2323
#include <ios>

src/benchmark/benchmark_setup.h

-22
This file was deleted.

src/catch.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Minetest
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
#include "catch.h"
5+
6+
#include "log.h"
7+
8+
namespace Catch {
9+
std::ostream& cout() {
10+
return rawstream;
11+
}
12+
std::ostream& clog() {
13+
return rawstream;
14+
}
15+
std::ostream& cerr() {
16+
return rawstream;
17+
}
18+
}

src/catch.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Minetest
2+
// SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
// We want to have catch write to rawstream (stderr) instead of stdout.
5+
// This should be included instead of <catch_amalgamated.hpp>
6+
// to patch the output streams accordingly.
7+
#define CATCH_CONFIG_NOSTDOUT
8+
#include <catch_amalgamated.hpp>
9+
10+
namespace Catch {
11+
std::ostream& cout();
12+
std::ostream& clog();
13+
std::ostream& cerr();
14+
}

src/unittest/test.cpp

+10-19
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1717
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1818
*/
1919

20-
#define CATCH_CONFIG_RUNNER
21-
// we want to have catch write to rawstream (stderr) instead of stdout
22-
#define CATCH_CONFIG_NOSTDOUT
23-
#include <catch.hpp>
20+
#include "catch.h"
2421

2522
#include "test.h"
2623

@@ -34,18 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3431

3532
#include <iostream>
3633

37-
// make catch write everything to rawstream
38-
namespace Catch {
39-
std::ostream& cout() {
40-
return rawstream;
41-
}
42-
std::ostream& clog() {
43-
return rawstream;
44-
}
45-
std::ostream& cerr() {
46-
return rawstream;
47-
}
48-
}
34+
#include "catch.h"
4935

5036
content_t t_CONTENT_STONE;
5137
content_t t_CONTENT_GRASS;
@@ -255,11 +241,16 @@ bool run_tests()
255241
}
256242

257243
rawstream << "Catch test results: " << std::endl;
258-
auto num_catch_tests_failed = Catch::Session().run();
259-
// We count the all the Catch tests as one test for Minetest's own logging
244+
Catch::Session session{};
245+
auto config = session.configData();
246+
config.skipBenchmarks = true;
247+
config.allowZeroTests = true;
248+
session.useConfigData(config);
249+
auto exit_code = session.run();
250+
// We count all the Catch tests as one test for Minetest's own logging
260251
// because we don't have a way to tell how many individual tests Catch ran.
261252
++num_total_tests_run;
262-
if (num_catch_tests_failed > 0) {
253+
if (exit_code != 0) {
263254
++num_modules_failed;
264255
++num_total_tests_failed;
265256
}

src/unittest/test_clientactiveobjectmgr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2121

2222
#include "client/activeobjectmgr.h"
2323

24-
#include <catch.hpp>
24+
#include "catch.h"
2525

2626
#include <unordered_set>
2727
#include <utility>

0 commit comments

Comments
 (0)