Move the tests to catch2 so I can get tap output for the game.

This commit is contained in:
Zed A. Shaw 2024-08-10 06:59:28 -04:00
parent 1fb99618bf
commit 52b59d38ad
5 changed files with 16 additions and 16 deletions

View file

@ -20,7 +20,7 @@ fmt = dependency('fmt')
ftxui_screen = dependency('ftxui-screen') ftxui_screen = dependency('ftxui-screen')
ftxui_dom = dependency('ftxui-dom') ftxui_dom = dependency('ftxui-dom')
ftxui_component = dependency('ftxui-component') ftxui_component = dependency('ftxui-component')
doctest = dependency('doctest') catch2 = dependency('catch2-with-main')
dependencies = [ dependencies = [
fmt, libgit2package_dep, efsw_dep, fmt, libgit2package_dep, efsw_dep,
@ -43,8 +43,7 @@ executable('ftx_thread_test', 'ftx_thread_test.cpp',
runtests = executable('runtests', [ runtests = executable('runtests', [
'game_engine.cpp', 'game_engine.cpp',
'tests/test1.cpp',
'tests/game_engine.cpp'], 'tests/game_engine.cpp'],
dependencies: dependencies + [doctest]) dependencies: dependencies + [catch2])
test('the tests', runtests) test('the tests', runtests)

View file

@ -9,6 +9,7 @@ meson wrap install fmt
meson wrap install sqlite3 meson wrap install sqlite3
meson wrap install sqlitecpp meson wrap install sqlitecpp
meson wrap install ftxui meson wrap install ftxui
meson wrap install catch2
# $env:CC="clang" # $env:CC="clang"
# $env:CXX="clang++" # $env:CXX="clang++"
meson setup --default-library=static --prefer-static builddir meson setup --default-library=static --prefer-static builddir

View file

@ -11,4 +11,5 @@ meson wrap install fmt
meson wrap install sqlite3 meson wrap install sqlite3
meson wrap install sqlitecpp meson wrap install sqlitecpp
meson wrap install ftxui meson wrap install ftxui
meson wrap install catch2
meson setup builddir meson setup builddir

View file

@ -1,7 +1,7 @@
#include <doctest.h> #include <catch2/catch_test_macros.hpp>
#include "../game_engine.hpp" #include "../game_engine.hpp"
TEST_CASE("brainfuck test") { TEST_CASE("brainfuck test", "[brainfuck]") {
Brainfucker bf; Brainfucker bf;
string code{"+.>+.>+.>"}; string code{"+.>+.>+.>"};
@ -10,23 +10,23 @@ TEST_CASE("brainfuck test") {
// this is actually ticks, not code length // this is actually ticks, not code length
bf.run(code.size()); bf.run(code.size());
CHECK(bf.data[0] == 1); REQUIRE(bf.data[0] == 1);
CHECK(bf.data[1] == 1); REQUIRE(bf.data[1] == 1);
CHECK(bf.data[2] == 1); REQUIRE(bf.data[2] == 1);
bf.reset(); bf.reset();
CHECK(bf.data[0] == 0); REQUIRE(bf.data[0] == 0);
CHECK(bf.data[1] == 0); REQUIRE(bf.data[1] == 0);
CHECK(bf.data[2] == 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 // test fails on purpose right now
GameEngine game{4}; GameEngine game{4};
string err{"error"}; string err{"error"};
game.hit(err); game.hit(err);
CHECK(game.is_dead() == true); REQUIRE(game.is_dead() == true);
} }

View file

@ -1,5 +1,4 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include <catch2/catch_test_macros.hpp>
#include <doctest.h>
int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; } int factorial(int number) { return number <= 1 ? number : factorial(number - 1) * number; }