commit: c05602f9b9171b0b10451ffabebde1cae55cab26
parent 04a855e7c02241321787e07ad41870ac484b79f0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 2 Sep 2024 19:24:00 +0200
test-cmd/pathchk: Change from cram to tap.sh
$ dumbbench --float ./test-cmd/pathchk.t
[snip]
cmd: Ran 27 iterations (6 outliers).
cmd: Rounded run time per iteration (seconds): 0.073850 +/- 0.000380 (0.5%)
$ dumbbench --float ./test-cmd/pathchk.sh
[snip]
cmd: Ran 20 iterations (0 outliers).
cmd: Rounded run time per iteration (seconds): 0.019610 +/- 0.000120 (0.6%)
Note: pathchk.t was missing path_max:ok hence the off-by-one fixed in 04a855e7c02241321787e07ad41870ac484b79f0
Diffstat:
3 files changed, 49 insertions(+), 43 deletions(-)
diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile
@@ -29,6 +29,7 @@ tap_test_program{name="id.sh", required_files=basedir.."/cmd/id", timeout=1}
tap_test_program{name="link.sh", required_files=basedir.."/cmd/link", timeout=1}
tap_test_program{name="logname.sh", required_files=basedir.."/cmd/logname", timeout=1}
tap_test_program{name="mktemp.sh", required_files=basedir.."/cmd/mktemp", timeout=1}
+tap_test_program{name="pathchk.sh", required_files=basedir.."/cmd/pathchk", timeout=1}
tap_test_program{name="pwd.sh", required_files=basedir.."/cmd/pwd", timeout=1}
tap_test_program{name="realpath.sh", required_files=basedir.."/cmd/realpath", timeout=1}
tap_test_program{name="seq.sh", required_files=basedir.."/cmd/seq", timeout=1}
diff --git a/test-cmd/pathchk.sh b/test-cmd/pathchk.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: MPL-2.0
+
+WD="$(dirname "$0")/../"
+target="${WD}/cmd/pathchk"
+plans=13
+
+. "${WD}/test-cmd/tap.sh"
+
+# Thanks glibc for the broken getconf
+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)")
+
+name_max_str=$(printf "%*s" "${NAME_MAX}" | tr ' ' _)
+t name_max:ok "foo/${name_max_str}/bar"
+t --exit=1 name_max:xfail "foo/s${name_max_str}/bar" "pathchk: Path component ($(( ${NAME_MAX} + 1 )) octets) is over the maximum size (${NAME_MAX} octets): s${name_max_str}
+"
+
+posix_name_max_str=$(printf "%*s" "${POSIX_NAME_MAX}" | tr ' ' _)
+t posix_name_max:ok "-p foo/${posix_name_max_str}/bar"
+t --exit=1 posix_name_max:xfail "-p foo/s${posix_name_max_str}/bar" "pathchk: Path component ($(( ${POSIX_NAME_MAX} + 1 )) octets) is over the maximum size (${POSIX_NAME_MAX} octets): s${posix_name_max_str}
+"
+
+path_max_str=$(printf "%*s" "$(( ${PATH_MAX} - 1 ))" | tr ' ' /)
+t path_max:ok "${path_max_str}"
+t --exit=1 path_max:xfail "s${path_max_str}" "pathchk: Path (${PATH_MAX} octets) is over the maximum size ($(( ${PATH_MAX} - 1 )) octets): s${path_max_str}
+"
+
+posix_path_max_str=$(printf "%*s" "$(( ${POSIX_PATH_MAX} - 1 ))" | tr ' ' /)
+t posix_path_max:ok "-p ${posix_path_max_str}"
+t --exit=1 posix_path_max:xfail "-p s${posix_path_max_str}" "pathchk: Path (${POSIX_PATH_MAX} octets) is over the maximum size ($(( ${POSIX_PATH_MAX} - 1 )) octets): s${posix_path_max_str}
+"
+
+t enoent /dev/null/foo
+t noparent /../foo
+
+t --exit=1 hyphen '-P ./-foo' 'pathchk: Path component starts with an hyphen: -foo
+'
+t --exit=1 hyphen_subdir '-P ./bar/-foo' 'pathchk: Path component starts with an hyphen: -foo
+'
+
+zero_two="$(printf '\02')"
+t --exit=1 posix_charset "-p foo${zero_two}bar" "pathchk: Error non-portable character '${zero_two}' (0x02) found in: foo${zero_two}bar
+"
diff --git a/test-cmd/pathchk.t b/test-cmd/pathchk.t
@@ -1,43 +0,0 @@
-#!/usr/bin/env cram
-# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
-# SPDX-License-Identifier: MPL-2.0
-
- $ export PATH="$TESTDIR/../cmd:$PATH"
-
- $ test "$(command -v pathchk)" = "$TESTDIR/../cmd/pathchk"
-
-Thanks glibc for the broken getconf
- $ POSIX_NAME_MAX=$(getconf _POSIX_NAME_MAX 2>/dev/null || echo 14)
- $ POSIX_PATH_MAX=$(getconf _POSIX_PATH_MAX 2>/dev/null || echo 256)
-
- $ pathchk "$(printf "foo/%*s/bar" "$(getconf NAME_MAX "$PWD")" | tr ' ' _)"
- $ pathchk "$(printf "foo/s%*s/bar" "$(getconf NAME_MAX "$PWD")" | tr ' ' _)"
- pathchk: Path component \([0-9]+ octets\) is over the maximum size \([0-9]+ octets\): s_+ (re)
- [1]
-
- $ pathchk -p "$(printf "foo/%*s/bar" "${POSIX_NAME_MAX}" | tr ' ' _)"
- $ pathchk -p "$(printf "foo/s%*s/bar" "${POSIX_NAME_MAX}" | tr ' ' _)"
- pathchk: Path component \([0-9]+ octets\) is over the maximum size \([0-9]+ octets\): s_+ (re)
- [1]
-
- $ pathchk "$(printf "s%*s" "$(getconf PATH_MAX "$PWD")" | tr ' ' /)"
- pathchk: Path \([0-9]+ octets\) is over the maximum size \([0-9]+ octets\): s/+ (re)
- [1]
-
- $ pathchk -p "$(printf "%*s" "$(( ${POSIX_PATH_MAX} - 1 ))" | tr ' ' /)"
- $ pathchk -p "$(printf "s%*s" "$(( ${POSIX_PATH_MAX} - 1 ))" | tr ' ' /)"
- pathchk: Path \([0-9]+ octets\) is over the maximum size \([0-9]+ octets\): s/+ (re)
- [1]
-
- $ pathchk /dev/null/foo
- $ pathchk /../foo
- $ pathchk -P ./-foo
- pathchk: Path component starts with an hyphen: -foo
- [1]
- $ pathchk -P ./bar/-foo
- pathchk: Path component starts with an hyphen: -foo
- [1]
-
- $ pathchk -p "foo$(printf '\01')bar"
- pathchk: Error non-portable character '\x01' (0x01) found in: foo\x01bar (esc)
- [1]