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
3 changes: 3 additions & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ jobs:
run: |
cmake --build cmake.output --target testrunner -- -j $(nproc)
./cmake.output/testrunner
# Re-run tests from within the build directory to validate that
# SIMPLECPP_TEST_SOURCE_DIR is correctly defined and resolved
(cd cmake.output && ./testrunner)

- name: Run valgrind
if: matrix.os == 'ubuntu-24.04'
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ add_library(simplecpp_obj OBJECT simplecpp.cpp)

add_executable(simplecpp $<TARGET_OBJECTS:simplecpp_obj> main.cpp)
add_executable(testrunner $<TARGET_OBJECTS:simplecpp_obj> test.cpp)
target_compile_definitions(testrunner
PRIVATE
SIMPLECPP_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
)

enable_testing()
add_test(NAME testrunner COMMAND testrunner)
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
all: testrunner simplecpp

CPPFLAGS ?=
CXXFLAGS = -Wall -Wextra -pedantic -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wundef -Wno-multichar -Wold-style-cast -std=c++11 -g $(CXXOPTS)
LDFLAGS = -g $(LDOPTS)

%.o: %.cpp simplecpp.h
$(CXX) $(CXXFLAGS) -c $<
# Define test source dir macro for compilation (preprocessor flags)
TEST_CPPFLAGS = -DSIMPLECPP_TEST_SOURCE_DIR=\"$(CURDIR)\"

# Only test.o gets the define
test.o: CPPFLAGS += $(TEST_CPPFLAGS)

%.o: %.cpp simplecpp.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $<

testrunner: test.o simplecpp.o
$(CXX) $(LDFLAGS) simplecpp.o test.o -o testrunner
Expand Down
12 changes: 11 additions & 1 deletion test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
#include <utility>
#include <vector>

#ifndef SIMPLECPP_TEST_SOURCE_DIR
#error "SIMPLECPP_TEST_SOURCE_DIR is not defined."
#endif

#define STRINGIZE_(x) #x
#define STRINGIZE(x) STRINGIZE_(x)

static const std::string testSourceDir = SIMPLECPP_TEST_SOURCE_DIR;
static int numberOfFailedAssertions = 0;

#define ASSERT_EQUALS(expected, actual) (assertEquals((expected), (actual), __LINE__))
Expand Down Expand Up @@ -1556,6 +1561,7 @@ static void has_include_1()
" #endif\n"
"#endif";
simplecpp::DUI dui;
dui.includePaths.push_back(testSourceDir);
dui.std = "c++17";
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
dui.std = "c++14";
Expand All @@ -1573,6 +1579,7 @@ static void has_include_2()
" #endif\n"
"#endif";
simplecpp::DUI dui;
dui.includePaths.push_back(testSourceDir);
dui.std = "c++17";
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
ASSERT_EQUALS("", preprocess(code));
Expand All @@ -1592,7 +1599,7 @@ static void has_include_3()
// Test file not found...
ASSERT_EQUALS("\n\n\n\nB", preprocess(code, dui));
// Unless -I is set (preferably, we should differentiate -I and -isystem...)
dui.includePaths.push_back("./testsuite");
dui.includePaths.push_back(testSourceDir + "/testsuite");
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
ASSERT_EQUALS("", preprocess(code));
}
Expand All @@ -1608,6 +1615,7 @@ static void has_include_4()
"#endif";
simplecpp::DUI dui;
dui.std = "c++17";
dui.includePaths.push_back(testSourceDir);
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
ASSERT_EQUALS("", preprocess(code));
}
Expand All @@ -1623,6 +1631,7 @@ static void has_include_5()
"#endif";
simplecpp::DUI dui;
dui.std = "c++17";
dui.includePaths.push_back(testSourceDir);
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
ASSERT_EQUALS("", preprocess(code));
}
Expand All @@ -1638,6 +1647,7 @@ static void has_include_6()
"#endif";
simplecpp::DUI dui;
dui.std = "gnu99";
dui.includePaths.push_back(testSourceDir);
ASSERT_EQUALS("\n\nA", preprocess(code, dui));
ASSERT_EQUALS("", preprocess(code));
}
Expand Down
Loading