From 08c0a3b50b879cdda54225f1c9f121ca9c3165cc Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Sun, 2 Feb 2025 16:37:59 +0100 Subject: [PATCH] added test support to the makefile --- cpp/.gitignore | 1 + cpp/Makefile | 26 +++++++++++++++++++++++++- cpp/src/main.cpp | 4 ---- cpp/tests/fen.cpp | 2 +- 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cpp/.gitignore b/cpp/.gitignore index e46b6c0..24f7267 100644 --- a/cpp/.gitignore +++ b/cpp/.gitignore @@ -30,3 +30,4 @@ *.exe *.out *.appobj/ +test_bin/ diff --git a/cpp/Makefile b/cpp/Makefile index 2af4a19..50c8770 100644 --- a/cpp/Makefile +++ b/cpp/Makefile @@ -29,4 +29,28 @@ main: $(OBJFILES) $(CXX) $(LDFLAGS) $(OBJFILES) $(LOADLIBES) $(LDLIBS) -o main clean: - rm -rf obj/* $(DEPFILES) + rm -rf obj/* $(DEPFILES) test_bin/ + + +# --- Test Support --- +# Find all test source files in the tests directory +TESTS := $(shell find tests -name "*.cpp") +# Define corresponding test executable names, e.g. tests/foo.cpp -> test_bin/foo +TEST_BIN := $(patsubst tests/%.cpp,test_bin/%,$(TESTS)) +LIBS := $(filter-out obj/main.o,$(OBJFILES)) + +# Pattern rule: how to build a test executable from a test source file. +# You can adjust CXXFLAGS or add include directories if needed. +test_bin/%: tests/%.cpp $(LIBS) + @echo $(LIBS) + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -o $@ $< $(LIBS) + +# The 'test' target builds all tests and then runs each one. +.PHONY: test +test: $(TEST_BIN) + @echo "Running all tests..." + @for t in $(TEST_BIN); do \ + echo "---- Running $$t ----"; \ + ./$$t || exit 1; \ + done diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index 41af89f..80a45dc 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -7,10 +7,6 @@ int main(int argc, char* argv[]) { "rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8"; Board* b = Board::setup_fen_position(pos); - std::cout << sizeof(Board) << std::endl; - std::cout << sizeof(int8_t[64]) << std::endl; - std::cout << sizeof(Colour) << std::endl; - std::string fen = b->to_fen(); std::cout << pos << std::endl; diff --git a/cpp/tests/fen.cpp b/cpp/tests/fen.cpp index 6477926..e2f6675 100644 --- a/cpp/tests/fen.cpp +++ b/cpp/tests/fen.cpp @@ -1,4 +1,4 @@ -#include "../board.hpp" +#include "../src/board.hpp" #include "lib.hpp" int main() {