Corresponding code changes

This commit is contained in:
Lars Mueller 2024-06-07 17:58:36 +02:00 committed by Lars Müller
parent 781c7a800f
commit ae4cd1ebf1
14 changed files with 60 additions and 55 deletions

@ -1,8 +1,8 @@
# catch2 is distributed as a standalone header.
# catch2 is distributed as a standalone header / source amalgamation.
#
# Downloaded from:
#
# https://github.com/catchorg/Catch2/releases/download/v2.13.9/catch.hpp
# https://github.com/catchorg/Catch2/releases/tag/v3.6.0
#
# The following changes were made to always print in microseconds, fixed format:
#
@ -12,6 +12,7 @@
# - return os << duration.value() << ' ' << duration.unitsAsString();
# + return os << std::fixed << duration.value() << ' ' << duration.unitsAsString();
add_library(catch2 INTERFACE)
add_library(catch2 STATIC catch_amalgamated.cpp)
target_compile_definitions(catch2 PRIVATE CATCH_CONFIG_NOSTDOUT CATCH_AMALGAMATED_CUSTOM_MAIN)
add_library(Catch2::Catch2 ALIAS catch2)
target_include_directories(catch2 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}")

@ -8952,7 +8952,7 @@ class Duration {
Unit m_units;
public:
explicit Duration(double inNanoseconds, Unit units = Unit::Auto)
explicit Duration(double inNanoseconds, Unit units = Unit::Microseconds)
: m_inNanoseconds(inNanoseconds),
m_units(units) {
if (m_units == Unit::Auto) {
@ -9002,7 +9002,7 @@ public:
}
friend auto operator << (std::ostream& os, Duration const& duration) -> std::ostream& {
return os << duration.value() << ' ' << duration.unitsAsString();
return os << std::fixed << duration.value() << ' ' << duration.unitsAsString();
}
};
} // end anon namespace

@ -474,6 +474,10 @@ if(BUILD_BENCHMARKS)
set(common_SRCS ${common_SRCS} ${BENCHMARK_SRCS})
endif()
if(BUILD_UNITTESTS OR BUILD_BENCHMARKS)
set(common_SRCS ${common_SRCS} catch.cpp)
endif()
# This gives us the icon and file version information
if(WIN32)
set(WINRESOURCE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../misc/winresource.rc")

@ -19,9 +19,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "benchmark/benchmark.h"
// This must be set in just this file
#define CATCH_CONFIG_RUNNER
#include "benchmark_setup.h"
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#include "catch.h"
bool run_benchmarks(const char *arg)
{

@ -1,7 +1,7 @@
// Minetest
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "benchmark_setup.h"
#include "catch.h"
#include "server/activeobjectmgr.h"
#include "util/numeric.h"

@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "benchmark_setup.h"
#include "catch.h"
#include "voxelalgorithms.h"
#include "dummygamedef.h"
#include "dummymap.h"

@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "benchmark_setup.h"
#include "catch.h"
#include "mapblock.h"
#include <vector>

@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "benchmark_setup.h"
#include "catch.h"
#include "util/container.h"
// Testing the standard library is not useful except to compare

@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "benchmark_setup.h"
#include "catch.h"
#include "util/serialize.h"
#include <sstream>
#include <ios>

@ -1,22 +0,0 @@
/*
Minetest
Copyright (C) 2022 Minetest Authors
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define CATCH_CONFIG_ENABLE_BENCHMARKING
#define CATCH_CONFIG_CONSOLE_WIDTH 160
#include <catch.hpp>

18
src/catch.cpp Normal file

@ -0,0 +1,18 @@
// Minetest
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "catch.h"
#include "log.h"
namespace Catch {
std::ostream& cout() {
return rawstream;
}
std::ostream& clog() {
return rawstream;
}
std::ostream& cerr() {
return rawstream;
}
}

14
src/catch.h Normal file

@ -0,0 +1,14 @@
// Minetest
// SPDX-License-Identifier: LGPL-2.1-or-later
// We want to have catch write to rawstream (stderr) instead of stdout.
// This should be included instead of <catch_amalgamated.hpp>
// to patch the output streams accordingly.
#define CATCH_CONFIG_NOSTDOUT
#include <catch_amalgamated.hpp>
namespace Catch {
std::ostream& cout();
std::ostream& clog();
std::ostream& cerr();
}

@ -17,10 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define CATCH_CONFIG_RUNNER
// we want to have catch write to rawstream (stderr) instead of stdout
#define CATCH_CONFIG_NOSTDOUT
#include <catch.hpp>
#include "catch.h"
#include "test.h"
@ -34,18 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <iostream>
// make catch write everything to rawstream
namespace Catch {
std::ostream& cout() {
return rawstream;
}
std::ostream& clog() {
return rawstream;
}
std::ostream& cerr() {
return rawstream;
}
}
#include "catch.h"
content_t t_CONTENT_STONE;
content_t t_CONTENT_GRASS;
@ -255,11 +241,16 @@ bool run_tests()
}
rawstream << "Catch test results: " << std::endl;
auto num_catch_tests_failed = Catch::Session().run();
// We count the all the Catch tests as one test for Minetest's own logging
Catch::Session session{};
auto config = session.configData();
config.skipBenchmarks = true;
config.allowZeroTests = true;
session.useConfigData(config);
auto exit_code = session.run();
// We count all the Catch tests as one test for Minetest's own logging
// because we don't have a way to tell how many individual tests Catch ran.
++num_total_tests_run;
if (num_catch_tests_failed > 0) {
if (exit_code != 0) {
++num_modules_failed;
++num_total_tests_failed;
}

@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/activeobjectmgr.h"
#include <catch.hpp>
#include "catch.h"
#include <unordered_set>
#include <utility>