commit: 7a265363e91dfb8d72d3f8e15b1a002a3b166b58
parent 3a33e4b67e6eee4b962a0f238019c53464e515df
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 2 Jul 2025 20:25:32 +0200
test-cmd/truncate.sh: migrate from test-cmd/truncate.t
Diffstat:
2 files changed, 39 insertions(+), 78 deletions(-)
diff --git a/test-cmd/truncate.sh b/test-cmd/truncate.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+# SPDX-License-Identifier: MPL-2.0
+
+plans=24
+WD="$(dirname "$0")"
+target="${WD}/../cmd/truncate"
+. "${WD}/tap.sh"
+
+touch foo
+
+wc_c() {
+ wc -c "$@" \
+ | while read foo bar; do
+ printf '%s,' "$foo"
+ done
+}
+
+tt() {
+ tt_name="tt_${1}" ; shift
+ tt_size="$1" ; shift
+ t_args "${tt_name}" '' "$@" foo
+ t_cmd "${tt_name}_check" "${tt_size}," wc_c foo
+}
+
+tt 0 0 -s 0
+tt 666 666 -s 666
+tt 666K 681984 -s 666K
+tt 666KiB 681984 -s 666KiB
+tt 666KB 666000 -s 666KB
+tt 1024 1024 -s 1024
+tt -666 358 -s -666
+tt +666 1024 -s +666
+tt -1024 0 -s -1024
+tt 2560 2560 -s 2560
+tt %1K $((3*1024)) -s %1K
+tt /2K 2048 -s /2K
+
+rm foo
diff --git a/test-cmd/truncate.t b/test-cmd/truncate.t
@@ -1,78 +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 truncate)" = "$TESTDIR/../cmd/truncate"
-
- $ touch foo
-
- $ truncate -s 0 foo
- $ wc -c foo
- \s*0\sfoo (re)
-
- $ truncate -s 666 foo
- $ wc -c foo
- \s*666\sfoo (re)
-
- $ truncate -s 666K foo
- $ wc -c foo
- \s*681984\sfoo (re)
-
- $ truncate -s 666KB foo
- $ wc -c foo
- \s*666000\sfoo (re)
-
- $ truncate -s 666KiB foo
- $ wc -c foo
- \s*681984\sfoo (re)
-
- $ truncate -s 1024 foo
- $ wc -c foo
- \s*1024\sfoo (re)
- $ truncate -s -666 foo
- $ wc -c foo
- \s*358\sfoo (re)
-
- $ truncate -s 666 foo
- $ wc -c foo
- \s*666\sfoo (re)
- $ truncate -s -1024 foo
- $ wc -c foo
- \s*0\sfoo (re)
-
- $ truncate -s 666 foo
- $ wc -c foo
- \s*666\sfoo (re)
- $ truncate -s +666 foo
- $ wc -c foo
- \s*1332\sfoo (re)
-
- $ truncate -s 15 foo
- $ wc -c foo
- \s*15\sfoo (re)
- $ truncate -s /10 foo
- $ wc -c foo
- \s*10\sfoo (re)
-
- $ truncate -s 15 foo
- $ wc -c foo
- \s*15\sfoo (re)
- $ truncate -s %10 foo
- $ wc -c foo
- \s*20\sfoo (re)
-
- $ truncate -s 15KB foo
- $ wc -c foo
- \s*15000\sfoo (re)
- $ truncate -s /10KB foo
- $ wc -c foo
- \s*10000\sfoo (re)
-
- $ truncate -s 15KB foo
- $ wc -c foo
- \s*15000\sfoo (re)
- $ truncate -s %10KB foo
- $ wc -c foo
- \s*20000\sfoo (re)