logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: d4e3d8fd7a3fbb15844393b32867d01025e1bf32
parent 6e1be1ece9c2f9f89f68030d302c48fed7b28e48
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 11 Feb 2022 23:19:43 +0100

Add shellcheck on test-bin

Diffstat:

MMakefile1+
Mtest-bin/args2+-
Mtest-bin/basename2+-
Mtest-bin/cat5++++-
Mtest-bin/date2+-
Mtest-bin/dirname2+-
Mtest-bin/echo2+-
Mtest-bin/false2+-
Mtest-bin/humanize2+-
Mtest-bin/pwd2+-
Atest-bin/shellcheck11+++++++++++
Mtest-bin/sname2+-
Mtest-bin/strings2+-
Mtest-bin/tee2+-
Mtest-bin/true2+-
Mtest-bin/xcd3++-
16 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile @@ -6,6 +6,7 @@ all: test: all $(SHELLCHECK) ./configure + SHELLCHECK=${SHELLCHECK} ./test-bin/shellcheck POSIX_ME_HARDER=1 POSIXLY_CORRECT=1 kyua test || (kyua report --verbose; false) cd bin ; $(MAKE) test cd sbin ; $(MAKE) test diff --git a/test-bin/args b/test-bin/args @@ -36,7 +36,7 @@ argv[4]: "/4" } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case noargs atf_add_test_case onearg atf_add_test_case twoargs diff --git a/test-bin/basename b/test-bin/basename @@ -44,7 +44,7 @@ nullarg_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case noargs atf_add_test_case one_slash atf_add_test_case two_slash diff --git a/test-bin/cat b/test-bin/cat @@ -33,6 +33,7 @@ atf_test_case noperm cleanup noperm_body() { touch inputs/chmod_000 || atf_fail "touching chmod_000" chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000" + # shellcheck disable=SC1112 atf_check -s exit:1 -e 'inline:\nError opening ‘inputs/chmod_000’: Permission denied\n' ../bin/cat inputs/chmod_000 } noperm_cleanup() { @@ -51,16 +52,18 @@ atf_test_case readslash readslash_body() { [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD allows to read directories" + # shellcheck disable=SC1112 atf_check -s exit:1 -e 'inline:\nError reading ‘/’: Is a directory\n' ../bin/cat / } atf_test_case enoent enoent_body() { + # shellcheck disable=SC1112 atf_check -s exit:1 -e 'inline:\nError opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../bin/cat /var/empty/e/no/ent } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case allfile atf_add_test_case allinput atf_add_test_case alldashinput diff --git a/test-bin/date b/test-bin/date @@ -20,7 +20,7 @@ utc_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case noargs atf_add_test_case epoch atf_add_test_case utc diff --git a/test-bin/dirname b/test-bin/dirname @@ -21,7 +21,7 @@ two_dash_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case noargs atf_add_test_case one_slash atf_add_test_case two_slash diff --git a/test-bin/echo b/test-bin/echo @@ -20,7 +20,7 @@ devfull_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case empty atf_add_test_case hello atf_add_test_case doubledash diff --git a/test-bin/false b/test-bin/false @@ -15,7 +15,7 @@ devfull_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case basic atf_add_test_case nohelp atf_add_test_case devfull diff --git a/test-bin/humanize b/test-bin/humanize @@ -75,7 +75,7 @@ limits_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case noarg atf_add_test_case badflag diff --git a/test-bin/pwd b/test-bin/pwd @@ -11,7 +11,7 @@ args_body() { atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case simple atf_add_test_case args } diff --git a/test-bin/shellcheck b/test-bin/shellcheck @@ -0,0 +1,11 @@ +#!/bin/sh +set -ex + +SHELLCHECK="${SHELLCHECK:-shellcheck}" + +${SHELLCHECK} "$0" + +cd "$(dirname "$0")" + +# shellcheck disable=SC2046 +${SHELLCHECK} --shell=sh $(grep atf_test_program ./Kyuafile | sed -E 's;^atf_test_program\{name="([^"]*)".*;./\1;') diff --git a/test-bin/sname b/test-bin/sname @@ -12,6 +12,6 @@ machine=$(uname -m) } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case generic } diff --git a/test-bin/strings b/test-bin/strings @@ -52,7 +52,7 @@ decformat_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case allbytes atf_add_test_case trueelf diff --git a/test-bin/tee b/test-bin/tee @@ -30,7 +30,7 @@ nullinput_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case allinput atf_add_test_case writefile atf_add_test_case appendfile diff --git a/test-bin/true b/test-bin/true @@ -15,7 +15,7 @@ devfull_body() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case basic atf_add_test_case nohelp atf_add_test_case devfull diff --git a/test-bin/xcd b/test-bin/xcd @@ -23,6 +23,7 @@ atf_test_case noperm cleanup noperm_body() { touch inputs/chmod_000 || atf_fail "touching chmod_000" chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000" + # shellcheck disable=SC1112 atf_check -s exit:1 -e 'inline:\nError opening ‘inputs/chmod_000’: Permission denied\n' -o 'inline:' ../bin/xcd inputs/chmod_000 } noperm_cleanup() { @@ -31,7 +32,7 @@ noperm_cleanup() { } atf_init_test_cases() { - cd "$(atf_get_srcdir)" + cd "$(atf_get_srcdir)" || exit 1 atf_add_test_case openfile atf_add_test_case stdinput atf_add_test_case nullfile