commit: 3f4ec818db3a23693088ca390e5bba01764f11c4
parent 43ebed05b353a91a9717869880017d8dd0c46539
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 20 Sep 2024 03:07:54 +0200
cmd/mkdir: unify error message formatting
Diffstat:
2 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/cmd/mkdir.c b/cmd/mkdir.c
@@ -28,12 +28,12 @@ mkdir_simple(char *path, mode_t mode)
assert(errno == 0);
if(mkdir(path, mode) < 0)
{
- fprintf(stderr, "mkdir: Failed making directory '%s': %s\n", path, strerror(errno));
+ fprintf(stderr, "%s: error: Failed making directory '%s': %s\n", argv0, path, strerror(errno));
errno = 0;
return -1;
}
- if(mkdir_parents_verbose) fprintf(stderr, "mkdir: Made directory: %s\n", path);
+ if(mkdir_parents_verbose) fprintf(stderr, "%s: Made directory: %s\n", argv0, path);
return 0;
}
@@ -71,16 +71,16 @@ main(int argc, char *argv[])
mode = new_mode(optarg, 0777, &errstr);
if(errstr != NULL)
{
- fprintf(stderr, "mkdir: Failed parsing mode '%s': %s\n", optarg, errstr);
+ fprintf(stderr, "%s: error: Failed parsing mode '%s': %s\n", argv0, optarg, errstr);
return 1;
}
break;
case ':':
- fprintf(stderr, "mkdir: Error: Missing operand for option: '-%c'\n", optopt);
+ fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt);
usage();
return 1;
case '?':
- fprintf(stderr, "mkdir: Error: Unrecognised option: '-%c'\n", optopt);
+ fprintf(stderr, "%s: error: Unrecognised option: '-%c'\n", argv0, optopt);
usage();
return 1;
default:
@@ -95,7 +95,7 @@ main(int argc, char *argv[])
if(argc < 1)
{
- fprintf(stderr, "mkdir: Missing operand\n");
+ fprintf(stderr, "%s: error: Missing operand\n", argv0);
usage();
return 1;
}
diff --git a/test-cmd/mkdir.sh b/test-cmd/mkdir.sh
@@ -5,29 +5,24 @@
WD="$(dirname "$0")"
target="${WD}/../cmd/mkdir"
target_chmod="${WD}/../cmd/chmod"
-plans=10
+plans=15
. "${WD}/tap.sh"
-t --exit=1 noargs '' 'mkdir: Missing operand
+t --exit=1 noargs '' 'mkdir: error: Missing operand
Usage: mkdir [-pv] [-m mode] path ...
'
umask 002
-t_mkdir() {
- t_err=0
-
- test ! -e "$@" || return 1
- "${target}" "$@" || return 1
- test -d "$@" || t_err=1
- rm -r "$@" || t_err=1
-
- return $t_err
-}
-t_cmd foo '' t_mkdir foo
+t_cmd foo:absent '' rm -f foo
+t foo:mkdir foo
+t_cmd foo:isdir '' test -d foo
+t_cmd foo:rm '' rm -r foo
-t_cmd --exit=1 foo "mkdir: Failed making directory 'enoent/file': No such file or directory
-" t_mkdir enoent/file
+t_cmd enoent:absent '' test ! -e enoent
+t --exit=1 foo:mkdir enoent/file "mkdir: error: Failed making directory 'enoent/file': No such file or directory
+"
+t_cmd enoent:still_absent '' test ! -e enoent
t_mkdir_parents() {
t_err=0
@@ -61,7 +56,7 @@ 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
+t_cmd --exit=1 verbose_no_parents "mkdir: error: Failed making directory 'verbose_foo/verbose_bar': No such file or directory
" t_mkdir_v verbose_foo/verbose_bar
t_mkdir_mode() {