mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Upgrade client active object mgr tests to Catch2 (#14565)
* Upgrade client active object mgr tests to Catch2 In addition to invoking Catch2's test runner after Minetest's homemade runner, this refactors the tests to follow the DRY principle, and gives them expressive names and clear assertions. Catch2 is already bundled with Minetest, so there are no added dependencies. * Increment failed modules count for Catch2 tests * Respect --test-module option for Catch2 tests * Improve Catch2 --test-module behavior This switches infostream to rawstream so that test runner output is displayed, and returns the correct boolean depending on the results. The tests are now found by setting the configuration instead of invoking the command line parser. * Test uniqueness of all IDS instead of just one Co-Authored-By: Lars Müller <appgurulars@gmx.de> * Include Catch2 test run in timing and logging * Flush std::cout after printing Catch results * Increment total tests run instead of hardcoding to 1 * Flush stderr before printing to stdout It's necessary to flush stderr before printing to stdout in adition to flushing stdout before printing to stderr, to make sure all output is ordered correctly. * Make Catch write to rawstream --------- Co-authored-by: Lars Müller <appgurulars@gmx.de>
This commit is contained in:
parent
a078cfee3e
commit
1298374818
6 changed files with 101 additions and 69 deletions
|
@ -17,6 +17,11 @@ 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 "test.h"
|
||||
|
||||
#include "nodedef.h"
|
||||
|
@ -27,6 +32,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "porting.h"
|
||||
#include "debug.h"
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
content_t t_CONTENT_STONE;
|
||||
content_t t_CONTENT_GRASS;
|
||||
content_t t_CONTENT_TORCH;
|
||||
|
@ -234,6 +254,16 @@ bool run_tests()
|
|||
num_total_tests_run += testmod->num_tests_run;
|
||||
}
|
||||
|
||||
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
|
||||
// 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) {
|
||||
++num_modules_failed;
|
||||
++num_total_tests_failed;
|
||||
}
|
||||
|
||||
u64 tdiff = porting::getTimeMs() - t1;
|
||||
|
||||
g_logger.setLevelSilenced(LL_ERROR, false);
|
||||
|
@ -269,8 +299,11 @@ bool run_tests(const std::string &module_name)
|
|||
|
||||
auto testmod = findTestModule(module_name);
|
||||
if (!testmod) {
|
||||
errorstream << "Test module not found: " << module_name << std::endl;
|
||||
return 1;
|
||||
rawstream << "Did not find module, searching Catch tests: " << module_name << std::endl;
|
||||
Catch::Session session;
|
||||
session.configData().testsOrTags.push_back(module_name);
|
||||
auto catch_test_failures = session.run();
|
||||
return catch_test_failures == 0;
|
||||
}
|
||||
|
||||
g_logger.setLevelSilenced(LL_ERROR, true);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue