commit: 0c00de4991ed0e7722881477dc858de001fb036e
parent 2b9a1206e400a30309fe7aae8d508f95151302be
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 3 Sep 2024 18:08:08 +0200
test-cmd/pathchk.sh: extract {NAME,PATH}_MAX from <limits.h>
Fixes test on NetBSD
Diffstat:
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
@@ -25,7 +25,8 @@ all: $(EXE) $(MAN1SO)
selfcheck: selfcheck-cmds selfcheck-libs
.PHONY: selfcheck-cmds
-selfcheck-cmds: $(EXE)
+TEST_CMDS = test-cmd/pathchk-getlimits
+selfcheck-cmds: $(EXE) $(TEST_CMDS)
LDSTATIC=$(LDSTATIC) ./check-cmds.sh
.PHONY: selfcheck-libs
@@ -36,7 +37,7 @@ selfcheck-libs: $(TEST_LIBS)
# Manpages with examples that cram/prysk can grok
MAN_EXAMPLES = cmd/readlink.1
.PHONY: check
-check: all check-man selfcheck-libs
+check: all check-man selfcheck-libs $(TEST_CMDS)
LDSTATIC=$(LDSTATIC) kyua test || (kyua report --verbose --results-filter=broken,failed; false)
MALLOC_CHECK_=3 POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 LC_ALL=C.UTF-8 $(CRAM) test-cmd/*.t ${MAN_EXAMPLES}
@@ -185,3 +186,6 @@ cmd/mv: cmd/mv.c lib/consent.c lib/consent.h lib/fs.c lib/fs.h Makefile config.m
cmd/sha1sum: cmd/sha1sum.c lib/sha1.c lib/sha1.h lib/bytes2hex.c lib/strconv.h Makefile
$(CC) -std=c99 $(CFLAGS) -o $@ cmd/sha1sum.c lib/sha1.c lib/bytes2hex.c $(LDFLAGS) $(LDSTATIC)
+
+test-cmd/pathchk-getlimits: test-cmd/pathchk-getlimits.c Makefile
+ $(CC) -std=c99 $(CFLAGS) -o $@ test-cmd/pathchk-getlimits.c $(LDFLAGS) $(LDSTATIC)
diff --git a/test-cmd/pathchk-getlimits.c b/test-cmd/pathchk-getlimits.c
@@ -0,0 +1,13 @@
+// utils-std: Collection of commonly available Unix tools
+// SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+// SPDX-License-Identifier: MPL-2.0
+
+#define _POSIX_C_SOURCE 202405L
+#include <stdio.h>
+#include <limits.h>
+
+int main(void)
+{
+ (void)printf("NAME_MAX=%zd\nPATH_MAX=%zd\n", NAME_MAX, PATH_MAX);
+ return 0;
+}
diff --git a/test-cmd/pathchk.sh b/test-cmd/pathchk.sh
@@ -12,8 +12,14 @@ plans=13
POSIX_NAME_MAX=$(getconf _POSIX_NAME_MAX 2>/dev/null || echo 14)
POSIX_PATH_MAX=$(getconf _POSIX_PATH_MAX 2>/dev/null || echo 256)
-NAME_MAX=$(getconf NAME_MAX "$(pwd)")
-PATH_MAX=$(getconf PATH_MAX "$(pwd)")
+# Get NAME_MAX and PATH_MAX from <limits.h> (getconf doesn't always matches, such as on NetBSD)
+if ! test -f "${WD}/test-cmd/pathchk-getlimits"; then
+ echo "${WD}/test-cmd/pathchk-getlimits: Is missing, did you use make?"
+ exit 1
+fi
+eval $("${WD}/test-cmd/pathchk-getlimits")
+echo "# NAME_MAX: ${NAME_MAX?}"
+echo "# PATH_MAX: ${PATH_MAX?}"
name_max_str=$(printf "%*s" "${NAME_MAX}" | tr ' ' _)
t name_max:ok "foo/${name_max_str}/bar"