1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-27 17:28:41 +00:00

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

View file

@ -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")

View file

@ -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)
{

View file

@ -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"

View file

@ -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"

View file

@ -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>

View file

@ -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

View file

@ -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>

View file

@ -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
View 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
View 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();
}

View file

@ -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;
}

View file

@ -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>