logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: af17b623d3cdabb3767e3b2602fc0ad96af2c53d
parent f02019a4496029cd95d1372fa32c2d97d629d01f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu, 19 Sep 2024 11:02:34 +0200

test-cmd/df: Change from atf-sh to tap.sh

Diffstat:

Mtest-cmd/Kyuafile2+-
Dtest-cmd/df30------------------------------
Atest-cmd/df.sh33+++++++++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -7,7 +7,6 @@ test_suite("utils-std commands") basedir = fs.dirname(fs.dirname(current_kyuafile())) -- 9,$|LC_ALL=C.UTF-8 sort -atf_test_program{name="df", required_files=basedir.."/cmd/df", timeout=1} tap_test_program{name="arch.sh", required_files=basedir.."/cmd/arch", timeout=1} tap_test_program{name="base64.sh", required_files=basedir.."/cmd/base64", timeout=1} tap_test_program{name="basename.sh", required_files=basedir.."/cmd/basename", timeout=1} @@ -17,6 +16,7 @@ tap_test_program{name="cksum.sh", required_files=basedir.."/cmd/cksum", timeout= tap_test_program{name="cmp.sh", required_files=basedir.."/cmd/cmp", timeout=1} tap_test_program{name="cut.sh", required_files=basedir.."/cmd/cut", timeout=1} tap_test_program{name="date.sh", required_files=basedir.."/cmd/date", timeout=1} +tap_test_program{name="df.sh", required_files=basedir.."/cmd/df", timeout=1} tap_test_program{name="dirname.sh", required_files=basedir.."/cmd/dirname", timeout=1} tap_test_program{name="echo.sh", required_files=basedir.."/cmd/echo", timeout=1} tap_test_program{name="env.sh", required_files=basedir.."/cmd/env", timeout=1} diff --git a/test-cmd/df b/test-cmd/df @@ -1,30 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: MPL-2.0 - -atf_test_case posix -posix_body() { - # stderr ignored because not all filesystems allow statvfs from a normal user. - # For example tracefs aka "/sys/kernel/debug/tracing" on Linux. - - atf_check -e ignore -o 'match:Filesystem 512-blocks Used Available Capacity Mounted on' sh -c '../cmd/df -P | head -n 1' - atf_check -e ignore -o 'match:Filesystem 1024-blocks Used Available Capacity Mounted on' sh -c '../cmd/df -Pk | head -n 1' - - atf_check -e ignore -o 'match:^[^ ]* [0-9]* [0-9]* [0-9]* [0-9]*% [^ ]$' sh -c '../cmd/df -P | sed -n 2,\$p' - atf_check -e ignore -o 'match:^[^ ]* [0-9]* [0-9]* [0-9]* [0-9]*% [^ ]$' sh -c '../cmd/df -Pk | sed -n 2,\$p' - - atf_check -e ignore -o 'match:^[^ ]* [0-9]* [0-9]* [0-9]* [0-9]*% [^ ]$' sh -c '../cmd/df -Pa | sed -n 2,\$p' - atf_check -e ignore -o 'match:^[^ ]* [0-9]* [0-9]* [0-9]* [0-9]*% [^ ]$' sh -c '../cmd/df -Pak | sed -n 2,\$p' -} - -atf_test_case args -args_body() { - atf_check -e ignore -o 'match:^[^ ]* [0-9]* [0-9]* [0-9]* [0-9]*% /$' sh -c '../cmd/df -P / | sed -n 2,\$p' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - atf_add_test_case posix - atf_add_test_case args -} diff --git a/test-cmd/df.sh b/test-cmd/df.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: 0BSD + +WD=$(dirname "$0") +target="${WD}/../cmd/df" +plans=7 +. "${WD}/tap.sh" + +# stderr ignored because not all filesystems allow statvfs from a normal user. +# For example tracefs aka "/sys/kernel/debug/tracing" on Linux. +t_df_l1() { + "$target" "$@" 2>/dev/null | head -n 1 +} +t_cmd posix 'Filesystem 512-blocks Used Available Capacity Mounted on +' t_df_l1 -P +t_cmd posix_1k 'Filesystem 1024-blocks Used Available Capacity Mounted on +' t_df_l1 -Pk + +set -o pipefail + +t_df_posix_cols() { + "$target" "$@" 2>/dev/null | sed -n '2,$p' | { grep -vE '[^ ]+ (-|[0-9]+) (-|[0-9]+) (-|[0-9]+) (-|[0-9]+%) [^ ]+$'; return 0; } +} +t_cmd posix_cols '' t_df_posix_cols -P +t_cmd posix_cols_k '' t_df_posix_cols -Pk +t_cmd posix_cols_a '' t_df_posix_cols -Pa +t_cmd posix_cols_ak '' t_df_posix_cols -Pak + +t_df_rootfs() { + "$target" "$@" 2>/dev/null | sed -n '2,$p' | { grep -vE '^[^ ]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+% /$'; return 0; } +} +t_cmd posix_cols_rootfs '' t_df_rootfs -P /