Merge pull request #2 from szymon-jozef/refactor/tests

Moved tests into it's own directory for better readability"
This commit is contained in:
Szymon
2026-01-06 18:15:59 +01:00
committed by GitHub
8 changed files with 65 additions and 17 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
out/
posts/
src/tests/tests
*.o

View File

@@ -80,7 +80,7 @@ From there you can rsync/push it to your server or do whatever you want to do wi
# How does the directory structure work?
Also pretty simple. You have:
- `/config` for config files. Initially empty so you need to copy it from example dir or make one yourself.
- `/examples` example of configuration files. Tests are dependent on it so don't edit the content of these files! You can copy it to `/config` and edit it there.
- `/examples` example of configuration files. You can copy it to `/config` and edit it there.
- `/out` for processed site.
- `/posts` here you write your blog posts. Every file should be in markdown format, metadata included!.
- `/src` for cpp files. Here's where you run the binary to translate your markdown posts into html.

View File

@@ -2,6 +2,7 @@ CXX = g++
CXXFLAGS = -std=c++17 -Wall
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
LIBS = -lmd4c-html
TEST_DIR = tests
all: blog
@@ -20,14 +21,14 @@ utils.o: utils.cpp utils.hpp
markdown.o: markdown.cpp markdown.hpp
$(CXX) $(CXXFLAGS) -c markdown.cpp
tests: tests.o config.o utils.o markdown.o
g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o tests $(TEST_LIBS)
tests.o: $(TEST_DIR)/tests.cpp config.hpp
$(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp
tests.o: tests.cpp config.hpp
$(CXX) $(CXXFLAGS) -c tests.cpp
tests: tests.o config.o utils.o markdown.o
g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o -o $(TEST_DIR)/tests $(TEST_LIBS)
check: tests
./tests
$(TEST_DIR)/tests
clean:
rm -f *.o blog tests
rm -f *.o $(TEST_DIR)/*.o blog $(TEST_DIR)/tests

8
src/tests/config.toml Normal file
View File

@@ -0,0 +1,8 @@
[general]
lang = "en"
title = "Blog"
[contact]
author = "author"
email = "email@example.com"
signal = "signal url"

BIN
src/tests/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 KiB

41
src/tests/post.md Normal file
View File

@@ -0,0 +1,41 @@
---
author: "joseph"
date: "2026-01-01"
title: "Example of a blog post"
tags: ["blog", "test", "lalilulelo"]
---
# This is an example post
In this example we will do a couple of cool markdown things.
## This is a h2 header
*This text is written in italic!*
### Look at this!
**This text is BOLD!**
## Hello world!
```cpp
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
}
```
This is super cool!
## Time to link some random website!
This [should be clickable](https://example.com)
## Image test
![this should show an image](./image.png)
## This is an ordered list
1. one
2. six
3. seven
## This is an unordered one
- six
- nine
- six
- nine

View File

@@ -1,13 +1,13 @@
#include "config.hpp"
#include "markdown.hpp"
#include "utils.hpp"
#include "../config.hpp"
#include "../markdown.hpp"
#include "../utils.hpp"
#include <catch2/catch_all.hpp>
#include <catch2/catch_test_macros.hpp>
#include <optional>
#include <string>
TEST_CASE("Checking config file read", "[config]") {
const std::string FILE_NAME = "../examples/config.toml";
const std::string FILE_NAME = "tests/config.toml";
Config config = get_config(FILE_NAME);
@@ -25,7 +25,7 @@ TEST_CASE("convert_string_to_set parses inline YAML string list") {
}
TEST_CASE("get_metadata function data correctness test") {
const std::string FILE_NAME = "../examples/post.md";
const std::string FILE_NAME = "./tests//post.md";
Metadata result = get_metadata(FILE_NAME).value();
std::string expected_author = "joseph";
@@ -43,16 +43,13 @@ TEST_CASE("get_metadata function data correctness test") {
}
TEST_CASE("get_metadata function test with a file that doesn't have metadata") {
const std::string FILE_NAME = "../examples/no_metadata_post.md";
const std::string FILE_NAME = ".tests/no_metadata_post.md";
std::optional<Metadata> result = get_metadata(FILE_NAME);
REQUIRE(result == std::nullopt);
}
/* theres to much testing stuff in examples
* i need to move tests to some other directory with testing files
*/
TEST_CASE("get_html function parsing test") {
const std::string INPUT = "../examples/post.md";
const std::string INPUT = "./tests/post.md";
const std::string EXPECTED_OUTPUT = R"HTML(<h1>This is an example post</h1>
<p>In this example we will do a couple of cool markdown things.</p>
<h2>This is a h2 header</h2>