From 011460254d9ac50b4dd492d689aeabb5422c7411 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 24 Feb 2026 18:06:16 -0500 Subject: [PATCH] Test multiple C++ standards; move tests to top level --- .gitignore | 2 +- Makefile | 24 ++++++++++++++++++++---- test/Makefile | 14 -------------- test/tests.cpp => tests.cpp | 4 ++-- 4 files changed, 23 insertions(+), 21 deletions(-) delete mode 100644 test/Makefile rename test/tests.cpp => tests.cpp (98%) diff --git a/.gitignore b/.gitignore index 8f3506f..84c048a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/test/build/ +/build/ diff --git a/Makefile b/Makefile index fdf8655..4b66553 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,23 @@ -.PHONY: test -test: - $(MAKE) -C test +# This Makefile is entirely for running unit tests for rcp.h + +INCLUDE := include +STANDARDS := 11 14 17 20 23 +BINARIES := $(addprefix build/tests-, $(STANDARDS)) + +.PHONY: all +all: $(BINARIES) + @for std in $(STANDARDS); do \ + echo "=== Test C++$$std ==="; \ + build/tests-$$std; \ + valgrind --leak-check=full --error-exitcode=1 \ + --log-file=build/valgrind-$$std.log build/tests-$$std \ + || { echo "valgrind failed for C++$$std (see build/valgrind-$$std.log)"; exit 1; }; \ + done + +build/tests-%: tests.cpp $(INCLUDE)/rcp.h + @mkdir -p $(dir $@) + $(CXX) -std=c++$* -g -Wall -I$(INCLUDE) -o $@ $< .PHONY: clean clean: - $(MAKE) -C test clean + rm -rf build diff --git a/test/Makefile b/test/Makefile deleted file mode 100644 index 00ab43d..0000000 --- a/test/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -INCLUDE := ../include - -.PHONY: all -all: build/tests - build/tests - valgrind --leak-check=full --error-exitcode=1 --log-file=build/valgrind.log build/tests - -build/tests: tests.cpp $(INCLUDE)/rcp.h - mkdir -p $$(dirname $@) - $(CXX) -std=c++20 -g -Wall -I$(INCLUDE) -o $@ $< - -.PHONY: clean -clean: - rm -rf build diff --git a/test/tests.cpp b/tests.cpp similarity index 98% rename from test/tests.cpp rename to tests.cpp index 33850fb..2e023b5 100644 --- a/test/tests.cpp +++ b/tests.cpp @@ -114,11 +114,11 @@ void test_multi_construct_from_raw_pointers() { Receiver r; auto myo = MyObj::create(); - for (size_t i = 0u; i < 5u; i++) + for (int i = 0; i < 5; i++) { myo->add_to(r); } - for (size_t i = 0u; i < 5u; i++) + for (int i = 0; i < 5; i++) { assert(r.objects[i]->v == 42); }