commit: 4435933486c5913e189acb67d0b88126514e3749
parent f812205d814e039ecf67ce5c429f879177a1e9d0
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 26 Aug 2024 09:21:45 +0200
test-cmd/{wc.t => wc.sh}: switch to tap.sh
Diffstat:
3 files changed, 111 insertions(+), 94 deletions(-)
diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile
@@ -38,5 +38,6 @@ tap_test_program{name="strings.sh", required_files=basedir.."/cmd/strings", time
tap_test_program{name="test.sh", required_files=basedir.."/cmd/test", timeout=2}
tap_test_program{name="true.sh", required_files=basedir.."/cmd/true", timeout=1}
tap_test_program{name="tty.sh", required_files=basedir.."/cmd/tty", timeout=1}
+tap_test_program{name="wc.sh", required_files=basedir.."/cmd/wc", timeout=1}
tap_test_program{name="uname.sh", required_files=basedir.."/cmd/uname", timeout=1}
tap_test_program{name="unlink.sh", required_files=basedir.."/cmd/unlink", timeout=1}
diff --git a/test-cmd/wc.sh b/test-cmd/wc.sh
@@ -0,0 +1,110 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: MPL-2.0
+
+WD="$(dirname "$0")/../"
+target="${WD}/cmd/wc"
+plans=24
+. "${WD}/test-cmd/tap.sh"
+
+export LANG=C.UTF-8 LC_ALL=C.UTF-8
+
+t --input='a b c' 'a b c' '' '0 3 5
+'
+
+t --input='a
+b
+c
+' 'a\nb\nc' '' '3 3 6
+'
+
+t --input='a
+b
+c
+' 'a\nb\nc' '-clw' '3 3 6
+'
+
+t --input='a
+bb
+ccc
+' 'a\nbb\nccc\n' '' '3 3 9
+'
+
+t --input='a
+bb
+ccc
+' 'a\nbb\nccc\n:-clw' '-clw' '3 3 9
+'
+
+
+t --input='я нет 草' 'ru+jp:-m' '-m' '7
+'
+t --input='я нет 草' 'ru+jp:-mw' '-mw' '3 7
+'
+t --input='я нет 草' 'ru+jp:-mlw' '-mlw' '0 3 7
+'
+
+t --input='' 'empty_stdin' '' '0 0 0
+'
+t 'empty_file' "${WD}/test-cmd/inputs/empty" "0 0 0 ${WD}/test-cmd/inputs/empty
+"
+
+t --exit=1 'enoent' '/var/empty/e/no/ent' "wc: Failed opening file '/var/empty/e/no/ent': No such file or directory
+"
+
+# Formatting with reduced counts
+
+t --input='
+' '\n:1l' '-l' '1
+'
+
+t --input='a
+' 'a\n:1l' '-l' '1
+'
+
+t --input='
+' '\n:1c' '-c' '1
+'
+
+t --input='a
+' 'a\n:2c' '-c' '2
+'
+
+t --input='
+' '\n:0w' '-w' '0
+'
+
+t --input='a
+' 'a\n:1w' '-w' '1
+'
+
+t --input='
+' '\n:1l1c' '-lc' '1 1
+'
+
+t --input='a
+' 'a\n:1l2c' '-lc' '1 2
+'
+
+t --input='' 'empty_stdin:0c' '-c' '0
+'
+t --input='' 'empty_stdin:0c0l' '-cl' '0 0
+'
+t --input='' 'empty_stdin:0w' '-w' '0
+'
+
+# Total when multiple files are specified
+
+t --input='foo
+' 'foo+empty' "${WD}/test-cmd/inputs/empty -" "\
+0 0 0 ${WD}/test-cmd/inputs/empty
+1 1 4
+1 1 4 total
+"
+
+t --input='foo
+' 'foo+empty:c' "-c ${WD}/test-cmd/inputs/empty -" "\
+0 ${WD}/test-cmd/inputs/empty
+4
+4 total
+"
diff --git a/test-cmd/wc.t b/test-cmd/wc.t
@@ -1,94 +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 wc)" = "$TESTDIR/../cmd/wc"
-
- $ export LANG=C.UTF-8 LC_ALL=C.UTF-8
-
- $ printf 'a b c' | wc
- \s*0\s*3\s*5\s* (re)
-
- $ printf 'a\nb\nc\n' | wc
- \s*3\s*3\s*6\s* (re)
- $ printf 'a\nb\nc\n' | wc -clw
- \s*3\s*3\s*6\s* (re)
-
- $ printf 'a\nbb\nccc\n' | wc
- \s*3\s*3\s*9\s* (re)
- $ printf 'a\nbb\nccc\n' | wc -clw
- \s*3\s*3\s*9\s* (re)
-
- $ printf 'я нет 草' | wc -m
- \s*7\s* (re)
- $ printf 'я нет 草' | wc -mw
- \s*3\s*7\s* (re)
- $ printf 'я нет 草' | wc -mlw
- \s*0\s*3\s*7\s* (re)
-
- $ wc <&-
- wc: Failed reading from file '<stdin>': Bad file descriptor
- [1]
- $ wc -m <&-
- wc: Failed reading from file '<stdin>': Bad file descriptor
- [1]
-
- $ echo -n >empty
- $ wc empty
- 0 0 0 empty
- $ wc /var/empty/e/no/ent
- wc: Failed opening file '/var/empty/e/no/ent': No such file or directory
- [1]
-
-Formatting with reduced counts
- $ echo | wc -l
- 1
- $ echo a | wc -l
- 1
-
- $ echo | wc -c
- 1
- $ echo a | wc -c
- 2
-
- $ echo | wc -w
- 0
- $ echo a | wc -w
- 1
-
- $ echo | wc -cl
- 1 1
- $ echo a | wc -cl
- 1 2
-
- $ wc -c empty
- 0 empty
- $ wc -cl empty
- 0 0 empty
- $ wc -w empty
- 0 empty
-
-Total when multiple files are specified
- $ echo foo | wc empty -
- 0 0 0 empty
- 1 1 4
- 1 1 4 total
- $ printf 'foo bar\n' > foobar
- $ wc foobar empty
- 1 2 8 foobar
- 0 0 0 empty
- 1 2 8 total
-
- $ printf 'foot bart\n' > footbart
- $ wc -c foobar footbart empty
- 8 foobar
- 10 footbart
- 0 empty
- 18 total
-
- $ rm foobar footbart empty
-
- $ find .
- .