From: Calvin Wan <calvinwan@google.com>
To: git@vger.kernel.org
Cc: Calvin Wan <calvinwan@google.com>
Subject: [RFC PATCH 2/2] unit test: add basic example
Date: Thu, 27 Apr 2023 17:50:07 +0000 [thread overview]
Message-ID: <20230427175007.902278-3-calvinwan@google.com> (raw)
In-Reply-To: <20230427175007.902278-1-calvinwan@google.com>
Although this commit doesn't showcase unit tests running against
anything in Git, locally, I have a smaller set of Git files compiling
into a library with unit tests running against it using this C TAP
harness.
However, you can run `make ctap` to get an idea of how the output looks
and use it as a baseline to play around with the other features of the
library.
Signed-off-by: Calvin Wan <calvinwan@google.com>
---
Makefile | 11 +++++++++++
t/TESTS | 1 +
t/unit-test.c | 14 ++++++++++++++
3 files changed, 26 insertions(+)
create mode 100644 t/unit-test.c
diff --git a/Makefile b/Makefile
index 60ab1a8b4f..b67b81e312 100644
--- a/Makefile
+++ b/Makefile
@@ -3831,3 +3831,14 @@ $(FUZZ_PROGRAMS): all
$(XDIFF_OBJS) $(EXTLIBS) git.o $@.o $(LIB_FUZZING_ENGINE) -o $@
fuzz-all: $(FUZZ_PROGRAMS)
+
+LIB_CTAP_SOURCES = t/tap/basic.c t/tap/basic.h t/tap/macros.h
+
+PHONY: ctap
+ctap:
+ cc -It -c $(LIB_CTAP_SOURCES)
+ ar -rc libtap.a basic.o
+ mkdir -p t/unit-test
+ cc -It -o t/unit-test/unit-test-t t/unit-test.c -L. -l:libtap.a
+ cc -o t/runtests t/runtests.c
+ cd t && ./runtests -l TESTS
diff --git a/t/TESTS b/t/TESTS
index e69de29bb2..4b1899a115 100644
--- a/t/TESTS
+++ b/t/TESTS
@@ -0,0 +1 @@
+unit-test/unit-test-t
diff --git a/t/unit-test.c b/t/unit-test.c
new file mode 100644
index 0000000000..6eceb50ee6
--- /dev/null
+++ b/t/unit-test.c
@@ -0,0 +1,14 @@
+#include <tap/basic.h>
+
+int unit_test() {
+ if (1 != 1)
+ return 0;
+ return 1;
+}
+
+int main(void)
+{
+ plan(1);
+ ok(unit_test(), "unit test runs successfully");
+ return 0;
+}
--
2.40.1.495.gc816e09b53d-goog
next prev parent reply other threads:[~2023-04-27 17:50 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-27 17:50 [RFC PATCH 0/2] add an external testing library for unit tests Calvin Wan
2023-04-27 17:50 ` [RFC PATCH 1/2] Add C TAP harness Calvin Wan
2023-04-27 18:29 ` SZEDER Gábor
2023-04-27 18:38 ` Calvin Wan
2023-04-27 20:15 ` Phillip Wood
2023-04-28 16:31 ` Calvin Wan
2023-05-02 15:46 ` Felipe Contreras
2023-05-10 15:46 ` Phillip Wood
2023-05-11 23:16 ` Glen Choo
2023-05-18 10:04 ` Phillip Wood
2023-06-21 15:57 ` Linus Arver
2023-06-26 13:15 ` Phillip Wood
2023-06-28 21:17 ` Linus Arver
2023-06-29 5:52 ` Oswald Buddenhagen
2023-06-30 9:48 ` Phillip Wood
2023-05-02 15:54 ` Felipe Contreras
2023-05-02 16:39 ` Ævar Arnfjörð Bjarmason
2023-05-02 18:11 ` Felipe Contreras
2023-05-02 16:34 ` Ævar Arnfjörð Bjarmason
2023-05-10 8:18 ` Phillip Wood
2023-04-27 17:50 ` Calvin Wan [this message]
2023-04-27 18:47 ` [RFC PATCH 2/2] unit test: add basic example Junio C Hamano
2023-05-02 15:58 ` Felipe Contreras
2023-04-27 18:39 ` [RFC PATCH 0/2] add an external testing library for unit tests Junio C Hamano
2023-04-27 18:46 ` Calvin Wan
2023-04-27 21:35 ` brian m. carlson
2023-05-02 4:18 ` Felipe Contreras
2023-05-02 13:52 ` Ævar Arnfjörð Bjarmason
2023-05-02 15:28 ` Felipe Contreras
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=20230427175007.902278-3-calvinwan@google.com \
--to=calvinwan@google.com \
--cc=git@vger.kernel.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).