From 7f98a33d7e48d3ecd0885a884ddddf5544bc7f9d Mon Sep 17 00:00:00 2001 From: Szymon P Date: Wed, 31 Dec 2025 13:54:04 +0100 Subject: [PATCH] Added unit testing with Catch2 framework --- src/main.cpp | 9 --------- src/makefile | 11 ++++++++++- src/tests.cpp | 13 +++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 src/tests.cpp diff --git a/src/main.cpp b/src/main.cpp index 05f0262..bf4c9e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,12 +3,3 @@ #include int main() { return 0; } - -void test_config_read() { - const std::string CONFIG_PATH = "../config/config_example.toml"; - Config config = get_config(CONFIG_PATH); - std::cout << "Config" << std::endl; - std::cout << "Author: " << config.contact.author << std::endl; - std::cout << "Email: " << config.contact.email << std::endl; - std::cout << "Signal: " << config.contact.signal << std::endl; -} diff --git a/src/makefile b/src/makefile index 85c9f51..e7a8320 100644 --- a/src/makefile +++ b/src/makefile @@ -12,5 +12,14 @@ main.o: main.cpp config.hpp config.o: config.cpp config.hpp $(CXX) $(CXXFLAGS) -c config.cpp +tests: tests.o config.o + g++ -std=c++17 -Wall tests.o config.o -o tests -lCatch2Main -lCatch2 + +tests.o: tests.cpp config.hpp + $(CXX) $(CXXFLAGS) -c tests.cpp + +check: tests + ./tests + clean: - rm -f *.o blog + rm -f *.o blog tests diff --git a/src/tests.cpp b/src/tests.cpp new file mode 100644 index 0000000..5a6f567 --- /dev/null +++ b/src/tests.cpp @@ -0,0 +1,13 @@ +#include "config.hpp" +#include +#include + +TEST_CASE("Checking config file read", "[config]") { + const std::string FILE_NAME = "../config/config_example.toml"; + + Config config = get_config(FILE_NAME); + + REQUIRE(config.contact.author == "author"); + REQUIRE(config.contact.email == "email@example.com"); + REQUIRE(config.contact.signal == "signal url"); +}