logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 5e3962357625458ab6fef8f4f2eed510369a8411
parent 42020ee157fce1fe38ed01f3aab1f16597a294bf
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  8 Jun 2021 04:44:50 +0200

Move to ATF+Kyua for tests

Diffstat:

A.gitignore4++++
AKyuafile5+++++
MMakefile2+-
MREADME2++
Mbin/dirname.c2+-
Atest-bin/Kyuafile7+++++++
Dtest-bin/Makefile4----
Atest-bin/all_bytes0
Atest-bin/basename29+++++++++++++++++++++++++++++
Dtest-bin/basename.t16----------------
Atest-bin/dirname23+++++++++++++++++++++++
Dtest-bin/dirname.t20--------------------
Atest-bin/xcd10++++++++++
Dtest-bin/xcd.t22----------------------
Rtest-bin/xcd.fixture -> test-bin/xcd_all_bytes.fixture0
15 files changed, 82 insertions(+), 64 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,4 @@ +/bin +!/bin/*.c +/sbin +!/sbin/*.c diff --git a/Kyuafile b/Kyuafile @@ -0,0 +1,5 @@ +syntax(2) + +test_suite("utils") + +include("test-bin/Kyuafile") diff --git a/Makefile b/Makefile @@ -3,7 +3,7 @@ all: cd sbin ; $(MAKE) test: all - cd test-bin ; $(MAKE) test + kyua test clean: cd bin ; $(MAKE) clean diff --git a/README b/README @@ -5,3 +5,5 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only # Dependencies * POSIX System (tested on musl+linux and glibc+linux) * libbsd or a BSD libc for bin/humanize +* (for tests) ATF: <https://github.com/jmmv/atf> +* (for tests) Kyua: <https://github.com/jmmv/kyua> diff --git a/bin/dirname.c b/bin/dirname.c @@ -10,7 +10,7 @@ main(int argc, char *argv[]) { if(argc != 2) { - fputs("usage: dirname string", stderr); + fputs("usage: dirname string\n", stderr); return 1; } diff --git a/test-bin/Kyuafile b/test-bin/Kyuafile @@ -0,0 +1,7 @@ +syntax(2) + +test_suite("utils") + +atf_test_program{name="xcd"} +atf_test_program{name="basename"} +atf_test_program{name="dirname"} diff --git a/test-bin/Makefile b/test-bin/Makefile @@ -1,4 +0,0 @@ -test: - ./xcd.t - ./basename.t - ./dirname.t diff --git a/test-bin/all_bytes b/test-bin/all_bytes Binary files differ. diff --git a/test-bin/basename b/test-bin/basename @@ -0,0 +1,29 @@ +#!/usr/bin/env atf-sh + +atf_test_case noargs +noargs_body() { + atf_check -o "inline:.\n" ../bin/basename +} + +atf_test_case singleslash +singleslash_body() { + atf_check -o "inline:bin\n" ../bin/basename "/usr/bin" +} + +atf_test_case doubleslash +doubleslash_body() { + atf_check -o "inline:bin\n" ../bin/basename "/usr//bin" +} + +atf_test_case testopt +testopt_body() { + atf_check -o "inline:bin\n" ../bin/basename "/usr//bin-test" "-test" +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" + atf_add_test_case noargs + atf_add_test_case singleslash + atf_add_test_case doubleslash + atf_add_test_case testopt +} diff --git a/test-bin/basename.t b/test-bin/basename.t @@ -1,16 +0,0 @@ -#!/bin/sh -failed=0 -path=../bin/basename -status() { - if [[ $2 -eq 0 ]]; then - echo "OK: ${1}" - else - echo "FAILED: ${1}" - failed=1 - fi -} -[[ "$(${path})" == "." ]] ; status "no args" $? -[[ "$(${path} /usr/bin)" == "bin" ]] ; status "/usr/bin" $? -[[ "$(${path} /usr/bin-test -test)" == "bin" ]] ; status "/usr/bin-test -test" $? - -exit $failed diff --git a/test-bin/dirname b/test-bin/dirname @@ -0,0 +1,23 @@ +#!/usr/bin/env atf-sh + +atf_test_case noargs +noargs_body() { + atf_check -e "inline:usage: dirname string\n" -s exit:1 ../bin/dirname +} + +atf_test_case singleslash +singleslash_body() { + atf_check -o "inline:/usr\n" ../bin/dirname "/usr/bin" +} + +atf_test_case doubleslash +doubleslash_body() { + atf_check -o "inline:/usr\n" ../bin/dirname "/usr//bin" +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" + atf_add_test_case noargs + atf_add_test_case singleslash + atf_add_test_case doubleslash +} diff --git a/test-bin/dirname.t b/test-bin/dirname.t @@ -1,20 +0,0 @@ -#!/bin/sh -failed=0 -path=../bin/dirname -status() { - if [ "$2" -eq 0 ]; then - echo "OK: ${1}" - else - echo "FAILED: ${1}" - failed=1 - fi -} -[ "$(${path} 2>/dev/null)" = "" ] ; status "no args" $? -[ "$(${path} /usr/bin)" = "/usr" ] ; status "/usr/bin" $? -[ "$(${path} /usr//bin)" = "/usr" ] ; status "/usr//bin" $? - -## POSIX-tests -#[ "$(${path} //)" = "//" ] ; status "//" $? -#[ "$(${path} ///)" = "///" ] ; status "///" $? - -exit $failed diff --git a/test-bin/xcd b/test-bin/xcd @@ -0,0 +1,10 @@ +#!/usr/bin/env atf-sh +atf_test_case stdinput +stdinput_body() { + atf_check -o file:xcd_all_bytes.fixture ../bin/xcd <all_bytes +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" + atf_add_test_case stdinput +} diff --git a/test-bin/xcd.t b/test-bin/xcd.t @@ -1,22 +0,0 @@ -#!/bin/sh -# all_bytes -( -base64 -d <<EOF -AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4 -OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3Bx -cnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmq -q6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj -5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w== -EOF -) | ../bin/xcd > xcd.out || exit 1 - -diff xcd.fixture xcd.out - -if [[ $? -eq 0 ]] -then - echo "OK: xcd" - rm xcd.out -else - echo "" - echo "FAILED: xcd" -fi diff --git a/test-bin/xcd.fixture b/test-bin/xcd_all_bytes.fixture