diff --git a/.gitignore b/.gitignore index 327fac9..c528bab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ out/ posts/ -src/tests/tests +src/build/ +/src/blog +/src/tests *.o diff --git a/src/compile_commands.json b/src/compile_commands.json new file mode 100644 index 0000000..afaf30c --- /dev/null +++ b/src/compile_commands.json @@ -0,0 +1,74 @@ +[ + { + "file": "main.cpp", + "arguments": [ + "g++", + "-std=c++17", + "-Wall", + "-Wextra", + "-O2", + "-I", + ".", + "-c", + "main.cpp", + "-o", + "build/main.o" + ], + "directory": "/home/szymon/Dokumenty/kodowanie/blog/src", + "output": "build/main.o" + }, + { + "file": "config/config.cpp", + "arguments": [ + "g++", + "-std=c++17", + "-Wall", + "-Wextra", + "-O2", + "-I", + ".", + "-c", + "config/config.cpp", + "-o", + "build/config/config.o" + ], + "directory": "/home/szymon/Dokumenty/kodowanie/blog/src", + "output": "build/config/config.o" + }, + { + "file": "format/format.cpp", + "arguments": [ + "g++", + "-std=c++17", + "-Wall", + "-Wextra", + "-O2", + "-I", + ".", + "-c", + "format/format.cpp", + "-o", + "build/format/format.o" + ], + "directory": "/home/szymon/Dokumenty/kodowanie/blog/src", + "output": "build/format/format.o" + }, + { + "file": "markdown/markdown.cpp", + "arguments": [ + "g++", + "-std=c++17", + "-Wall", + "-Wextra", + "-O2", + "-I", + ".", + "-c", + "markdown/markdown.cpp", + "-o", + "build/markdown/markdown.o" + ], + "directory": "/home/szymon/Dokumenty/kodowanie/blog/src", + "output": "build/markdown/markdown.o" + } +] \ No newline at end of file diff --git a/src/config.cpp b/src/config/config.cpp similarity index 100% rename from src/config.cpp rename to src/config/config.cpp diff --git a/src/config.hpp b/src/config/config.hpp similarity index 100% rename from src/config.hpp rename to src/config/config.hpp diff --git a/src/formatter.cpp b/src/format/format.cpp similarity index 95% rename from src/formatter.cpp rename to src/format/format.cpp index c71408f..5bf4f23 100644 --- a/src/formatter.cpp +++ b/src/format/format.cpp @@ -1,4 +1,4 @@ -#include "markdown.hpp" +#include "markdown/markdown.hpp" #include #include #include diff --git a/src/formatter.hpp b/src/format/format.hpp similarity index 100% rename from src/formatter.hpp rename to src/format/format.hpp diff --git a/src/main.cpp b/src/main.cpp index bf4c9e4..c03f3d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "config.hpp" +#include "config/config.hpp" #include #include diff --git a/src/makefile b/src/makefile index ad44c4f..d921679 100644 --- a/src/makefile +++ b/src/makefile @@ -1,37 +1,51 @@ CXX = g++ -CXXFLAGS = -std=c++17 -Wall -TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2 +CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -I . LIBS = -lmd4c-html -TEST_DIR = tests +TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2 -all: blog +BUILD_DIR = build -blog: main.o config.o utils.o - $(CXX) $(CXXFLAGS) main.o config.o -o blog $(LIBS) +SOURCES = main.cpp \ + config/config.cpp \ + format/format.cpp \ + markdown/markdown.cpp -main.o: main.cpp config.hpp - $(CXX) $(CXXFLAGS) -c main.cpp +OBJECTS = $(SOURCES:%.cpp=$(BUILD_DIR)/%.o) -config.o: config.cpp config.hpp - $(CXX) $(CXXFLAGS) -c config.cpp +TEST_SOURCES = tests.cpp \ + config/config.cpp \ + format/format.cpp \ + markdown/markdown.cpp -utils.o: utils.cpp utils.hpp - $(CXX) $(CXXFLAGS) -c utils.cpp +TEST_OBJECTS = $(TEST_SOURCES:%.cpp=$(BUILD_DIR)/%.o) -markdown.o: markdown.cpp markdown.hpp - $(CXX) $(CXXFLAGS) -c markdown.cpp +TARGET = blog +TEST_TARGET = tests -formatter.o: formatter.cpp formatter.hpp - $(CXX) $(CXXFLAGS) -c formatter.cpp +.PHONY: all clean test directories -tests.o: $(TEST_DIR)/tests.cpp config.hpp - $(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp +all: directories $(TARGET) -tests: tests.o config.o utils.o markdown.o formatter.o - g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o formatter.o -o $(TEST_DIR)/tests $(TEST_LIBS) +directories: + @mkdir -p $(BUILD_DIR)/config + @mkdir -p $(BUILD_DIR)/format + @mkdir -p $(BUILD_DIR)/markdown -check: tests - $(TEST_DIR)/tests +$(TARGET): $(OBJECTS) + $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) + +$(TEST_TARGET): $(TEST_OBJECTS) + $(CXX) $(CXXFLAGS) -o $@ $^ $(TEST_LIBS) + +$(BUILD_DIR)/%.o: %.cpp + @mkdir -p $(dir $@) + $(CXX) $(CXXFLAGS) -c $< -o $@ + +test: directories $(TEST_TARGET) + ./$(TEST_TARGET) clean: - rm -f *.o $(TEST_DIR)/*.o blog $(TEST_DIR)/tests + rm -rf $(BUILD_DIR) + rm -f $(TARGET) $(TEST_TARGET) + +rebuild: clean all diff --git a/src/markdown.cpp b/src/markdown/markdown.cpp similarity index 99% rename from src/markdown.cpp rename to src/markdown/markdown.cpp index 93484ac..34bf0c5 100644 --- a/src/markdown.cpp +++ b/src/markdown/markdown.cpp @@ -1,5 +1,4 @@ #include "markdown.hpp" -#include "utils.hpp" #include #include #include diff --git a/src/markdown.hpp b/src/markdown/markdown.hpp similarity index 100% rename from src/markdown.hpp rename to src/markdown/markdown.hpp diff --git a/src/tests/config.toml b/src/test_files/config.toml similarity index 100% rename from src/tests/config.toml rename to src/test_files/config.toml diff --git a/src/tests/formatter.html b/src/test_files/formatter.html similarity index 100% rename from src/tests/formatter.html rename to src/test_files/formatter.html diff --git a/src/tests/image.png b/src/test_files/image.png similarity index 100% rename from src/tests/image.png rename to src/test_files/image.png diff --git a/src/tests/no_metadata_post.md b/src/test_files/no_metadata_post.md similarity index 100% rename from src/tests/no_metadata_post.md rename to src/test_files/no_metadata_post.md diff --git a/src/tests/post.md b/src/test_files/post.md similarity index 100% rename from src/tests/post.md rename to src/test_files/post.md diff --git a/src/tests/tests.cpp b/src/tests.cpp similarity index 87% rename from src/tests/tests.cpp rename to src/tests.cpp index 2daa9b1..b0eb144 100644 --- a/src/tests/tests.cpp +++ b/src/tests.cpp @@ -1,7 +1,6 @@ -#include "../config.hpp" -#include "../formatter.hpp" -#include "../markdown.hpp" -#include "../utils.hpp" +#include "config/config.hpp" +#include "format/format.hpp" +#include "markdown/markdown.hpp" #include #include #include @@ -9,7 +8,7 @@ #include TEST_CASE("Checking config file read", "[config]") { - const std::string FILE_NAME = "tests/config.toml"; + const std::string FILE_NAME = "test_files/config.toml"; Config config = get_config(FILE_NAME); @@ -21,7 +20,7 @@ TEST_CASE("Checking config file read", "[config]") { } TEST_CASE("get_metadata function data correctness test") { - const std::string FILE_NAME = "./tests/post.md"; + const std::string FILE_NAME = "./test_files/post.md"; Metadata result = get_metadata(FILE_NAME).value(); std::string expected_author = "joseph"; @@ -42,13 +41,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 = ".tests/no_metadata_post.md"; + const std::string FILE_NAME = ".test_files/no_metadata_post.md"; std::optional result = get_metadata(FILE_NAME); REQUIRE(result == std::nullopt); } TEST_CASE("get_html function parsing test") { - const std::string INPUT = "./tests/post.md"; + const std::string INPUT = "./test_files/post.md"; const std::string EXPECTED_OUTPUT = R"HTML(

This is an example post

In this example we will do a couple of cool markdown things.

This is a h2 header

@@ -86,7 +85,7 @@ int main() { } TEST_CASE("formatter injection test") { - const std::string FILE_NAME = "./tests/formatter.html"; + const std::string FILE_NAME = "./test_files/formatter.html"; const std::string EXPECTED_OUTPUT = R"( diff --git a/src/utils.cpp b/src/utils.cpp deleted file mode 100644 index d685c7b..0000000 --- a/src/utils.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include - -void trim(std::string &str) { - str.erase(str.find_last_not_of(' ') + 1); - str.erase(0, str.find_first_not_of(' ')); - str.erase(str.find_last_not_of('"') + 1); - str.erase(0, str.find_first_not_of('"')); -} diff --git a/src/utils.hpp b/src/utils.hpp deleted file mode 100644 index d005eb6..0000000 --- a/src/utils.hpp +++ /dev/null @@ -1,4 +0,0 @@ -#include - -// trim string in-place, removing all whitespaces and surrounding '"' symbols -void trim(std::string &str);