From 52b59d38ad5b4a004997b22cd4218019c14a98d9 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sat, 10 Aug 2024 06:59:28 -0400 Subject: [PATCH] Move the tests to catch2 so I can get tap output for the game. --- meson.build | 5 ++--- scripts/reset_build.ps1 | 1 + scripts/reset_build.sh | 1 + tests/game_engine.cpp | 22 +++++++++++----------- tests/test1.cpp | 3 +-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/meson.build b/meson.build index b467296..73e5c78 100644 --- a/meson.build +++ b/meson.build @@ -20,7 +20,7 @@ fmt = dependency('fmt') ftxui_screen = dependency('ftxui-screen') ftxui_dom = dependency('ftxui-dom') ftxui_component = dependency('ftxui-component') -doctest = dependency('doctest') +catch2 = dependency('catch2-with-main') dependencies = [ fmt, libgit2package_dep, efsw_dep, @@ -43,8 +43,7 @@ executable('ftx_thread_test', 'ftx_thread_test.cpp', runtests = executable('runtests', [ 'game_engine.cpp', - 'tests/test1.cpp', 'tests/game_engine.cpp'], - dependencies: dependencies + [doctest]) + dependencies: dependencies + [catch2]) test('the tests', runtests) diff --git a/scripts/reset_build.ps1 b/scripts/reset_build.ps1 index 75d8515..4f326ec 100644 --- a/scripts/reset_build.ps1 +++ b/scripts/reset_build.ps1 @@ -9,6 +9,7 @@ meson wrap install fmt meson wrap install sqlite3 meson wrap install sqlitecpp meson wrap install ftxui +meson wrap install catch2 # $env:CC="clang" # $env:CXX="clang++" meson setup --default-library=static --prefer-static builddir diff --git a/scripts/reset_build.sh b/scripts/reset_build.sh index 3a35aa3..6bd417c 100644 --- a/scripts/reset_build.sh +++ b/scripts/reset_build.sh @@ -11,4 +11,5 @@ meson wrap install fmt meson wrap install sqlite3 meson wrap install sqlitecpp meson wrap install ftxui +meson wrap install catch2 meson setup builddir diff --git a/tests/game_engine.cpp b/tests/game_engine.cpp index 50e5805..e39f786 100644 --- a/tests/game_engine.cpp +++ b/tests/game_engine.cpp @@ -1,7 +1,7 @@ -#include +#include #include "../game_engine.hpp" -TEST_CASE("brainfuck test") { +TEST_CASE("brainfuck test", "[brainfuck]") { Brainfucker bf; string code{"+.>+.>+.>"}; @@ -10,23 +10,23 @@ TEST_CASE("brainfuck test") { // this is actually ticks, not code length bf.run(code.size()); - CHECK(bf.data[0] == 1); - CHECK(bf.data[1] == 1); - CHECK(bf.data[2] == 1); + REQUIRE(bf.data[0] == 1); + REQUIRE(bf.data[1] == 1); + REQUIRE(bf.data[2] == 1); bf.reset(); - CHECK(bf.data[0] == 0); - CHECK(bf.data[1] == 0); - CHECK(bf.data[2] == 0); + REQUIRE(bf.data[0] == 0); + REQUIRE(bf.data[1] == 0); + REQUIRE(bf.data[2] == 0); - CHECK(bf.code.empty()); + REQUIRE(bf.code.empty()); } -TEST_CASE("game engine can start and take hit") { +TEST_CASE("game engine can start and take hit", "[brainfuck]") { // test fails on purpose right now GameEngine game{4}; string err{"error"}; game.hit(err); - CHECK(game.is_dead() == true); + REQUIRE(game.is_dead() == true); } diff --git a/tests/test1.cpp b/tests/test1.cpp index c4aa842..99c61a9 100644 --- a/tests/test1.cpp +++ b/tests/test1.cpp @@ -1,5 +1,4 @@ -#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include +#include int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; }