commit: cab62a7330ebb7211566fe31de78642b7cf3d1b1
parent b992f2b0a21bada0d06cc9c553da8a8074cfaf03
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 17 Sep 2024 23:43:16 +0200
test-cmd/mkdir: Change from cram to tap.sh
Diffstat:
3 files changed, 103 insertions(+), 77 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="join.sh", required_files=basedir.."/cmd/join", 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="mkdir.sh", required_files=basedir.."/cmd/mkdir", timeout=1}
tap_test_program{name="mktemp.sh", required_files=basedir.."/cmd/mktemp", timeout=1}
tap_test_program{name="paste.sh", required_files=basedir.."/cmd/paste", timeout=1}
tap_test_program{name="pathchk.sh", required_files=basedir.."/cmd/pathchk", timeout=1}
diff --git a/test-cmd/mkdir.sh b/test-cmd/mkdir.sh
@@ -0,0 +1,102 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: MPL-2.0
+
+WD="$(dirname "$0")"
+target="${WD}/../cmd/mkdir"
+target_chmod="${WD}/../cmd/chmod"
+plans=10
+. "${WD}/tap.sh"
+
+t --exit=1 noargs '' 'mkdir: Missing operand
+Usage: mkdir [-pv] [-m mode] path ...
+'
+
+umask 002
+
+t_mkdir() {
+ t_err=0
+
+ test ! -e "$@" || return 1
+ "${target}" "$@" || t_err=1
+ test -d "$@" || t_err=1
+ rm -r "$@" || t_err=1
+
+ return $t_err
+}
+t_cmd foo '' t_mkdir foo
+
+t_cmd --exit=1 foo "mkdir: Failed making directory 'enoent/file': No such file or directory
+rm: Failed getting status for 'enoent/file': No such file or directory
+" t_mkdir enoent/file
+
+t_mkdir_parents() {
+ t_err=0
+
+ test ! -e gaia || return 1
+ "${target}" -p gaia/zeus || t_err=1
+ "${target_chmod}" -v + gaia gaia/zeus || t_err=1
+ rm -r gaia || t_err=1
+
+ return $t_err
+}
+
+t_cmd mkdir_parents "chmod: Permissions already set to 00775/drwxrwxr-x for 'gaia'
+chmod: Permissions already set to 00775/drwxrwxr-x for 'gaia/zeus'
+" t_mkdir_parents
+
+t_mkdir_v() {
+ t_err=0
+ for dir; do
+ test ! -e "$dir" || return 1
+ done
+ "${target}" -v "$@" || t_err=1
+ for dir; do
+ test -d "$dir" || t_err=1
+ done
+ rm -r "$@" || t_err=1
+
+ return $t_err
+}
+t_cmd verbose "mkdir: Made directory: verbose1
+mkdir: Made directory: verbose2
+" t_mkdir_v verbose1 verbose2
+
+t_cmd --exit=1 verbose_no_parents "mkdir: Failed making directory 'verbose_foo/verbose_bar': No such file or directory
+rm: Failed getting status for 'verbose_foo/verbose_bar': No such file or directory
+" t_mkdir_v verbose_foo/verbose_bar
+
+t_mkdir_mode() {
+ t_err=0
+
+ test ! -e "$2" || return 1
+ "${target}" -m "$1" "$2" || t_err=1
+ "${target_chmod}" -v + "$2" || t_err=1
+ rm -r "$2" || t_err=1
+
+ return $t_err
+}
+t_cmd plus_x "chmod: Permissions already set to 00775/drwxrwxr-x for 'plus_x'
+" t_mkdir_mode +x plus_x
+
+t_cmd go_minus_x "chmod: Permissions already set to 00764/drwxrw-r-- for 'go_minus_x'
+" t_mkdir_mode go-x go_minus_x
+
+t_cmd minus_x "chmod: Permissions already set to 00664/drw-rw-r-- for 'minus_x'
+" t_mkdir_mode -x minus_x
+
+t_mkdir_024() {
+ t_err=0
+
+ umask 024
+ test ! -e zero_two || return 1
+ "${target}" -p zero_two/four || t_err=1
+ "${target_chmod}" -v + zero_two zero_two/four || t_err=1
+ rm -r zero_two || t_err=1
+
+ return $t_err
+}
+
+t_cmd 024 "chmod: Permissions already set to 00753/drwxr-x-wx for 'zero_two'
+chmod: Permissions already set to 00753/drwxr-x-wx for 'zero_two/four'
+" t_mkdir_024
diff --git a/test-cmd/mkdir.t b/test-cmd/mkdir.t
@@ -1,77 +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 mkdir)" = "$TESTDIR/../cmd/mkdir"
-
-# Using chmod -v + to get permission bits, + with no perm nor who doesn't changes mode bits
- $ test "$(command -v chmod)" = "$TESTDIR/../cmd/chmod"
-
- $ mkdir
- mkdir: Missing operand
- Usage: mkdir [-pv] [-m mode] path ...
- [1]
-
- $ umask 002
-
- $ test ! -e foo
- $ mkdir foo
- $ test -d foo
- $ rm -r foo
-
- $ test ! -e enoent
- $ mkdir enoent/file
- mkdir: Failed making directory 'enoent/file': No such file or directory
- [1]
- $ test ! -e enoent
-
- $ test ! -e gaia
- $ mkdir -p gaia/zeus
- $ chmod -v + gaia gaia/zeus
- chmod: Permissions already set to 00775/drwxrwxr-x for 'gaia'
- chmod: Permissions already set to 00775/drwxrwxr-x for 'gaia/zeus'
- $ rm -r gaia
-
- $ mkdir -v verbose1 verbose2
- mkdir: Made directory: verbose1
- mkdir: Made directory: verbose2
- $ chmod -v + verbose1 verbose2
- chmod: Permissions already set to 00775/drwxrwxr-x for 'verbose1'
- chmod: Permissions already set to 00775/drwxrwxr-x for 'verbose2'
- $ mkdir -v verbose_foo/verbose_bar
- mkdir: Failed making directory 'verbose_foo/verbose_bar': No such file or directory
- [1]
- $ test ! -e verbose_foo
- $ mkdir -vp verbose_foop/verbose_barp
- mkdir: Made directory: verbose_foop
- mkdir: Made directory: verbose_foop/verbose_barp
- $ chmod -v + verbose_foop verbose_foop/verbose_barp
- chmod: Permissions already set to 00775/drwxrwxr-x for 'verbose_foop'
- chmod: Permissions already set to 00775/drwxrwxr-x for 'verbose_foop/verbose_barp'
- $ rm -r verbose1 verbose2 verbose_foop
-
- $ mkdir -m +x plus_x
- $ chmod -v + plus_x
- chmod: Permissions already set to 00775/drwxrwxr-x for 'plus_x'
- $ rm -r plus_x
- $ mkdir -m go-x go_minus_x
- $ chmod -v + go_minus_x
- chmod: Permissions already set to 00764/drwxrw-r-- for 'go_minus_x'
- $ rm -r go_minus_x
- $ mkdir -m -x minus_x
- $ chmod -v + minus_x
- chmod: Permissions already set to 00664/drw-rw-r-- for 'minus_x'
- $ rm -r minus_x
-
- $ umask 024
- $ mkdir -p zero_two/four
- $ chmod -v + zero_two zero_two/four
- chmod: Permissions already set to 00753/drwxr-x-wx for 'zero_two'
- chmod: Permissions already set to 00753/drwxr-x-wx for 'zero_two/four'
- $ rm -r zero_two
-
-No files should be left
- $ find .
- .