From: Carlos Maniero <carlos@maniero.me>
To: ~johnnyrichard/olang-devel@lists.sr.ht
Cc: Carlos Maniero <carlos@maniero.me>
Subject: [PATCH olang 2/2] tests: add unit tests configuration
Date: Sat, 17 Feb 2024 21:50:23 -0300 [thread overview]
Message-ID: <20240218005023.3723888-2-carlos@maniero.me> (raw)
In-Reply-To: <20240218005023.3723888-1-carlos@maniero.me>
This commit introduces a basic configuration for unit tests. However, as
there are currently no unit tests, the linter step has not been
activated. This is because clang-format does not handle zero files
gracefully.
The linter step must be enabled once the first unit test is implemented.
Signed-off-by: Carlos Maniero <carlos@maniero.me>
---
Makefile | 6 +++++-
tests/unit/Makefile | 28 ++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 tests/unit/Makefile
diff --git a/Makefile b/Makefile
index b13b41b..62297ad 100644
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,6 @@ linter: $(SRCS) $(HEADERS)
clang-format --dry-run --Werror $?
$(MAKE) -C tests/integration/ linter
-
.PHONY: linter-fix
linter-fix: $(SRCS) $(HEADERS)
clang-format -i $?
@@ -32,9 +31,14 @@ integration-test:
$(MAKE)
$(MAKE) -C tests/integration/
+.PHONY: unit-test
+unit-test:
+ $(MAKE) -C tests/unit/
+
.PHONY: check
check:
$(MAKE) integration-test
+ $(MAKE) unit-test
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
diff --git a/tests/unit/Makefile b/tests/unit/Makefile
new file mode 100644
index 0000000..ab250cf
--- /dev/null
+++ b/tests/unit/Makefile
@@ -0,0 +1,28 @@
+SRCS := $(wildcard *_test.c)
+OBJS := $(patsubst %_test.c, %_test.o, $(SRCS))
+CFLAGS := -I../../src -I../shared
+TESTS := $(patsubst %_test.c, %_test, $(SRCS))
+EXEC_TESTS := $(patsubst %_test, ./%_test, $(TESTS))
+MUNIT_SRC := ../shared/munit.c
+MUNIT := ./munit.o
+
+.PHONY: all
+all: $(MUNIT) $(TESTS)
+ @for file in $(EXEC_TESTS); do \
+ ./"$$file"; \
+ done
+
+.PHONY: clean
+clean:
+ $(RM) *.o *_test
+
+.PHONY: linter
+linter: $(SRCS)
+ clang-format --dry-run --Werror $?
+
+.PHONY: linter-fix
+linter-fix: $(SRCS)
+ clang-format -i $?
+
+$(MUNIT):
+ $(CC) -c $(MUNIT_SRC) $(CFLAGS) -o $(MUNIT)
--
2.34.1
next prev parent reply other threads:[~2024-02-18 0:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-18 0:27 [PATCH olang 0/2] add unit tests config Carlos Maniero
2024-02-18 0:50 ` [PATCH olang 1/2] tests: move munit to a shared directory Carlos Maniero
2024-02-18 0:50 ` Carlos Maniero [this message]
2024-02-18 0:55 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-02-19 0:50 ` [PATCH olang 0/2] add unit tests config Johnny Richard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240218005023.3723888-2-carlos@maniero.me \
--to=carlos@maniero.me \
--cc=~johnnyrichard/olang-devel@lists.sr.ht \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox