Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
11 changes: 4 additions & 7 deletions src/willow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}/..)
2 changes: 1 addition & 1 deletion src/willow/reporters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
3 changes: 2 additions & 1 deletion src/willow/test.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef WILLOW_TEST_H
#define WILLOW_TEST_H

#include <optional>
#include <string>

namespace Willow {
Expand Down Expand Up @@ -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

Expand Down
Loading