diff --git a/CMakeLists.txt b/CMakeLists.txt index 3171c1d..b47a6af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,20 @@ cmake_minimum_required(VERSION 3.30) project(willow-test LANGUAGES CXX) -set(CMAKE_CXX_COMPILER "/usr/bin/clang++") -set(CMAKE_CXX_STANDARD 23) -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -add_compile_options(-g) -add_compile_options(-Wall) -add_compile_options(-Wextra) -add_compile_options(-Wconversion) -add_compile_options(-Wimplicit-fallthrough) - add_subdirectory(src/willow) + if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message("LOCAL BUILD ONLY") + set(CMAKE_CXX_COMPILER "/usr/bin/clang++") + set(CMAKE_CXX_STANDARD 23) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + + add_compile_options(-g) + add_compile_options(-Wall) + add_compile_options(-Wextra) + add_compile_options(-Wconversion) + add_compile_options(-Wimplicit-fallthrough) + add_executable(willow_test src/main.cpp) target_link_libraries(willow_test PRIVATE willow) endif() diff --git a/README.md b/README.md index b0ccb14..53922d4 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Currently, willow only supports CMake for distribution, although if you know what you're doing, feel free to clone the repo and do what you need yourself. ```cmake +set(CMAKE_CXX_STANDARD 23) include(FetchContent) fetchcontent_declare( willow @@ -32,7 +33,7 @@ auto add(int x, int y) -> int { return x + y; } // it succeeded or not. Alerts print on function failure auto test_add(Willow::Test* test) -> int { if (add(3, 2) != 5) { - Willow::alert(test, "3 + 2 does not equal 5"); + test->alert("3 + 2 does not equal 5"); return 1; } diff --git a/src/willow/CMakeLists.txt b/src/willow/CMakeLists.txt index 8a45bad..df3fbe5 100644 --- a/src/willow/CMakeLists.txt +++ b/src/willow/CMakeLists.txt @@ -1,12 +1,9 @@ add_library(willow STATIC) set_target_properties(willow PROPERTIES LINKER_LANGUAGE CXX) -target_sources(willow - # PRIVATE - # foo.cpp - PUBLIC - reporters.h - test.h - willow.h +target_sources(willow PUBLIC + reporters.h + test.h + willow.h ) target_include_directories(willow PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/willow/reporters.h b/src/willow/reporters.h index 33616d5..7671054 100644 --- a/src/willow/reporters.h +++ b/src/willow/reporters.h @@ -52,10 +52,10 @@ namespace Willow { if (test.status == Status::Fail) { results.fail++; - std::println("\x1b[31m\tReturn code: {}\x1b[0m", test.retcode); if (test.msg.has_value()) { std::println("\x1b[31m\t{}\x1b[0m", test.msg.value()); } + std::println("\x1b[31m\tReturn code: {}\x1b[0m", test.retcode); } else if (test.status == Status::Skip) { results.skip++; diff --git a/src/willow/test.h b/src/willow/test.h index 7023e30..4af748b 100644 --- a/src/willow/test.h +++ b/src/willow/test.h @@ -1,6 +1,7 @@ #ifndef WILLOW_TEST_H #define WILLOW_TEST_H +#include #include namespace Willow { @@ -43,7 +44,7 @@ namespace Willow { auto operator()() -> void { retcode = fn(this); } - constexpr auto alert(std::string message) -> void { msg = message; } + constexpr auto alert(const std::string& message) -> void { msg = message; } }; }; // namespace Willow