summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-04-07 08:28:32 -0300
committerEuAndreh <eu@euandre.org>2024-04-07 08:35:50 -0300
commitd56bf7cae8157f6f75ccc59df1c945603e510f7d (patch)
treec8c87857de8693886b3d3e69e3fbde4ca18d7e76
parentsrc/logerr.c: Also *try* to log something when fprintf() and vfprintf() fail (diff)
downloadpindaiba-d56bf7cae8157f6f75ccc59df1c945603e510f7d.tar.gz
pindaiba-d56bf7cae8157f6f75ccc59df1c945603e510f7d.tar.xz
src/lib.c: Print project metadata on pindaiba_main
-rw-r--r--Makefile15
-rw-r--r--deps.mk10
-rw-r--r--src/lib.c24
-rw-r--r--src/main.c4
-rw-r--r--src/pindaiba.h14
-rwxr-xr-xtests/cli-opts.sh13
6 files changed, 50 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index 33cbe67..d5ba524 100644
--- a/Makefile
+++ b/Makefile
@@ -92,9 +92,10 @@ all: $(derived-assets)
lib$(NAME).a: $(sources.o)
$(NAME).a: $(sources.o) src/main.o
-src/config.h: Makefile deps.mk
-$(sources.o) $(tests.o) src/main.o: Makefile deps.mk src/config.h
-tests/slurp.o: tests/slurp.h Makefile deps.mk src/config.h
+src/config.h: Makefile deps.mk
+$(sources.o) $(tests.o): Makefile deps.mk src/config.h
+src/main.o: src/$(NAME).h Makefile deps.mk src/config.h
+tests/slurp.o: Makefile deps.mk src/config.h
$(archives):
@@ -115,7 +116,13 @@ $(tests.bin-check):
check-unit: $(tests.bin-check)
-check-integration:
+integration-tests = \
+ tests/cli-opts.sh \
+
+$(integration-tests): $(NAME).bin ALWAYS
+ sh $@ $(EXEC)$(NAME).bin
+
+check-integration: $(integration-tests)
## Run all tests. Each test suite is isolated, so that a parallel
diff --git a/deps.mk b/deps.mk
index 6faa254..de778e2 100644
--- a/deps.mk
+++ b/deps.mk
@@ -49,21 +49,21 @@ tests/testing.bin-check: tests/testing.bin
src/catalog.o: src/logerr.h
src/i18n.o:
-src/lib.o:
+src/lib.o: src/logerr.h
src/logerr.o:
src/random.o: src/logerr.h
src/testing.o:
tests/catalog.o: src/logerr.h src/testing.h tests/slurp.h
-tests/i18n.o: src/logerr.h src/catalog.h
-tests/lib.o:
+tests/i18n.o: src/catalog.h src/logerr.h
+tests/lib.o: src/logerr.h
tests/logerr.o: src/testing.h tests/slurp.h
tests/random.o: src/logerr.h src/testing.h
tests/testing.o:
tests/catalog.a: src/logerr.o src/testing.o tests/slurp.o
-tests/i18n.a: src/logerr.o src/catalog.o
-tests/lib.a:
+tests/i18n.a: src/catalog.o src/logerr.o
+tests/lib.a: src/logerr.o
tests/logerr.a: src/testing.o tests/slurp.o
tests/random.a: src/logerr.o src/testing.o
tests/testing.a:
diff --git a/src/lib.c b/src/lib.c
index a5b480f..02c0f92 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -1,11 +1,25 @@
+#include "config.h"
+
+#include <errno.h>
#include <stdio.h>
+#include <string.h>
+
+#include "logerr.h"
int
-re_main(int argc, char **argv) {
- int rc = 0;
- for (int i = 0; i < argc; i++) {
- printf("argv[%d]: %s\n", i, argv[i]);
+pindaiba_main(int argc, char *argv[]) {
+ int rc = -1;
+
+ (void)argc;
+ (void)argv;
+
+ if (printf("%s %s %s\n", NAME, VERSION, DATE) < 0) {
+ logerr("printf() < 0: %s\n", strerror(errno));
+ goto out;
}
- return rc;
+
+ rc = 0;
+out:
+ return !!rc;
}
diff --git a/src/main.c b/src/main.c
index ff3ea4e..f657aa9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,7 +4,5 @@
int
main(int argc, char **argv) {
- // FIXME: pindaiba(1) has at least -h and -V, and maybe with no
- // arguments it prints some arch information?
- return re_main(argc, argv);
+ return pindaiba_main(argc, argv);
}
diff --git a/src/pindaiba.h b/src/pindaiba.h
index 39c9f2d..37511c7 100644
--- a/src/pindaiba.h
+++ b/src/pindaiba.h
@@ -1,14 +1,2 @@
-/**
- * # Xa blau
- *
- * Xupli xablau xubliu, xubliu:
- *
- * ```
- * int
- * main(int argc, char **argv) {
- * return re_main(argc, argv);
- * }
- * ```
- */
int
-re_main(int argc, char **argv);
+pindaiba_main(int argc, char **argv);
diff --git a/tests/cli-opts.sh b/tests/cli-opts.sh
new file mode 100755
index 0000000..f8b9f0a
--- /dev/null
+++ b/tests/cli-opts.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+set -eu
+
+VERSION="$(awk '/^VERSION / { print $3 }' Makefile)"
+DATE="$(awk '/^DATE / { print $3 }' Makefile)"
+NAME="$(awk '/^NAME / { print $3 }' Makefile)"
+
+EXPECTED="$NAME $VERSION $DATE"
+GIVEN="$("$@")"
+
+if [ "$GIVEN" != "$EXPECTED" ]; then
+ exit 1
+fi