Added unit testing with Catch2 framework

This commit is contained in:
2025-12-31 13:54:04 +01:00
parent abf9f1fa31
commit 7f98a33d7e
3 changed files with 23 additions and 10 deletions

View File

@@ -3,12 +3,3 @@
#include <string>
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;
}

View File

@@ -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

13
src/tests.cpp Normal file
View File

@@ -0,0 +1,13 @@
#include "config.hpp"
#include <catch2/catch_all.hpp>
#include <string>
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");
}