logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: e71a0c3461d8214872bcc231ab6aaec4af759811
parent 0ceb03be63a189837ca03e43f638354d7dda092b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  6 Jun 2022 23:17:53 +0200

Merge /bin and /sbin to /cmd

Diffstat:

M.gitignore13+++++--------
M.reuse/dep52+-
MKyuafile3+--
MMakefile56+++++++++++++++++++++++++++++++++++++++++---------------
DMakefile.common21---------------------
Dbin/Makefile33---------------------------------
Rbin/args.1 -> cmd/args.10
Rbin/args.c -> cmd/args.c0
Rbin/basename.1 -> cmd/basename.10
Rbin/basename.c -> cmd/basename.c0
Rbin/cat.1 -> cmd/cat.10
Rbin/cat.c -> cmd/cat.c0
Rbin/date.1 -> cmd/date.10
Rbin/date.c -> cmd/date.c0
Rbin/del.1 -> cmd/del.10
Rbin/del.c -> cmd/del.c0
Rbin/dirname.1 -> cmd/dirname.10
Rbin/dirname.c -> cmd/dirname.c0
Rbin/echo.1 -> cmd/echo.10
Rbin/echo.c -> cmd/echo.c0
Rbin/env.1 -> cmd/env.10
Rbin/env.c -> cmd/env.c0
Rbin/errno.1 -> cmd/errno.10
Rbin/errno.c -> cmd/errno.c0
Rbin/false.1 -> cmd/false.10
Rbin/false.c -> cmd/false.c0
Rbin/humanize.1 -> cmd/humanize.10
Rbin/humanize.c -> cmd/humanize.c0
Rbin/id.c -> cmd/id.c0
Rbin/link.1 -> cmd/link.10
Rbin/link.c -> cmd/link.c0
Rbin/lolcat.1 -> cmd/lolcat.10
Rbin/lolcat.c -> cmd/lolcat.c0
Rbin/mdate.c -> cmd/mdate.c0
Rsbin/memsys.c -> cmd/memsys.c0
Rbin/pwd.c -> cmd/pwd.c0
Rbin/seq.c -> cmd/seq.c0
Rbin/sizeof.c -> cmd/sizeof.c0
Rbin/sname.1 -> cmd/sname.10
Rbin/sname.c -> cmd/sname.c0
Rbin/strings.c -> cmd/strings.c0
Rbin/sync.1 -> cmd/sync.10
Rbin/sync.c -> cmd/sync.c0
Rbin/tee.c -> cmd/tee.c0
Rbin/true.1 -> cmd/true.10
Rbin/true.c -> cmd/true.c0
Rbin/tty.c -> cmd/tty.c0
Rbin/unlink.1 -> cmd/unlink.10
Rbin/unlink.c -> cmd/unlink.c0
Rbin/xcd.c -> cmd/xcd.c0
Mconfigure22++++++----------------
Dsbin/Makefile16----------------
Dtest-bin/Kyuafile34----------------------------------
Dtest-bin/args47-----------------------------------------------
Dtest-bin/basename80-------------------------------------------------------------------------------
Dtest-bin/cat78------------------------------------------------------------------------------
Dtest-bin/date78------------------------------------------------------------------------------
Dtest-bin/del57---------------------------------------------------------
Dtest-bin/dirname38--------------------------------------
Dtest-bin/echo31-------------------------------
Dtest-bin/env63---------------------------------------------------------------
Dtest-bin/errno51---------------------------------------------------
Dtest-bin/false25-------------------------
Dtest-bin/humanize94-------------------------------------------------------------------------------
Dtest-bin/id154-------------------------------------------------------------------------------
Dtest-bin/link35-----------------------------------
Dtest-bin/lolcat92-------------------------------------------------------------------------------
Dtest-bin/mdate13-------------
Dtest-bin/pwd49-------------------------------------------------
Dtest-bin/seq75---------------------------------------------------------------------------
Dtest-bin/sizeof26--------------------------
Dtest-bin/sname33---------------------------------
Dtest-bin/strings123-------------------------------------------------------------------------------
Dtest-bin/tee93-------------------------------------------------------------------------------
Dtest-bin/true25-------------------------
Dtest-bin/tty43-------------------------------------------
Dtest-bin/unlink24------------------------
Dtest-bin/xcd54------------------------------------------------------
Atest-cmd/Kyuafile35+++++++++++++++++++++++++++++++++++
Atest-cmd/args47+++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/basename80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/cat78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/date78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/del57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/dirname38++++++++++++++++++++++++++++++++++++++
Atest-cmd/echo31+++++++++++++++++++++++++++++++
Atest-cmd/env63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/errno51+++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/false25+++++++++++++++++++++++++
Atest-cmd/humanize94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/id154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rtest-bin/inputs/all_bytes -> test-cmd/inputs/all_bytes0
Atest-cmd/inputs/strings/libc_start_main0
Rtest-bin/inputs/strings/true -> test-cmd/inputs/strings/true0
Atest-cmd/link35+++++++++++++++++++++++++++++++++++
Atest-cmd/lolcat92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/mdate13+++++++++++++
Atest-cmd/memsys48++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/mkdir45+++++++++++++++++++++++++++++++++++++++++++++
Rtest-bin/outputs/lolcat/all_bytes -> test-cmd/outputs/lolcat/all_bytes0
Atest-cmd/outputs/lolcat/all_bytes.l12++++++++++++
Rtest-bin/outputs/strings/all_bytes -> test-cmd/outputs/strings/all_bytes0
Rtest-bin/outputs/strings/all_bytes_td -> test-cmd/outputs/strings/all_bytes_td0
Rtest-bin/outputs/strings/all_bytes_to -> test-cmd/outputs/strings/all_bytes_to0
Rtest-bin/outputs/strings/all_bytes_tx -> test-cmd/outputs/strings/all_bytes_tx0
Rtest-bin/outputs/strings/true -> test-cmd/outputs/strings/true0
Rtest-bin/outputs/strings/true_8 -> test-cmd/outputs/strings/true_80
Rtest-bin/outputs/strings/true_8_td -> test-cmd/outputs/strings/true_8_td0
Rtest-bin/outputs/strings/true_8_to -> test-cmd/outputs/strings/true_8_to0
Rtest-bin/outputs/strings/true_8_tx -> test-cmd/outputs/strings/true_8_tx0
Rtest-bin/outputs/strings/true_td -> test-cmd/outputs/strings/true_td0
Rtest-bin/outputs/strings/true_to -> test-cmd/outputs/strings/true_to0
Rtest-bin/outputs/strings/true_tx -> test-cmd/outputs/strings/true_tx0
Rtest-bin/outputs/tee/hello_all_bytes -> test-cmd/outputs/tee/hello_all_bytes0
Rtest-bin/outputs/xcd/all_bytes -> test-cmd/outputs/xcd/all_bytes0
Rtest-bin/outputs/xcd/null -> test-cmd/outputs/xcd/null0
Atest-cmd/pwd49+++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/seq75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rtest-bin/shellcheck -> test-cmd/shellcheck0
Atest-cmd/sizeof26++++++++++++++++++++++++++
Atest-cmd/sname33+++++++++++++++++++++++++++++++++
Atest-cmd/strings123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/tee93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rtest-bin/inputs/all_bytes -> test-cmd/tmp_tee.log0
Atest-cmd/true25+++++++++++++++++++++++++
Atest-cmd/tty43+++++++++++++++++++++++++++++++++++++++++++
Atest-cmd/unlink24++++++++++++++++++++++++
Atest-cmd/xcd54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtest-sbin/Kyuafile10----------
Dtest-sbin/memsys48------------------------------------------------
130 files changed, 1675 insertions(+), 1685 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -2,14 +2,11 @@ # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only /config.mk -/bin/* -!/bin/*.c -!/bin/*.sh -!/bin/*.1 -/sbin/* -!/sbin/*.c -!/sbin/*.sh -!/sbin/*.1 +/target_filter +/cmd/* +!/cmd/*.c +!/cmd/*.ha +!/cmd/*.1 # Kyua /html/ diff --git a/.reuse/dep5 b/.reuse/dep5 @@ -1,6 +1,6 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Source: https://hacktivis.me/git/utils -Files: test-bin/inputs/* test-bin/outputs/* example/* +Files: test-cmd/inputs/* test-cmd/outputs/* example/* Copyright: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> License: CC0-1.0 diff --git a/Kyuafile b/Kyuafile @@ -4,5 +4,4 @@ syntax(2) test_suite("utils") -include("test-bin/Kyuafile") -include("test-sbin/Kyuafile") +include("test-cmd/Kyuafile") diff --git a/Makefile b/Makefile @@ -3,9 +3,15 @@ include config.mk -all: - cd bin ; $(MAKE) - cd sbin ; $(MAKE) +all: $(EXE) + +.c: + rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) -o $@ $< $(LDFLAGS) + +.c.o: + rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) -c -o $@ $< .PHONY: test test: all @@ -14,30 +20,50 @@ test: all .PHONY: lint lint: $(SHELLCHECK) ./configure test_all.sh test_functions.sh ./sh/* - SHELLCHECK=${SHELLCHECK} ./test-bin/shellcheck + SHELLCHECK=${SHELLCHECK} ./test-cmd/shellcheck ${FLAWFINDER} --error-level=4 . - cd bin ; $(MAKE) lint - cd sbin ; $(MAKE) lint + $(MANDOC) -Tlint -Wunsupp,error,warning $(MAN1) clean: - cd bin ; $(MAKE) clean - cd sbin ; $(MAKE) clean + rm -fr $(EXE) + rm -fr ${EXE:=.c.gcov} ${EXE:=.gcda} ${EXE:=.gcno} -install: script-install bin-install +install: script-install cmd-install script-install: mkdir -p $(DESTDIR)$(SHELLDIR)/ $(DESTDIR)$(PERLDIR)/ cp -r sh/* $(DESTDIR)$(SHELLDIR)/ cp -r perl/* $(DESTDIR)$(PERLDIR)/ -bin-install: - cd bin ; $(MAKE) install - cd sbin ; $(MAKE) install +cmd-install: + mkdir -p ${DESTDIR}${BINDIR}/ + cp -p ${EXE} ${DESTDIR}${BINDIR}/ + chown 0:0 ${DESTDIR}${BINDIR}/memsys + chmod 4755 ${DESTDIR}${BINDIR}/memsys + mkdir -p ${DESTDIR}${MANDIR}/man1 + cp -p ${MAN1} ${DESTDIR}${MANDIR}/man1 +.PHONY: coverage coverage: - cd bin ; $(MAKE) coverage - cd sbin ; $(MAKE) coverage + $(GCOV) -b $(EXE) -C_SOURCES = bin/*.c sbin/*.c +C_SOURCES = cmd/*.c format: $(C_SOURCES) clang-format -style=file -assume-filename=.clang-format -i $(C_SOURCES) + +cmd/lolcat: cmd/lolcat.c Makefile + rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) -o $@ $< -lm $(LDFLAGS) + +cmd/xcd: cmd/xcd.c Makefile + rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) -o $@ $< -lm $(LDFLAGS) + +cmd/humanize: cmd/humanize.c Makefile + rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) $(LIBBSD_CFLAGS) -o $@ $< $(LIBBSD_LIBS) $(LDFLAGS) + +cmd/strings: cmd/strings.c Makefile + rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} + $(CC) -std=c99 $(CFLAGS) $(LIBBSD_CFLAGS) -o $@ $< $(LIBBSD_LIBS) $(LDFLAGS) + diff --git a/Makefile.common b/Makefile.common @@ -1,21 +0,0 @@ -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -all: $(EXE) - -.c: - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) -o $@ $< $(LDFLAGS) - -.c.o: - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) -c -o $@ $< - -.PHONY: coverage -coverage: - $(GCOV) -b $(EXE) - -.PHONY: clean -clean: - rm -fr $(EXE) - rm -fr ${EXE:=.c.gcov} ${EXE:=.gcda} ${EXE:=.gcno} diff --git a/bin/Makefile b/bin/Makefile @@ -1,33 +0,0 @@ -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -include config.mk -include ../config.mk -include ../Makefile.common - -.PHONY: lint -lint: - $(MANDOC) -Tlint -Wunsupp,error,warning $(MAN1) - -lolcat: lolcat.c Makefile - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) -o $@ $< -lm $(LDFLAGS) - -xcd: xcd.c Makefile - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) -o $@ $< -lm $(LDFLAGS) - -humanize: humanize.c Makefile - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) $(LIBBSD_CFLAGS) -o $@ $< $(LIBBSD_LIBS) $(LDFLAGS) - -strings: strings.c Makefile - rm -f ${<:=.gcov} ${@:=.gcda} ${@:=.gcno} - $(CC) -std=c99 $(CFLAGS) $(LIBBSD_CFLAGS) -o $@ $< $(LIBBSD_LIBS) $(LDFLAGS) - - -install: - mkdir -p ${DESTDIR}${BINDIR}/ - cp -p ${EXE} ${DESTDIR}${BINDIR}/ - mkdir -p ${DESTDIR}${MANDIR}/man1 - cp -p ${MAN1} ${DESTDIR}${MANDIR}/man1 diff --git a/bin/args.1 b/cmd/args.1 diff --git a/bin/args.c b/cmd/args.c diff --git a/bin/basename.1 b/cmd/basename.1 diff --git a/bin/basename.c b/cmd/basename.c diff --git a/bin/cat.1 b/cmd/cat.1 diff --git a/bin/cat.c b/cmd/cat.c diff --git a/bin/date.1 b/cmd/date.1 diff --git a/bin/date.c b/cmd/date.c diff --git a/bin/del.1 b/cmd/del.1 diff --git a/bin/del.c b/cmd/del.c diff --git a/bin/dirname.1 b/cmd/dirname.1 diff --git a/bin/dirname.c b/cmd/dirname.c diff --git a/bin/echo.1 b/cmd/echo.1 diff --git a/bin/echo.c b/cmd/echo.c diff --git a/bin/env.1 b/cmd/env.1 diff --git a/bin/env.c b/cmd/env.c diff --git a/bin/errno.1 b/cmd/errno.1 diff --git a/bin/errno.c b/cmd/errno.c diff --git a/bin/false.1 b/cmd/false.1 diff --git a/bin/false.c b/cmd/false.c diff --git a/bin/humanize.1 b/cmd/humanize.1 diff --git a/bin/humanize.c b/cmd/humanize.c diff --git a/bin/id.c b/cmd/id.c diff --git a/bin/link.1 b/cmd/link.1 diff --git a/bin/link.c b/cmd/link.c diff --git a/bin/lolcat.1 b/cmd/lolcat.1 diff --git a/bin/lolcat.c b/cmd/lolcat.c diff --git a/bin/mdate.c b/cmd/mdate.c diff --git a/sbin/memsys.c b/cmd/memsys.c diff --git a/bin/pwd.c b/cmd/pwd.c diff --git a/bin/seq.c b/cmd/seq.c diff --git a/bin/sizeof.c b/cmd/sizeof.c diff --git a/bin/sname.1 b/cmd/sname.1 diff --git a/bin/sname.c b/cmd/sname.c diff --git a/bin/strings.c b/cmd/strings.c diff --git a/bin/sync.1 b/cmd/sync.1 diff --git a/bin/sync.c b/cmd/sync.c diff --git a/bin/tee.c b/cmd/tee.c diff --git a/bin/true.1 b/cmd/true.1 diff --git a/bin/true.c b/cmd/true.c diff --git a/bin/tty.c b/cmd/tty.c diff --git a/bin/unlink.1 b/cmd/unlink.1 diff --git a/bin/unlink.c b/cmd/unlink.c diff --git a/bin/xcd.c b/cmd/xcd.c diff --git a/configure b/configure @@ -13,7 +13,6 @@ Variables: BINDIR=DIR SHELLDIR=DIR PERLDIR=DIR - SBINDIR=DIR MANDIR=DIR PKGCONFIG=BIN @@ -59,11 +58,11 @@ pkg_config_check() { gen_targets() { printf 'EXE = ' - printf '%s\n ' *.c | grep -v -f target_filter | sed 's;.c$;;' | tr -d '\n' + printf '%s\n ' cmd/*.c | grep -v -f target_filter | sed 's;.c$;;' | tr -d '\n' echo printf 'MAN1 = ' - printf '%s\n ' *.1 | grep -v -f target_filter | tr -d '\n' + printf '%s\n ' cmd/*.1 | grep -v -f target_filter | tr -d '\n' echo } @@ -123,17 +122,13 @@ done BINDIR="${BINDIR:-${PREFIX}/bin}" SHELLDIR="${SHELLDIR:-${BINDIR}}" PERLDIR="${PERLDIR:-${BINDIR}}" -SBINDIR="${SBINDIR:-${PREFIX}/sbin}" MANDIR="${MANDIR:-${PREFIX}/share/man}" # Add some extra CFLAGS CFLAGS="${CFLAGS} ${EXTRA_CFLAGS}" printf 'Pruning old configurations ...' -rm -f config.mk bin/config.mk sbin/config.mk \ - && echo '#' > bin/target_filter \ - && echo '#' > sbin/target_filter \ - ; or_die +rm -f config.mk && echo '#' > target_filter ; or_die ## System checks # commands @@ -187,7 +182,7 @@ then LIBBSD_CFLAGS="$("${PKGCONFIG}" --cflags libbsd-overlay) -DHAVE_LIBBSD" LIBBSD_LIBS="$("${PKGCONFIG}" --libs libbsd-overlay)" else - cat >> bin/target_filter <<EOF + cat >> target_filter <<EOF # strtonum strings.c strings.1 @@ -202,12 +197,6 @@ echo ## Configuration write -printf 'Writing bin/config.mk ...' -(cd bin && gen_targets) > bin/config.mk ; or_die - -printf 'Writing sbin/config.mk ...' -(cd sbin && gen_targets) > sbin/config.mk ; or_die - printf 'Writing to config.mk ...' cat >config.mk <<EOF # Autogenerated by ./configure @@ -215,7 +204,6 @@ PREFIX = ${PREFIX} BINDIR = ${BINDIR} SHELLDIR = ${SHELLDIR} PERLDIR = ${PERLDIR} -SBINDIR = ${SBINDIR} MANDIR = ${MANDIR} PKGCONFIG = ${PKGCONFIG} @@ -236,6 +224,8 @@ LIBBSD_LIBS = ${LIBBSD_LIBS} EOF is_ok +gen_targets >> config.mk ; or_die + echo echo 'Done, you can now run make' diff --git a/sbin/Makefile b/sbin/Makefile @@ -1,16 +0,0 @@ -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -include config.mk -include ../config.mk -include ../Makefile.common - -.PHONY: lint -lint: - : - -install: - mkdir -p ${DESTDIR}${SBINDIR}/ - cp -p memsys ${DESTDIR}${SBINDIR}/ - chown 0:0 ${DESTDIR}${SBINDIR}/memsys - chmod 4755 ${DESTDIR}${SBINDIR}/memsys diff --git a/test-bin/Kyuafile b/test-bin/Kyuafile @@ -1,34 +0,0 @@ --- SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> --- SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only -syntax(2) - -test_suite("utils") - -basedir = fs.dirname(fs.dirname(current_kyuafile())) - --- 7,$|LC_ALL=C.UTF-8 sort -atf_test_program{name="args", required_files=basedir.."/bin/args", timeout=1} -atf_test_program{name="basename", required_files=basedir.."/bin/basename", timeout=1} -atf_test_program{name="cat", required_files=basedir.."/bin/cat", timeout=1} -atf_test_program{name="date", required_files=basedir.."/bin/date", timeout=1} -atf_test_program{name="del", required_files=basedir.."/bin/del", timeout=1} -atf_test_program{name="dirname", required_files=basedir.."/bin/dirname", timeout=1} -atf_test_program{name="echo", required_files=basedir.."/bin/echo", timeout=1} -atf_test_program{name="env", required_files=basedir.."/bin/env", timeout=1} -atf_test_program{name="errno", required_files=basedir.."/bin/errno", timeout=1} -atf_test_program{name="false", required_files=basedir.."/bin/false", timeout=1} -atf_test_program{name="humanize", required_files=basedir.."/bin/humanize", timeout=1} -atf_test_program{name="id", required_files=basedir.."/bin/id", timeout=1} -atf_test_program{name="link", required_files=basedir.."/bin/link", timeout=1} -atf_test_program{name="lolcat", required_files=basedir.."/bin/lolcat", timeout=1} -atf_test_program{name="mdate", required_files=basedir.."/bin/mdate", timeout=1} -atf_test_program{name="pwd", required_files=basedir.."/bin/pwd", timeout=1} -atf_test_program{name="seq", required_files=basedir.."/bin/seq", timeout=1} -atf_test_program{name="sizeof", required_files=basedir.."/bin/sizeof", timeout=1} -atf_test_program{name="sname", required_files=basedir.."/bin/sname", timeout=1} -atf_test_program{name="strings", required_files=basedir.."/bin/strings", timeout=1} -atf_test_program{name="tee", required_files=basedir.."/bin/tee", timeout=1} -atf_test_program{name="true", required_files=basedir.."/bin/true", timeout=1} -atf_test_program{name="tty", required_files=basedir.."/bin/tty", timeout=1} -atf_test_program{name="xcd", required_files=basedir.."/bin/xcd", timeout=1} -atf_test_program{name="unlink", required_files=basedir.."/bin/unlink", timeout=1} diff --git a/test-bin/args b/test-bin/args @@ -1,47 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - - -atf_test_case noargs -noargs_body() { - atf_check -o 'inline:argc: 1 -argv[0]: "../bin/args" -' ../bin/args -} - -atf_test_case onearg -onearg_body() { - atf_check -o 'inline:argc: 2 -argv[0]: "../bin/args" -argv[1]: "a" -' ../bin/args a -} - -atf_test_case twoargs -twoargs_body() { - atf_check -o 'inline:argc: 3 -argv[0]: "../bin/args" -argv[1]: "a" -argv[2]: "b c" -' ../bin/args a 'b c' -} - -atf_test_case options -options_body() { - atf_check -o 'inline:argc: 5 -argv[0]: "../bin/args" -argv[1]: "-1" -argv[2]: "+2" -argv[3]: "--3" -argv[4]: "/4" -' ../bin/args -1 +2 --3 /4 -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case noargs - atf_add_test_case onearg - atf_add_test_case twoargs - atf_add_test_case options -} diff --git a/test-bin/basename b/test-bin/basename @@ -1,80 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - - -atf_test_case noargs -noargs_body() { - atf_check -o "inline:.\n" ../bin/basename -} - -atf_test_case one_slash -one_slash_body() { - atf_check -o "inline:bin\n" ../bin/basename "/usr/bin" -} - -atf_test_case two_slash -two_slash_body() { - atf_check -o "inline:bin\n" ../bin/basename "/usr//bin" -} - -atf_test_case two_dash -two_dash_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_test_case usage -usage_body() { - atf_check -s exit:1 -e "inline:usage: basename string [suffix]\n" ../bin/basename 1 2 3 -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../bin/basename >/dev/full' - atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../bin/basename "/usr/bin" >/dev/full' - atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../bin/basename "/usr//bin-test" "-test" >/dev/full' -} - -atf_test_case nullarg -nullarg_body() { - atf_check -e "inline:.\n" ../bin/basename "$(printf '\x00')" - atf_check -e "inline:bin\n" ../bin/basename "/usr/bin" "$(printf '\x00')" -} - -atf_test_case doubledash -doubledash_body() { - atf_check -o 'inline:-\n' -- ../bin/basename '-' - atf_check -o 'inline:.\n' -- ../bin/basename '--' - atf_check -o 'inline:--\n' -- ../bin/basename --a a - atf_check -o 'inline:---\n' -- ../bin/basename '---' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case noargs - atf_add_test_case one_slash - atf_add_test_case two_slash - atf_add_test_case two_dash - atf_add_test_case testopt - atf_add_test_case usage - - # puts in glibc doesn't returns -1 on failure - atf_add_test_case devfull - - # Broken behavior in ATF, might be caused by stripping out \x00 - #atf_add_test_case nullarg - - atf_add_test_case doubledash -} diff --git a/test-bin/cat b/test-bin/cat @@ -1,78 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case allfile -allfile_body() { - atf_check -o file:inputs/all_bytes ../bin/cat inputs/all_bytes -} - -atf_test_case allinput -allinput_body() { - atf_check -o file:inputs/all_bytes ../bin/cat <inputs/all_bytes -} - -atf_test_case alldashinput -alldashinput_body() { - atf_check -o file:inputs/all_bytes ../bin/cat - <inputs/all_bytes -} - -atf_test_case devnull -devnull_body() { - atf_check ../bin/cat /dev/null - atf_check ../bin/cat </dev/null - atf_check ../bin/cat - </dev/null -} - -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() { - chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" - rm inputs/chmod_000 || atf_fail "rm chmod_000" -} - -atf_test_case devfull -devfull_body() { - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/cat inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/cat <inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/cat - <inputs/all_bytes >/dev/full' -} - -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_test_case doubledash -doubledash_body() { - atf_check -o file:inputs/all_bytes -- ../bin/cat -- inputs/all_bytes - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:\nError opening ‘---’: No such file or directory\n' -o empty -- ../bin/cat --- inputs/all_bytes -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case allfile - atf_add_test_case allinput - atf_add_test_case alldashinput - atf_add_test_case devnull - atf_add_test_case noperm - atf_add_test_case devfull - atf_add_test_case readslash - atf_add_test_case enoent - atf_add_test_case doubledash -} diff --git a/test-bin/date b/test-bin/date @@ -1,78 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case noargs -noargs_body() { - atf_check -o not-empty ../bin/date -} - -atf_test_case badarg -badarg_body() { - atf_check -s 'exit:1' -e "inline:Error: Unrecognised option: '-x'\ndate [-u][-d datetime] [+format]\n" ../bin/date -x -} - -atf_test_case epoch -epoch_body() { - atf_check -o "match:^[0-9]+$" ../bin/date '+%s' -} - -atf_test_case rfc3339 -rfc3339_body() { - atf_check -o "match:^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{4}$" ../bin/date '+%FT%T%z' -} - -atf_test_case empty -empty_body() { - atf_check -o 'inline:\n' ../bin/date '+' -} - -atf_test_case echolike -echolike_body() { - atf_check -o 'inline:hello world\n' ../bin/date '+hello world' -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 -e 'inline:puts: No space left on device\n' sh -c '../bin/date >/dev/full' -} - -atf_test_case utc -utc_body() { - atf_check -o "match:^[0-9]+$" ../bin/date -u '+%s' -} - -atf_test_case timestamp -timestamp_body() { - atf_check -o "inline:1970-01-01T00:00:00\n" ../bin/date -u -d @0 '+%FT%T' - atf_check -o "inline:1970-01-01T00:01:09\n" ../bin/date -u -d @69 '+%FT%T' - atf_check -o "inline:1969-12-31T23:58:51\n" ../bin/date -u -d @-69 '+%FT%T' - - atf_check -s 'exit:1' -e "inline:Error: Missing operand for option: '-d'\ndate [-u][-d datetime] [+format]\n" ../bin/date -u -d - atf_check -s 'exit:1' ../bin/date -u -d 69 - - # 36893488147419103232 = 2^65 - atf_check -s 'exit:1' -e not-empty ../bin/date -u -d @36893488147419103232 -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case noargs - atf_add_test_case badarg - atf_add_test_case empty - atf_add_test_case echolike - atf_add_test_case devfull - - atf_add_test_case epoch - atf_add_test_case rfc3339 - atf_add_test_case utc - - atf_add_test_case timestamp -} diff --git a/test-bin/del b/test-bin/del @@ -1,57 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case basic cleanup -basic_body() { - touch inputs/del-test || atf_fail "touching del-test" - atf_check ../bin/del inputs/del-test - - mkdir -p inputs/del-test.d || atf_fail "mkdir del-test.d" - atf_check ../bin/del inputs/del-test.d -} -basic_cleanup() { - rm -fr inputs/del-test inputs/del-test.d || atf_fail "rm inputs/del-test{,.d}" -} - -atf_test_case nopermf cleanup -nopermf_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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../bin/del inputs/chmod_000 -} -nopermf_cleanup() { - rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}" -} - -atf_test_case nopermd cleanup -nopermd_body() { - mkdir -p inputs/chmod_000.d || atf_fail "mkdir chmod_000.d" - chmod 0000 inputs/chmod_000.d || atf_fail "chmod 0000 chmod_000.d" - - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:Error opening ‘inputs/chmod_000’: Permission denied\n' ../bin/del inputs/chmod_000.d -} -nopermd_cleanup() { - rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}" -} - -atf_test_case enoent -enoent_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:remove(/var/empty/e/no/ent) error: No such file or directory\n' ../bin/del /var/empty/e/no/ent -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case basic - - # None of the supported implementations of remove(3) seem to have checks - # based on file mode - #atf_add_test_case nopermf - #atf_add_test_case nopermd - - atf_add_test_case enoent -} diff --git a/test-bin/dirname b/test-bin/dirname @@ -1,38 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - - -atf_test_case noargs -noargs_body() { - atf_check -e "inline:usage: dirname string\n" -s exit:1 ../bin/dirname -} - -atf_test_case one_slash -one_slash_body() { - atf_check -o "inline:/usr\n" ../bin/dirname "/usr/bin" -} - -atf_test_case two_slash -two_slash_body() { - atf_check -o "inline:/usr\n" ../bin/dirname "/usr//bin" -} - -atf_test_case two_dash -two_dash_body() { - atf_check -o "inline:/usr\n" ../bin/dirname -- "/usr//bin" -} - -atf_test_case badarg -badarg_body() { - atf_check -s exit:1 -e "inline:usage: dirname string\n" ../bin/dirname -a "/usr//bin" -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case noargs - atf_add_test_case badarg - atf_add_test_case one_slash - atf_add_test_case two_slash - atf_add_test_case two_dash -} diff --git a/test-bin/echo b/test-bin/echo @@ -1,31 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case empty -empty_body() { - atf_check -o "inline:\n" ../bin/echo -} - -atf_test_case hello -hello_body() { - atf_check -o "inline:hello world\n" ../bin/echo hello world -} - -atf_test_case doubledash -doubledash_body() { - atf_check -o "inline:-- hello\n" ../bin/echo -- hello -} - -atf_test_case devfull -devfull_body() { - atf_check -s exit:1 -e 'inline:write(1, buffer, arg_len): No space left on device\n' sh -c '../bin/echo hello world >/dev/full' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case empty - atf_add_test_case hello - atf_add_test_case doubledash - atf_add_test_case devfull -} diff --git a/test-bin/env b/test-bin/env @@ -1,63 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case noargs -noargs_body() { - [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment" - - atf_check -o "inline:FOO=BAR\n" env -i FOO=BAR ../bin/env -} - -atf_test_case badarg -badarg_body() { - atf_check -s not-exit:0 -e "inline:Error: Unrecognised option: '-f'\nenv [-i] [-u key] [key=value ...] [command [args]]\n" ../bin/env -f -} - -atf_test_case iflag -iflag_body() { - [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment" - - atf_check -o "inline:FOO=BAR\n" ../bin/env -i FOO=BAR ../bin/env - atf_check -o "inline:FOO=BAR\n" ../bin/env -i FOO=BAR - atf_check -o "not-inline:FOO=BAR\n" ../bin/env FOO=BAR ../bin/env - atf_check -o "not-inline:FOO=BAR\n" ../bin/env FOO=BAR -} - -atf_test_case uflag -uflag_body() { - [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment" - - atf_check -o "inline:FOO=BAR\n" ../bin/env -i FOO=BAR BAR=FOO ../bin/env -u BAR - - atf_check -s not-exit:0 -e "inline:Error: Missing operand for option: '-u'\nenv [-i] [-u key] [key=value ...] [command [args]]\n" ../bin/env -u -} - -atf_test_case devfull -devfull_body() { - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 -e 'inline:env: puts: No space left on device\n' sh -c '../bin/env >/dev/full' -} - -atf_test_case noutil -noutil_body() { - atf_check -s exit:127 -e 'inline:env: execve: No such file or directory\n' ../bin/env /var/empty/e/no/ent -} - -atf_test_case false -false_body() { - atf_check -s exit:1 ../bin/env false -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case noargs - atf_add_test_case badarg - atf_add_test_case iflag - atf_add_test_case uflag - atf_add_test_case devfull - atf_add_test_case noutil - atf_add_test_case false -} diff --git a/test-bin/errno b/test-bin/errno @@ -1,51 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case simple -simple_body() { - atf_check -o "inline:Operation not permitted\n" ../bin/errno 1 -} - -atf_test_case noargs -noargs_body() { - atf_check -s exit:1 -o "inline:usage: errno <number>\n" ../bin/errno -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 sh -c '../bin/errno 1 >/dev/full' -} - -atf_test_case einval -einval_body() { - if has_glibc; then - atf_check -s exit:0 -o "inline:Unknown error -1\n" ../bin/errno -1 - elif has_musl; then - atf_check -s exit:0 -o "inline:No error information\n" ../bin/errno -1 - else - atf_check -s exit:1 -e "inline:errno: strerror: Invalid argument\n" ../bin/errno -1 - fi -} - -atf_test_case erange -erange_body() { - # 36893488147419103232 = 2^65 - atf_check -s 'exit:1' -e not-empty ../bin/errno 36893488147419103232 -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case simple - atf_add_test_case noargs - atf_add_test_case devfull - atf_add_test_case einval - atf_add_test_case erange -} diff --git a/test-bin/false b/test-bin/false @@ -1,25 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case basic -basic_body() { - atf_check -s exit:1 ../bin/false -} - -atf_test_case nohelp -nohelp_body() { - atf_check -s exit:1 ../bin/false --help -} - -atf_test_case devfull -devfull_body() { - atf_check -s exit:1 ../bin/false --help >/dev/full -} - -atf_init_test_cases() { - 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 @@ -1,94 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case one -one_body() { - atf_check -o "inline:1 \n" ../bin/humanize 1 - atf_check -o "inline:1 \n" ../bin/humanize -d 1 - atf_check -o "inline:1 B\n" ../bin/humanize -b 1 -} - -atf_test_case two -two_body() { - atf_check -o "inline:12 \n" ../bin/humanize 12 - atf_check -o "inline:12 \n" ../bin/humanize -d 12 - atf_check -o "inline:12 B\n" ../bin/humanize -b 12 -} - -atf_test_case three -three_body() { - atf_check -o "inline:123 \n" ../bin/humanize 123 - atf_check -o "inline:123 \n" ../bin/humanize -d 123 - atf_check -o "inline:123 B\n" ../bin/humanize -b 123 -} - -# 1 234 -atf_test_case four -four_body() { - atf_check -o "inline:1.234 k\n" ../bin/humanize 1234 - atf_check -o "inline:1.234 k\n" ../bin/humanize -d 1234 - atf_check -o "inline:1.20508 KiB\n" ../bin/humanize -b 1234 -} - -# 12 345 -atf_test_case five -five_body() { - atf_check -o "inline:12.345 k\n" ../bin/humanize 12345 - atf_check -o "inline:12.345 k\n" ../bin/humanize -d 12345 - atf_check -o "inline:12.0557 KiB\n" ../bin/humanize -b 12345 -} - -# 123 456 -atf_test_case six -six_body() { - atf_check -o "inline:123.456 k\n" ../bin/humanize 123456 - atf_check -o "inline:123.456 k\n" ../bin/humanize -d 123456 - atf_check -o "inline:120.562 KiB\n" ../bin/humanize -b 123456 -} - -# 1234 4567 -atf_test_case seven -seven_body() { - atf_check -o "inline:1.23457 M\n" ../bin/humanize 1234567 - atf_check -o "inline:1.23457 M\n" ../bin/humanize -d 1234567 - atf_check -o "inline:1.17737 MiB\n" ../bin/humanize -b 1234567 -} - -atf_test_case noarg -noarg_body() { - atf_check -s exit:1 -e 'inline:Usage: humanize [-bd] number\n' ../bin/humanize -} - -atf_test_case badflag -badflag_body() { - atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../bin/humanize -f - atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../bin/humanize -f 123 -} - -atf_test_case limits -limits_body() { - atf_check -o 'inline:9.22337 E\n' ../bin/humanize 9223372036854775807 - atf_check -s exit:1 -e 'inline:humanize: strtonum: 9223372036854775808 is too large\n' ../bin/humanize 9223372036854775808 - - # Not as great as it should but at least not a lie - atf_check -o 'inline:-9.22337e+18 \n' ../bin/humanize -- -9223372036854775808 - - atf_check -s exit:1 -e 'inline:humanize: strtonum: -9223372036854775809 is too small\n' ../bin/humanize -- -9223372036854775809 -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - atf_add_test_case noarg - atf_add_test_case badflag - atf_add_test_case limits - - atf_add_test_case one - atf_add_test_case two - atf_add_test_case three - atf_add_test_case four - atf_add_test_case five - atf_add_test_case six - atf_add_test_case seven -} diff --git a/test-bin/id b/test-bin/id @@ -1,154 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case noargs cleanup -noargs_body() { - atf_check -o save:noargs.out ../bin/id - atf_check grep -q "uid=$(id -u)($(id -un)) gid=$(id -g)($(id -gn)) groups=" noargs.out -} -noargs_cleanup() { - rm -f noargs.out -} - -atf_test_case names cleanup -names_body() { - atf_check -o save:names.out ../bin/id -n - atf_check grep -q "uid=$(id -un) gid=$(id -gn) groups=" names.out -} -names_cleanup() { - rm -f names.out -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 sh -c '../bin/id >/dev/full' - atf_check -s exit:1 sh -c '../bin/id -n >/dev/full' - atf_check -s exit:1 sh -c '../bin/id -u >/dev/full' - atf_check -s exit:1 sh -c '../bin/id -g >/dev/full' -} - -atf_test_case group -group_body() { - atf_check -o "inline:$(id -g)\n" ../bin/id -g - atf_check -o "inline:$(id -gr)\n" ../bin/id -gr - atf_check -o "inline:$(id -gn)\n" ../bin/id -gn - atf_check -o "inline:$(id -gnr)\n" ../bin/id -gnr -} - -atf_test_case user -user_body() { - atf_check -o "inline:$(id -u)\n" ../bin/id -u - atf_check -o "inline:$(id -ur)\n" ../bin/id -ur - atf_check -o "inline:$(id -un)\n" ../bin/id -un - atf_check -o "inline:$(id -unr)\n" ../bin/id -unr -} - -atf_test_case groups -groups_body() { - # sadly GNU coreutils' id(1) sorts it's grouplist - - atf_check -o not-empty ../bin/id -G - atf_check -o not-empty ../bin/id -Gr - atf_check -o not-empty ../bin/id -Gn - atf_check -o not-empty ../bin/id -Gnr -} - -atf_test_case noetc -noetc_body() { - bwrap_args="--bind / / --bind /var/empty /etc" - - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - set -f - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -u - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for user ID $(id -u)\n" -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -un - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -g - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for group ID $(id -g)\n" -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -gn -} - -atf_test_case nopasswd -nopasswd_body() { - bwrap_args="--bind / / --bind /dev/null /etc/passwd" - - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - set -f - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -u - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for user ID $(id -u)\n" -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -un - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -g - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -gn)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -gn -} - -atf_test_case nogroup -nogroup_body() { - bwrap_args="--bind / / --bind /dev/null /etc/group" - - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - set -f - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -u - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -un)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -un - - # shellcheck disable=SC2086 - atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -g - # shellcheck disable=SC2086 - atf_check -s exit:1 -e "inline:id: cannot find name for group ID $(id -g)\n" -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../bin/id -gn -} - -atf_test_case badarg -badarg_body() { - atf_check -s exit:1 -e 'inline:Usage: id [-Ggu] [-nr] [user]\n' ../bin/id -a -} - -atf_test_case root cleanup -root_body() { - atf_check -o save:root.out ../bin/id root - atf_check grep -q "uid=$(id -u root)($(id -un root)) gid=$(id -g root)($(id -gn root)) groups=" root.out -} -root_cleanup() { - rm -f root.out -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case devfull - atf_add_test_case badarg - - atf_add_test_case noargs - atf_add_test_case names - atf_add_test_case group - atf_add_test_case user - atf_add_test_case groups - - atf_add_test_case noetc - atf_add_test_case nogroup - atf_add_test_case nopasswd - - atf_add_test_case root -} diff --git a/test-bin/link b/test-bin/link @@ -1,35 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case empty -empty_body() { - atf_check -s exit:1 -e "inline:usage: link <reference> <destination>\n" ../bin/link -} - -atf_test_case basic cleanup -basic_body() { - touch foo - - atf_check ../bin/link foo bar - atf_check cmp foo bar - - echo hello >> foo - atf_check cmp foo bar -} -basic_cleanup() { - atf_check rm -f foo bar -} - -atf_test_case enoent -enoent_body() { - atf_check -s exit:1 -e 'inline:link: No such file or directory\n' ../bin/link /var/empty/e/no/ent enoent_foo - atf_check -s exit:1 -e 'inline:link: No such file or directory\n' ../bin/link enoent_bar /var/empty/e/no/ent -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case empty - atf_add_test_case basic - atf_add_test_case enoent -} diff --git a/test-bin/lolcat b/test-bin/lolcat @@ -1,92 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case allfile -allfile_body() { - atf_check -o file:outputs/lolcat/all_bytes ../bin/lolcat inputs/all_bytes -} - -atf_test_case allinput -allinput_body() { - atf_check -o file:outputs/lolcat/all_bytes ../bin/lolcat <inputs/all_bytes -} - -atf_test_case alldashinput -alldashinput_body() { - atf_check -o file:outputs/lolcat/all_bytes ../bin/lolcat - <inputs/all_bytes -} - -atf_test_case devnull -devnull_body() { - if [ "$(uname -s)" = "FreeBSD" ] || [ "$(uname -s)" = "NetBSD" ]; then - # FIXME - atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../bin/lolcat /dev/null - atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../bin/lolcat </dev/null - atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../bin/lolcat - </dev/null - else - atf_check -o 'inline:' ../bin/lolcat /dev/null - atf_check -o 'inline:' ../bin/lolcat </dev/null - atf_check -o 'inline:' ../bin/lolcat - </dev/null - fi -} - -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/lolcat inputs/chmod_000 -} -noperm_cleanup() { - chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" - rm inputs/chmod_000 || atf_fail "rm chmod_000" -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for fputc()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD badly handling write errors" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD badly handling write errors" - - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/lolcat inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/lolcat <inputs/all_bytes >/dev/full' - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/lolcat - <inputs/all_bytes >/dev/full' -} - -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:\nRead error: Is a directory\n' -o 'inline:' ../bin/lolcat ./ -} - -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' -o 'inline:' ../bin/lolcat /var/empty/e/no/ent -} - -atf_test_case doubledash -doubledash_body() { - atf_check -o file:outputs/lolcat/all_bytes -- ../bin/lolcat -- inputs/all_bytes - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:\nError opening ‘---’: No such file or directory\n' -o 'inline:' -- ../bin/lolcat --- inputs/all_bytes -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case allfile - atf_add_test_case allinput - atf_add_test_case alldashinput - atf_add_test_case devnull - atf_add_test_case noperm - atf_add_test_case devfull - atf_add_test_case readslash - atf_add_test_case enoent - atf_add_test_case doubledash -} diff --git a/test-bin/mdate b/test-bin/mdate @@ -1,13 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case basic -basic_body() { - atf_check -o "match:^[0-9A-F]+,[0-9A-F]+$" ../bin/mdate -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case basic -} diff --git a/test-bin/pwd b/test-bin/pwd @@ -1,49 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case simple -simple_body() { - atf_check -o "inline:${PWD}\n" ../bin/pwd - atf_check -o "inline:$(atf_get_srcdir)\n" ../bin/pwd -} - -atf_test_case args -args_body() { - atf_check -s exit:1 -e "inline:usage: pwd\n" ../bin/pwd -H -} - -atf_test_case enoent cleanup -enoent_body() { - mkdir -p "$(atf_get_srcdir)/remove-me" || exit 1 - cd "$(atf_get_srcdir)/remove-me" || exit 1 - - atf_check -o "inline:$(atf_get_srcdir)/remove-me\n" "$(atf_get_srcdir)/../bin/pwd" - - rm -fr "$(atf_get_srcdir)/remove-me" || exit 1 - - atf_check -s exit:1 -e 'inline:getcwd: No such file or directory\n' "$(atf_get_srcdir)/../bin/pwd" -} -enoent_cleanup() { - rm -fr "$(atf_get_srcdir)/remove-me" -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 sh -c '../bin/pwd >/dev/full' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case simple - atf_add_test_case args - atf_add_test_case enoent - atf_add_test_case devfull -} diff --git a/test-bin/seq b/test-bin/seq @@ -1,75 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case one -one_body() { - atf_check -o "inline:1\n" ../bin/seq 1 - atf_check -o "inline:1\n2\n3\n4\n5\n" ../bin/seq 5 - - atf_check -o "inline:1\n0\n-1\n" -- ../bin/seq -- -1 - atf_check -o "inline:1\n0\n-1\n-2\n-3\n-4\n-5\n" -- ../bin/seq -- -5 -} - -atf_test_case two -two_body() { - atf_check -o "inline:0\n1\n" ../bin/seq 0 1 - atf_check -o "inline:0\n1\n2\n3\n4\n5\n" ../bin/seq 0 5 - atf_check -o "inline:10\n11\n12\n13\n14\n15\n" ../bin/seq 10 15 - - atf_check -o "inline:0\n-1\n" -- ../bin/seq 0 -1 - atf_check -o "inline:0\n-1\n-2\n-3\n-4\n-5\n" -- ../bin/seq 0 -5 - atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" -- ../bin/seq -- -10 -15 - atf_check -o "inline:2\n1\n0\n-1\n-2\n" -- ../bin/seq 2 -2 - atf_check -o "inline:-2\n-1\n0\n1\n2\n" -- ../bin/seq -- -2 2 -} - -atf_test_case three -three_body() { - atf_check -o "inline:0\n1\n" ../bin/seq 0 1 1 - atf_check -o "inline:0\n1\n2\n3\n4\n5\n" ../bin/seq 0 1 5 - atf_check -o "inline:10\n11\n12\n13\n14\n15\n" ../bin/seq 10 1 15 - - atf_check -o "inline:0\n2\n4\n" ../bin/seq 0 2 5 - atf_check -o "inline:10\n12\n14\n" ../bin/seq 10 2 15 - - atf_check -o "inline:0\n-1\n" -- ../bin/seq 0 1 -1 - atf_check -o "inline:0\n-1\n-2\n-3\n-4\n-5\n" -- ../bin/seq 0 1 -5 - atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" -- ../bin/seq -- -10 1 -15 - - atf_check -o "inline:0\n-1\n" -- ../bin/seq 0 -1 -1 - - atf_check -o "inline:0\n-2\n-4\n" -- ../bin/seq 0 2 -5 - atf_check -o "inline:-10\n-12\n-14\n" -- ../bin/seq -- -10 2 -15 -} - -atf_test_case noarg -noarg_body() { - atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../bin/seq -} - -atf_test_case badflag -badflag_body() { - atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../bin/seq -f -} - -atf_test_case limits -limits_body() { - atf_check ../bin/seq 9223372036854775806 9223372036854775807 - atf_check -s exit:1 ../bin/seq 9223372036854775806 9223372036854775808 - - atf_check ../bin/seq -- -9223372036854775807 -9223372036854775808 - atf_check -s exit:1 ../bin/seq -- -9223372036854775807 -9223372036854775809 -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - atf_add_test_case one - atf_add_test_case two - atf_add_test_case three - - atf_add_test_case noarg - atf_add_test_case badflag - #atf_add_test_case limits -} diff --git a/test-bin/sizeof b/test-bin/sizeof @@ -1,26 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case empty -empty_body() { - atf_check -o not-empty ../bin/sizeof -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for printf()" - [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for printf()" - [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for printf()" - - atf_check -s exit:1 sh -c '../bin/sizeof >/dev/full' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case empty - atf_add_test_case devfull -} diff --git a/test-bin/sname b/test-bin/sname @@ -1,33 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case generic -generic_body() { - # sed is because of FreeBSD - atf_check -o "inline:\ -sysname=$(uname -s) -nodename=$(uname -n) -release=$(uname -r) -version=$(uname -v | sed 's; *$;;') -machine=$(uname -m) -" ../bin/sname -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 -e 'inline:sname: No space left on device\n' sh -c '../bin/sname >/dev/full' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case generic - atf_add_test_case devfull -} diff --git a/test-bin/strings b/test-bin/strings @@ -1,123 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case allbytes -allbytes_body() { - atf_check -o file:outputs/strings/all_bytes ../bin/strings inputs/all_bytes - atf_check -o file:outputs/strings/all_bytes ../bin/strings <inputs/all_bytes - atf_check -o file:outputs/strings/all_bytes ../bin/strings - <inputs/all_bytes -} - -atf_test_case trueelf -trueelf_body() { - atf_check -o file:outputs/strings/true ../bin/strings inputs/strings/true - atf_check -o file:outputs/strings/true ../bin/strings <inputs/strings/true - atf_check -o file:outputs/strings/true ../bin/strings - <inputs/strings/true -} - -atf_test_case true8elf -true8elf_body() { - atf_check -o file:outputs/strings/true_8 ../bin/strings -n 8 inputs/strings/true - atf_check -o file:outputs/strings/true_8 ../bin/strings -n 8 <inputs/strings/true - atf_check -o file:outputs/strings/true_8 ../bin/strings -n 8 - <inputs/strings/true -} - -atf_test_case devnull -devnull_body() { - atf_check ../bin/strings /dev/null - atf_check ../bin/strings </dev/null - atf_check ../bin/strings - </dev/null -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/strings inputs/strings/true >/dev/full' -} - -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/strings inputs/chmod_000 -} -noperm_cleanup() { - chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" - rm inputs/chmod_000 || atf_fail "rm chmod_000" -} - -atf_test_case octalformat -octalformat_body() { - atf_check -o file:outputs/strings/all_bytes_to ../bin/strings -to inputs/all_bytes - atf_check ../bin/strings -to /dev/null - atf_check -o file:outputs/strings/true_to ../bin/strings -to inputs/strings/true - atf_check -o file:outputs/strings/true_8_to ../bin/strings -to -n 8 inputs/strings/true -} - -atf_test_case hexformat -hexformat_body() { - atf_check -o file:outputs/strings/all_bytes_tx ../bin/strings -tx inputs/all_bytes - atf_check ../bin/strings -tx /dev/null - atf_check -o file:outputs/strings/true_tx ../bin/strings -tx inputs/strings/true - atf_check -o file:outputs/strings/true_8_tx ../bin/strings -tx -n 8 inputs/strings/true -} - -atf_test_case decformat -decformat_body() { - atf_check -o file:outputs/strings/all_bytes_td ../bin/strings -td inputs/all_bytes - atf_check ../bin/strings -td /dev/null - atf_check -o file:outputs/strings/true_td ../bin/strings -td inputs/strings/true - atf_check -o file:outputs/strings/true_8_td ../bin/strings -td -n 8 inputs/strings/true -} - -atf_test_case badformat -badformat_body() { - usage="strings: [-a] [-t format] [-n number] [file...]\n" - - atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../bin/strings -tt inputs/all_bytes - atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../bin/strings -tt /dev/null - atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../bin/strings -tt inputs/strings/true - atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../bin/strings -tt -n 8 inputs/strings/true -} - -atf_test_case erange_n -erange_n_body() { - usage="strings: [-a] [-t format] [-n number] [file...]\n" - - atf_check -s exit:1 -e "inline:Minimal string length is too small: 0\n${usage}" -- ../bin/strings -n 0 inputs/all_bytes - atf_check -s exit:1 -e "inline:Minimal string length is too large: 4097\n${usage}" -- ../bin/strings -n 4097 inputs/all_bytes - atf_check -s exit:1 -e "inline:Minimal string length is invalid: f\n${usage}" -- ../bin/strings -n f inputs/all_bytes - atf_check -s exit:1 -e "inline:Minimal string length is invalid: 42f\n${usage}" -- ../bin/strings -n 42f inputs/all_bytes -} - -atf_test_case usage -usage_body() { - atf_check -s exit:1 -e 'inline:strings: [-a] [-t format] [-n number] [file...]\n' ../bin/strings -t aa inputs/all_bytes -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case allbytes - atf_add_test_case trueelf - atf_add_test_case true8elf - atf_add_test_case devnull - - atf_add_test_case devfull - atf_add_test_case noperm - atf_add_test_case erange_n - - atf_add_test_case octalformat - atf_add_test_case hexformat - atf_add_test_case decformat - atf_add_test_case badformat - - atf_add_test_case usage -} diff --git a/test-bin/tee b/test-bin/tee @@ -1,93 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case allinput -allinput_body() { - atf_check -o file:inputs/all_bytes ../bin/tee <inputs/all_bytes - atf_check -o file:inputs/all_bytes ../bin/tee - <inputs/all_bytes -} - -atf_test_case writefile -writefile_body() { - echo 'hello' > tmp_tee.log - atf_check -o file:inputs/all_bytes ../bin/tee tmp_tee.log <inputs/all_bytes - atf_check -o empty -s exit:1 grep hello tmp_tee.log -} -writefile_cleanup() { - rm tmp_tee.log -} - -atf_test_case appendfile -appendfile_body() { - echo 'hello' > tmp_tee.log - atf_check -o file:inputs/all_bytes ../bin/tee -a tmp_tee.log <inputs/all_bytes - atf_check -o file:outputs/tee/hello_all_bytes cat tmp_tee.log -} -appendfile_cleanup() { - rm tmp_tee.log -} - -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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../bin/tee inputs/chmod_000 </dev/null -} -noperm_cleanup() { - chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" - rm inputs/chmod_000 || atf_fail "rm chmod_000" -} - -atf_test_case devfull -devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for fputs()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for fputs()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for fputs()" - - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:Error writing ‘<stdout>’: No space left on device\n' sh -c '../bin/tee <inputs/all_bytes >/dev/full' - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:Error writing ‘<stdout>’: No space left on device\n' sh -c '../bin/tee - <inputs/all_bytes >/dev/full' -} - -atf_test_case nullinput -nullinput_body() { - atf_check ../bin/tee </dev/null -} - -atf_test_case writeslash -writeslash_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:Error opening ‘./’: Is a directory\n' ../bin/tee ./ <inputs/all_bytes -} - -atf_test_case enoent -enoent_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../bin/tee /var/empty/e/no/ent <inputs/all_bytes -} - -atf_test_case doubledash -doubledash_body() { - atf_check -o file:inputs/all_bytes -- ../bin/tee -- <inputs/all_bytes - #atf_check -s exit:1 -e 'inline:Error opening ‘---’: No such file or directory\n' -o empty -- ../bin/tee --- <inputs/all_bytes -} - - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case allinput - atf_add_test_case writefile - atf_add_test_case appendfile - atf_add_test_case noperm - atf_add_test_case devfull - atf_add_test_case nullinput - atf_add_test_case writeslash - atf_add_test_case enoent - atf_add_test_case doubledash -} diff --git a/test-bin/true b/test-bin/true @@ -1,25 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case basic -basic_body() { - atf_check ../bin/true -} - -atf_test_case nohelp -nohelp_body() { - atf_check ../bin/true --help -} - -atf_test_case devfull -devfull_body() { - atf_check ../bin/true --help >/dev/full -} - -atf_init_test_cases() { - 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/tty b/test-bin/tty @@ -1,43 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case basic -basic_body() { - tty >/dev/null || atf_expect_fail "test environment not in a tty" - - atf_check -o 'not-inline:not a tty\n' ../bin/tty - -} - -atf_test_case in_devnull -in_devnull_body() { - atf_check -s 'exit:1' -o 'inline:not a tty\n' ../bin/tty </dev/null -} - -atf_test_case out_devnull -out_devnull_body() { - tty >/dev/null || atf_expect_fail "test environment not in a tty" - - atf_check -o 'not-inline:not a tty\n' sh -c '../bin/tty >/dev/null' -} - -atf_test_case out_devfull -out_devfull_body() { - has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" - [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" - [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" - - atf_check -s "exit:2" sh -c '../bin/tty >/dev/full' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - . ../test_functions.sh - - atf_add_test_case basic - atf_add_test_case in_devnull - atf_add_test_case out_devnull - atf_add_test_case out_devfull -} diff --git a/test-bin/unlink b/test-bin/unlink @@ -1,24 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case basic cleanup -basic_body() { - touch inputs/unlink-this || atf_fail "touch inputs/unlink-this" - atf_check ../bin/unlink inputs/unlink-this -} -basic_cleanup() { - rm -f inputs/unlink-this || atf_fail "rm -f inputs/unlink-this" -} - -atf_test_case enoent -enoent_body() { - # shellcheck disable=SC1112 - atf_check -s exit:1 -e 'inline:unlink: Cannot unlink ‘/var/empty/e/no/ent’: No such file or directory\n' ../bin/unlink /var/empty/e/no/ent -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case basic - atf_add_test_case enoent -} diff --git a/test-bin/xcd b/test-bin/xcd @@ -1,54 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - -atf_test_case openfile -openfile_body() { - atf_check -o file:outputs/xcd/all_bytes ../bin/xcd inputs/all_bytes -} - -atf_test_case stdinput -stdinput_body() { - atf_check -o file:outputs/xcd/all_bytes ../bin/xcd <inputs/all_bytes - atf_check -o file:outputs/xcd/all_bytes ../bin/xcd - <inputs/all_bytes -} - -atf_test_case nullfile -nullfile_body() { - atf_check -o file:outputs/xcd/null ../bin/xcd /dev/null -} - -atf_test_case nullinput -nullinput_body() { - atf_check -o file:outputs/xcd/null ../bin/xcd </dev/null -} - -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() { - chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" - rm inputs/chmod_000 || atf_fail "rm chmod_000" -} - -atf_test_case devfull -devfull_body() { - # shellcheck disable=SC1112 - atf_check -s 'exit:1' -e 'inline:\nWrite error: No space left on device\n\nError closing ‘inputs/strings/true’: No space left on device\n' sh -c '../bin/xcd inputs/strings/true >/dev/full' - atf_check -s 'exit:1' -e 'inline:\nWrite error: No space left on device\n' sh -c '../bin/xcd <inputs/strings/true >/dev/full' - atf_check -s 'exit:1' -e 'inline:\nWrite error: No space left on device\n' sh -c '../bin/xcd - <inputs/strings/true >/dev/full' -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - atf_add_test_case openfile - atf_add_test_case stdinput - atf_add_test_case nullfile - atf_add_test_case nullinput - atf_add_test_case noperm - atf_add_test_case devfull -} diff --git a/test-cmd/Kyuafile b/test-cmd/Kyuafile @@ -0,0 +1,35 @@ +-- SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +-- SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only +syntax(2) + +test_suite("utils") + +basedir = fs.dirname(fs.dirname(current_kyuafile())) + +-- 7,$|LC_ALL=C.UTF-8 sort +atf_test_program{name="args", required_files=basedir.."/cmd/args", timeout=1} +atf_test_program{name="basename", required_files=basedir.."/cmd/basename", timeout=1} +atf_test_program{name="cat", required_files=basedir.."/cmd/cat", timeout=1} +atf_test_program{name="date", required_files=basedir.."/cmd/date", timeout=1} +atf_test_program{name="del", required_files=basedir.."/cmd/del", timeout=1} +atf_test_program{name="dirname", required_files=basedir.."/cmd/dirname", timeout=1} +atf_test_program{name="echo", required_files=basedir.."/cmd/echo", timeout=1} +atf_test_program{name="env", required_files=basedir.."/cmd/env", timeout=1} +atf_test_program{name="errno", required_files=basedir.."/cmd/errno", timeout=1} +atf_test_program{name="false", required_files=basedir.."/cmd/false", timeout=1} +atf_test_program{name="humanize", required_files=basedir.."/cmd/humanize", timeout=1} +atf_test_program{name="id", required_files=basedir.."/cmd/id", timeout=1} +atf_test_program{name="link", required_files=basedir.."/cmd/link", timeout=1} +atf_test_program{name="lolcat", required_files=basedir.."/cmd/lolcat", timeout=1} +atf_test_program{name="mdate", required_files=basedir.."/cmd/mdate", timeout=1} +atf_test_program{name="memsys", required_files=basedir.."/cmd/memsys", timeout=1} +atf_test_program{name="pwd", required_files=basedir.."/cmd/pwd", timeout=1} +atf_test_program{name="seq", required_files=basedir.."/cmd/seq", timeout=1} +atf_test_program{name="sizeof", required_files=basedir.."/cmd/sizeof", timeout=1} +atf_test_program{name="sname", required_files=basedir.."/cmd/sname", timeout=1} +atf_test_program{name="strings", required_files=basedir.."/cmd/strings", timeout=1} +atf_test_program{name="tee", required_files=basedir.."/cmd/tee", timeout=1} +atf_test_program{name="true", required_files=basedir.."/cmd/true", timeout=1} +atf_test_program{name="tty", required_files=basedir.."/cmd/tty", timeout=1} +atf_test_program{name="unlink", required_files=basedir.."/cmd/unlink", timeout=1} +atf_test_program{name="xcd", required_files=basedir.."/cmd/xcd", timeout=1} diff --git a/test-cmd/args b/test-cmd/args @@ -0,0 +1,47 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + + +atf_test_case noargs +noargs_body() { + atf_check -o 'inline:argc: 1 +argv[0]: "../cmd/args" +' ../cmd/args +} + +atf_test_case onearg +onearg_body() { + atf_check -o 'inline:argc: 2 +argv[0]: "../cmd/args" +argv[1]: "a" +' ../cmd/args a +} + +atf_test_case twoargs +twoargs_body() { + atf_check -o 'inline:argc: 3 +argv[0]: "../cmd/args" +argv[1]: "a" +argv[2]: "b c" +' ../cmd/args a 'b c' +} + +atf_test_case options +options_body() { + atf_check -o 'inline:argc: 5 +argv[0]: "../cmd/args" +argv[1]: "-1" +argv[2]: "+2" +argv[3]: "--3" +argv[4]: "/4" +' ../cmd/args -1 +2 --3 /4 +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case noargs + atf_add_test_case onearg + atf_add_test_case twoargs + atf_add_test_case options +} diff --git a/test-cmd/basename b/test-cmd/basename @@ -0,0 +1,80 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + + +atf_test_case noargs +noargs_body() { + atf_check -o "inline:.\n" ../cmd/basename +} + +atf_test_case one_slash +one_slash_body() { + atf_check -o "inline:bin\n" ../cmd/basename "/usr/bin" +} + +atf_test_case two_slash +two_slash_body() { + atf_check -o "inline:bin\n" ../cmd/basename "/usr//bin" +} + +atf_test_case two_dash +two_dash_body() { + atf_check -o "inline:bin\n" ../cmd/basename -- "/usr//bin" +} + +atf_test_case testopt +testopt_body() { + atf_check -o "inline:bin\n" ../cmd/basename "/usr//bin-test" "-test" +} + +atf_test_case usage +usage_body() { + atf_check -s exit:1 -e "inline:usage: basename string [suffix]\n" ../cmd/basename 1 2 3 +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename >/dev/full' + atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename "/usr/bin" >/dev/full' + atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename "/usr//bin-test" "-test" >/dev/full' +} + +atf_test_case nullarg +nullarg_body() { + atf_check -e "inline:.\n" ../cmd/basename "$(printf '\x00')" + atf_check -e "inline:bin\n" ../cmd/basename "/usr/bin" "$(printf '\x00')" +} + +atf_test_case doubledash +doubledash_body() { + atf_check -o 'inline:-\n' -- ../cmd/basename '-' + atf_check -o 'inline:.\n' -- ../cmd/basename '--' + atf_check -o 'inline:--\n' -- ../cmd/basename --a a + atf_check -o 'inline:---\n' -- ../cmd/basename '---' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case noargs + atf_add_test_case one_slash + atf_add_test_case two_slash + atf_add_test_case two_dash + atf_add_test_case testopt + atf_add_test_case usage + + # puts in glibc doesn't returns -1 on failure + atf_add_test_case devfull + + # Broken behavior in ATF, might be caused by stripping out \x00 + #atf_add_test_case nullarg + + atf_add_test_case doubledash +} diff --git a/test-cmd/cat b/test-cmd/cat @@ -0,0 +1,78 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case allfile +allfile_body() { + atf_check -o file:inputs/all_bytes ../cmd/cat inputs/all_bytes +} + +atf_test_case allinput +allinput_body() { + atf_check -o file:inputs/all_bytes ../cmd/cat <inputs/all_bytes +} + +atf_test_case alldashinput +alldashinput_body() { + atf_check -o file:inputs/all_bytes ../cmd/cat - <inputs/all_bytes +} + +atf_test_case devnull +devnull_body() { + atf_check ../cmd/cat /dev/null + atf_check ../cmd/cat </dev/null + atf_check ../cmd/cat - </dev/null +} + +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' ../cmd/cat inputs/chmod_000 +} +noperm_cleanup() { + chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" + rm inputs/chmod_000 || atf_fail "rm chmod_000" +} + +atf_test_case devfull +devfull_body() { + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/cat inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/cat <inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/cat - <inputs/all_bytes >/dev/full' +} + +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' ../cmd/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' ../cmd/cat /var/empty/e/no/ent +} + +atf_test_case doubledash +doubledash_body() { + atf_check -o file:inputs/all_bytes -- ../cmd/cat -- inputs/all_bytes + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:\nError opening ‘---’: No such file or directory\n' -o empty -- ../cmd/cat --- inputs/all_bytes +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case allfile + atf_add_test_case allinput + atf_add_test_case alldashinput + atf_add_test_case devnull + atf_add_test_case noperm + atf_add_test_case devfull + atf_add_test_case readslash + atf_add_test_case enoent + atf_add_test_case doubledash +} diff --git a/test-cmd/date b/test-cmd/date @@ -0,0 +1,78 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case noargs +noargs_body() { + atf_check -o not-empty ../cmd/date +} + +atf_test_case badarg +badarg_body() { + atf_check -s 'exit:1' -e "inline:Error: Unrecognised option: '-x'\ndate [-u][-d datetime] [+format]\n" ../cmd/date -x +} + +atf_test_case epoch +epoch_body() { + atf_check -o "match:^[0-9]+$" ../cmd/date '+%s' +} + +atf_test_case rfc3339 +rfc3339_body() { + atf_check -o "match:^[0-9]{4}\-[0-9]{2}\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{4}$" ../cmd/date '+%FT%T%z' +} + +atf_test_case empty +empty_body() { + atf_check -o 'inline:\n' ../cmd/date '+' +} + +atf_test_case echolike +echolike_body() { + atf_check -o 'inline:hello world\n' ../cmd/date '+hello world' +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 -e 'inline:puts: No space left on device\n' sh -c '../cmd/date >/dev/full' +} + +atf_test_case utc +utc_body() { + atf_check -o "match:^[0-9]+$" ../cmd/date -u '+%s' +} + +atf_test_case timestamp +timestamp_body() { + atf_check -o "inline:1970-01-01T00:00:00\n" ../cmd/date -u -d @0 '+%FT%T' + atf_check -o "inline:1970-01-01T00:01:09\n" ../cmd/date -u -d @69 '+%FT%T' + atf_check -o "inline:1969-12-31T23:58:51\n" ../cmd/date -u -d @-69 '+%FT%T' + + atf_check -s 'exit:1' -e "inline:Error: Missing operand for option: '-d'\ndate [-u][-d datetime] [+format]\n" ../cmd/date -u -d + atf_check -s 'exit:1' ../cmd/date -u -d 69 + + # 36893488147419103232 = 2^65 + atf_check -s 'exit:1' -e not-empty ../cmd/date -u -d @36893488147419103232 +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case noargs + atf_add_test_case badarg + atf_add_test_case empty + atf_add_test_case echolike + atf_add_test_case devfull + + atf_add_test_case epoch + atf_add_test_case rfc3339 + atf_add_test_case utc + + atf_add_test_case timestamp +} diff --git a/test-cmd/del b/test-cmd/del @@ -0,0 +1,57 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case basic cleanup +basic_body() { + touch inputs/del-test || atf_fail "touching del-test" + atf_check ../cmd/del inputs/del-test + + mkdir -p inputs/del-test.d || atf_fail "mkdir del-test.d" + atf_check ../cmd/del inputs/del-test.d +} +basic_cleanup() { + rm -fr inputs/del-test inputs/del-test.d || atf_fail "rm inputs/del-test{,.d}" +} + +atf_test_case nopermf cleanup +nopermf_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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/del inputs/chmod_000 +} +nopermf_cleanup() { + rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}" +} + +atf_test_case nopermd cleanup +nopermd_body() { + mkdir -p inputs/chmod_000.d || atf_fail "mkdir chmod_000.d" + chmod 0000 inputs/chmod_000.d || atf_fail "chmod 0000 chmod_000.d" + + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/del inputs/chmod_000.d +} +nopermd_cleanup() { + rm -fr inputs/chmod_000 inputs/chmod_000.d || atf_fail "rm chmod_000{,.d}" +} + +atf_test_case enoent +enoent_body() { + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:remove(/var/empty/e/no/ent) error: No such file or directory\n' ../cmd/del /var/empty/e/no/ent +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case basic + + # None of the supported implementations of remove(3) seem to have checks + # based on file mode + #atf_add_test_case nopermf + #atf_add_test_case nopermd + + atf_add_test_case enoent +} diff --git a/test-cmd/dirname b/test-cmd/dirname @@ -0,0 +1,38 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + + +atf_test_case noargs +noargs_body() { + atf_check -e "inline:usage: dirname string\n" -s exit:1 ../cmd/dirname +} + +atf_test_case one_slash +one_slash_body() { + atf_check -o "inline:/usr\n" ../cmd/dirname "/usr/bin" +} + +atf_test_case two_slash +two_slash_body() { + atf_check -o "inline:/usr\n" ../cmd/dirname "/usr//bin" +} + +atf_test_case two_dash +two_dash_body() { + atf_check -o "inline:/usr\n" ../cmd/dirname -- "/usr//bin" +} + +atf_test_case badarg +badarg_body() { + atf_check -s exit:1 -e "inline:usage: dirname string\n" ../cmd/dirname -a "/usr//bin" +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case noargs + atf_add_test_case badarg + atf_add_test_case one_slash + atf_add_test_case two_slash + atf_add_test_case two_dash +} diff --git a/test-cmd/echo b/test-cmd/echo @@ -0,0 +1,31 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case empty +empty_body() { + atf_check -o "inline:\n" ../cmd/echo +} + +atf_test_case hello +hello_body() { + atf_check -o "inline:hello world\n" ../cmd/echo hello world +} + +atf_test_case doubledash +doubledash_body() { + atf_check -o "inline:-- hello\n" ../cmd/echo -- hello +} + +atf_test_case devfull +devfull_body() { + atf_check -s exit:1 -e 'inline:write(1, buffer, arg_len): No space left on device\n' sh -c '../cmd/echo hello world >/dev/full' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case empty + atf_add_test_case hello + atf_add_test_case doubledash + atf_add_test_case devfull +} diff --git a/test-cmd/env b/test-cmd/env @@ -0,0 +1,63 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case noargs +noargs_body() { + [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment" + + atf_check -o "inline:FOO=BAR\n" env -i FOO=BAR ../cmd/env +} + +atf_test_case badarg +badarg_body() { + atf_check -s not-exit:0 -e "inline:Error: Unrecognised option: '-f'\nenv [-i] [-u key] [key=value ...] [command [args]]\n" ../cmd/env -f +} + +atf_test_case iflag +iflag_body() { + [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment" + + atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR ../cmd/env + atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR + atf_check -o "not-inline:FOO=BAR\n" ../cmd/env FOO=BAR ../cmd/env + atf_check -o "not-inline:FOO=BAR\n" ../cmd/env FOO=BAR +} + +atf_test_case uflag +uflag_body() { + [ "${LD_PRELOAD}" = "libsandbox.so" ] && atf_expect_fail "sandbox (gentoo) interferes with the environment" + + atf_check -o "inline:FOO=BAR\n" ../cmd/env -i FOO=BAR BAR=FOO ../cmd/env -u BAR + + atf_check -s not-exit:0 -e "inline:Error: Missing operand for option: '-u'\nenv [-i] [-u key] [key=value ...] [command [args]]\n" ../cmd/env -u +} + +atf_test_case devfull +devfull_body() { + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 -e 'inline:env: puts: No space left on device\n' sh -c '../cmd/env >/dev/full' +} + +atf_test_case noutil +noutil_body() { + atf_check -s exit:127 -e 'inline:env: execve: No such file or directory\n' ../cmd/env /var/empty/e/no/ent +} + +atf_test_case false +false_body() { + atf_check -s exit:1 ../cmd/env false +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case noargs + atf_add_test_case badarg + atf_add_test_case iflag + atf_add_test_case uflag + atf_add_test_case devfull + atf_add_test_case noutil + atf_add_test_case false +} diff --git a/test-cmd/errno b/test-cmd/errno @@ -0,0 +1,51 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case simple +simple_body() { + atf_check -o "inline:Operation not permitted\n" ../cmd/errno 1 +} + +atf_test_case noargs +noargs_body() { + atf_check -s exit:1 -o "inline:usage: errno <number>\n" ../cmd/errno +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 sh -c '../cmd/errno 1 >/dev/full' +} + +atf_test_case einval +einval_body() { + if has_glibc; then + atf_check -s exit:0 -o "inline:Unknown error -1\n" ../cmd/errno -1 + elif has_musl; then + atf_check -s exit:0 -o "inline:No error information\n" ../cmd/errno -1 + else + atf_check -s exit:1 -e "inline:errno: strerror: Invalid argument\n" ../cmd/errno -1 + fi +} + +atf_test_case erange +erange_body() { + # 36893488147419103232 = 2^65 + atf_check -s 'exit:1' -e not-empty ../cmd/errno 36893488147419103232 +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case simple + atf_add_test_case noargs + atf_add_test_case devfull + atf_add_test_case einval + atf_add_test_case erange +} diff --git a/test-cmd/false b/test-cmd/false @@ -0,0 +1,25 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case basic +basic_body() { + atf_check -s exit:1 ../cmd/false +} + +atf_test_case nohelp +nohelp_body() { + atf_check -s exit:1 ../cmd/false --help +} + +atf_test_case devfull +devfull_body() { + atf_check -s exit:1 ../cmd/false --help >/dev/full +} + +atf_init_test_cases() { + 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-cmd/humanize b/test-cmd/humanize @@ -0,0 +1,94 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case one +one_body() { + atf_check -o "inline:1 \n" ../cmd/humanize 1 + atf_check -o "inline:1 \n" ../cmd/humanize -d 1 + atf_check -o "inline:1 B\n" ../cmd/humanize -b 1 +} + +atf_test_case two +two_body() { + atf_check -o "inline:12 \n" ../cmd/humanize 12 + atf_check -o "inline:12 \n" ../cmd/humanize -d 12 + atf_check -o "inline:12 B\n" ../cmd/humanize -b 12 +} + +atf_test_case three +three_body() { + atf_check -o "inline:123 \n" ../cmd/humanize 123 + atf_check -o "inline:123 \n" ../cmd/humanize -d 123 + atf_check -o "inline:123 B\n" ../cmd/humanize -b 123 +} + +# 1 234 +atf_test_case four +four_body() { + atf_check -o "inline:1.234 k\n" ../cmd/humanize 1234 + atf_check -o "inline:1.234 k\n" ../cmd/humanize -d 1234 + atf_check -o "inline:1.20508 KiB\n" ../cmd/humanize -b 1234 +} + +# 12 345 +atf_test_case five +five_body() { + atf_check -o "inline:12.345 k\n" ../cmd/humanize 12345 + atf_check -o "inline:12.345 k\n" ../cmd/humanize -d 12345 + atf_check -o "inline:12.0557 KiB\n" ../cmd/humanize -b 12345 +} + +# 123 456 +atf_test_case six +six_body() { + atf_check -o "inline:123.456 k\n" ../cmd/humanize 123456 + atf_check -o "inline:123.456 k\n" ../cmd/humanize -d 123456 + atf_check -o "inline:120.562 KiB\n" ../cmd/humanize -b 123456 +} + +# 1234 4567 +atf_test_case seven +seven_body() { + atf_check -o "inline:1.23457 M\n" ../cmd/humanize 1234567 + atf_check -o "inline:1.23457 M\n" ../cmd/humanize -d 1234567 + atf_check -o "inline:1.17737 MiB\n" ../cmd/humanize -b 1234567 +} + +atf_test_case noarg +noarg_body() { + atf_check -s exit:1 -e 'inline:Usage: humanize [-bd] number\n' ../cmd/humanize +} + +atf_test_case badflag +badflag_body() { + atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../cmd/humanize -f + atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../cmd/humanize -f 123 +} + +atf_test_case limits +limits_body() { + atf_check -o 'inline:9.22337 E\n' ../cmd/humanize 9223372036854775807 + atf_check -s exit:1 -e 'inline:humanize: strtonum: 9223372036854775808 is too large\n' ../cmd/humanize 9223372036854775808 + + # Not as great as it should but at least not a lie + atf_check -o 'inline:-9.22337e+18 \n' ../cmd/humanize -- -9223372036854775808 + + atf_check -s exit:1 -e 'inline:humanize: strtonum: -9223372036854775809 is too small\n' ../cmd/humanize -- -9223372036854775809 +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + atf_add_test_case noarg + atf_add_test_case badflag + atf_add_test_case limits + + atf_add_test_case one + atf_add_test_case two + atf_add_test_case three + atf_add_test_case four + atf_add_test_case five + atf_add_test_case six + atf_add_test_case seven +} diff --git a/test-cmd/id b/test-cmd/id @@ -0,0 +1,154 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case noargs cleanup +noargs_body() { + atf_check -o save:noargs.out ../cmd/id + atf_check grep -q "uid=$(id -u)($(id -un)) gid=$(id -g)($(id -gn)) groups=" noargs.out +} +noargs_cleanup() { + rm -f noargs.out +} + +atf_test_case names cleanup +names_body() { + atf_check -o save:names.out ../cmd/id -n + atf_check grep -q "uid=$(id -un) gid=$(id -gn) groups=" names.out +} +names_cleanup() { + rm -f names.out +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 sh -c '../cmd/id >/dev/full' + atf_check -s exit:1 sh -c '../cmd/id -n >/dev/full' + atf_check -s exit:1 sh -c '../cmd/id -u >/dev/full' + atf_check -s exit:1 sh -c '../cmd/id -g >/dev/full' +} + +atf_test_case group +group_body() { + atf_check -o "inline:$(id -g)\n" ../cmd/id -g + atf_check -o "inline:$(id -gr)\n" ../cmd/id -gr + atf_check -o "inline:$(id -gn)\n" ../cmd/id -gn + atf_check -o "inline:$(id -gnr)\n" ../cmd/id -gnr +} + +atf_test_case user +user_body() { + atf_check -o "inline:$(id -u)\n" ../cmd/id -u + atf_check -o "inline:$(id -ur)\n" ../cmd/id -ur + atf_check -o "inline:$(id -un)\n" ../cmd/id -un + atf_check -o "inline:$(id -unr)\n" ../cmd/id -unr +} + +atf_test_case groups +groups_body() { + # sadly GNU coreutils' id(1) sorts it's grouplist + + atf_check -o not-empty ../cmd/id -G + atf_check -o not-empty ../cmd/id -Gr + atf_check -o not-empty ../cmd/id -Gn + atf_check -o not-empty ../cmd/id -Gnr +} + +atf_test_case noetc +noetc_body() { + bwrap_args="--bind / / --bind /var/empty /etc" + + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" + + set -f + + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -u + # shellcheck disable=SC2086 + atf_check -s exit:1 -e "inline:id: cannot find name for user ID $(id -u)\n" -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -un + + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -g + # shellcheck disable=SC2086 + atf_check -s exit:1 -e "inline:id: cannot find name for group ID $(id -g)\n" -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -gn +} + +atf_test_case nopasswd +nopasswd_body() { + bwrap_args="--bind / / --bind /dev/null /etc/passwd" + + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" + + set -f + + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -u + # shellcheck disable=SC2086 + atf_check -s exit:1 -e "inline:id: cannot find name for user ID $(id -u)\n" -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -un + + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -g + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -gn)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -gn +} + +atf_test_case nogroup +nogroup_body() { + bwrap_args="--bind / / --bind /dev/null /etc/group" + + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" + + set -f + + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -u)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -u + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -un)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -un + + # shellcheck disable=SC2086 + atf_check -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -g + # shellcheck disable=SC2086 + atf_check -s exit:1 -e "inline:id: cannot find name for group ID $(id -g)\n" -o "inline:$(id -g)\n" -- "${BWRAP:-bwrap}" ${bwrap_args} ../cmd/id -gn +} + +atf_test_case badarg +badarg_body() { + atf_check -s exit:1 -e 'inline:Usage: id [-Ggu] [-nr] [user]\n' ../cmd/id -a +} + +atf_test_case root cleanup +root_body() { + atf_check -o save:root.out ../cmd/id root + atf_check grep -q "uid=$(id -u root)($(id -un root)) gid=$(id -g root)($(id -gn root)) groups=" root.out +} +root_cleanup() { + rm -f root.out +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case devfull + atf_add_test_case badarg + + atf_add_test_case noargs + atf_add_test_case names + atf_add_test_case group + atf_add_test_case user + atf_add_test_case groups + + atf_add_test_case noetc + atf_add_test_case nogroup + atf_add_test_case nopasswd + + atf_add_test_case root +} diff --git a/test-bin/inputs/all_bytes b/test-cmd/inputs/all_bytes Binary files differ. diff --git a/test-cmd/inputs/strings/libc_start_main b/test-cmd/inputs/strings/libc_start_main Binary files differ. diff --git a/test-bin/inputs/strings/true b/test-cmd/inputs/strings/true Binary files differ. diff --git a/test-cmd/link b/test-cmd/link @@ -0,0 +1,35 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case empty +empty_body() { + atf_check -s exit:1 -e "inline:usage: link <reference> <destination>\n" ../cmd/link +} + +atf_test_case basic cleanup +basic_body() { + touch foo + + atf_check ../cmd/link foo bar + atf_check cmp foo bar + + echo hello >> foo + atf_check cmp foo bar +} +basic_cleanup() { + atf_check rm -f foo bar +} + +atf_test_case enoent +enoent_body() { + atf_check -s exit:1 -e 'inline:link: No such file or directory\n' ../cmd/link /var/empty/e/no/ent enoent_foo + atf_check -s exit:1 -e 'inline:link: No such file or directory\n' ../cmd/link enoent_bar /var/empty/e/no/ent +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case empty + atf_add_test_case basic + atf_add_test_case enoent +} diff --git a/test-cmd/lolcat b/test-cmd/lolcat @@ -0,0 +1,92 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case allfile +allfile_body() { + atf_check -o file:outputs/lolcat/all_bytes ../cmd/lolcat inputs/all_bytes +} + +atf_test_case allinput +allinput_body() { + atf_check -o file:outputs/lolcat/all_bytes ../cmd/lolcat <inputs/all_bytes +} + +atf_test_case alldashinput +alldashinput_body() { + atf_check -o file:outputs/lolcat/all_bytes ../cmd/lolcat - <inputs/all_bytes +} + +atf_test_case devnull +devnull_body() { + if [ "$(uname -s)" = "FreeBSD" ] || [ "$(uname -s)" = "NetBSD" ]; then + # FIXME + atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../cmd/lolcat /dev/null + atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../cmd/lolcat </dev/null + atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../cmd/lolcat - </dev/null + else + atf_check -o 'inline:' ../cmd/lolcat /dev/null + atf_check -o 'inline:' ../cmd/lolcat </dev/null + atf_check -o 'inline:' ../cmd/lolcat - </dev/null + fi +} + +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:' ../cmd/lolcat inputs/chmod_000 +} +noperm_cleanup() { + chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" + rm inputs/chmod_000 || atf_fail "rm chmod_000" +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for fputc()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD badly handling write errors" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD badly handling write errors" + + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/lolcat inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/lolcat <inputs/all_bytes >/dev/full' + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/lolcat - <inputs/all_bytes >/dev/full' +} + +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:\nRead error: Is a directory\n' -o 'inline:' ../cmd/lolcat ./ +} + +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' -o 'inline:' ../cmd/lolcat /var/empty/e/no/ent +} + +atf_test_case doubledash +doubledash_body() { + atf_check -o file:outputs/lolcat/all_bytes -- ../cmd/lolcat -- inputs/all_bytes + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:\nError opening ‘---’: No such file or directory\n' -o 'inline:' -- ../cmd/lolcat --- inputs/all_bytes +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case allfile + atf_add_test_case allinput + atf_add_test_case alldashinput + atf_add_test_case devnull + atf_add_test_case noperm + atf_add_test_case devfull + atf_add_test_case readslash + atf_add_test_case enoent + atf_add_test_case doubledash +} diff --git a/test-cmd/mdate b/test-cmd/mdate @@ -0,0 +1,13 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case basic +basic_body() { + atf_check -o "match:^[0-9A-F]+,[0-9A-F]+$" ../cmd/mdate +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case basic +} diff --git a/test-cmd/memsys b/test-cmd/memsys @@ -0,0 +1,48 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + + +atf_test_case basic cleanup +basic_body() { + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" + + atf_check touch ./tmp-memsys + atf_check -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys /sys/power/state ../cmd/memsys + atf_check -o 'inline:mem' cat tmp-memsys +} +basic_cleanup() { + rm -f tmp-memsys +} + +atf_test_case chmod_000 cleanup +chmod_000_body() { + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" + + atf_check touch ./tmp-memsys.000 + atf_check chmod 000 ./tmp-memsys.000 + atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys.000 /sys/power/state ../cmd/memsys + atf_check chmod 600 ./tmp-memsys.000 + atf_check -o empty cat tmp-memsys.000 +} +chmod_000_cleanup() { + rm -f tmp-memsys.000 +} + +atf_test_case devfull +devfull_body() { + command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" + [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" + + atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind /dev/full /sys/power/state ../cmd/memsys +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + atf_add_test_case basic + atf_add_test_case chmod_000 + atf_add_test_case devfull +} diff --git a/test-cmd/mkdir b/test-cmd/mkdir @@ -0,0 +1,45 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case empty +empty_body() { + atf_check -s exit:1 -e 'inline:mkdir: missing operands\nUsage: mkdir [-p] [-m mode] [directories...]\n' ../cmd/mkdir +} + +atf_test_case foo cleanup +foo_body() { + atf_check rm -fr mkdir-foo + atf_check ../cmd/mkdir mkdir-foo + atf_check test -d mkdir-foo +} +foo_cleanup() { + rm -fr mkdir-foo +} + +atf_test_case p_flag cleanup +p_flag_body() { + atf_check rm -fr mkdir-p_flag/1/2/3 + atf_check -s exit:1 -e 'inline:mkdir: No such file or directory\n' ../cmd/mkdir mkdir-p_flag/1/2/3 + atf_check ../cmd/mkdir -p mkdir-p_flag/1/2/3 + atf_check test -d mkdir-p_flag/1/2/3 +} +p_flag_cleanup() { + rm -fr mkdir-p_flag/1/2/3 +} + +atf_test_case devnull +devnull_body() { + atf_check -s exit:1 -e 'inline:mkdir: File exists\n' ../cmd/mkdir /dev/null + atf_check -s exit:1 -e 'inline:mkdir: File exists\n' ../cmd/mkdir -p /dev/null + atf_check -s exit:1 -e 'inline:mkdir: Not a directory\n' ../cmd/mkdir /dev/null/no + atf_check -s exit:1 -e 'inline:mkdir: Not a directory\n' ../cmd/mkdir -p /dev/null/no +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case empty + atf_add_test_case foo + #atf_add_test_case p_flag + atf_add_test_case devnull +} diff --git a/test-bin/outputs/lolcat/all_bytes b/test-cmd/outputs/lolcat/all_bytes Binary files differ. diff --git a/test-cmd/outputs/lolcat/all_bytes.l b/test-cmd/outputs/lolcat/all_bytes.l @@ -0,0 +1,12 @@ +\000\001\002\003\004\005\006\a\b\t$ +\v\f\r\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\ +\035\036\037 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWX\ +YZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\ +\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\ +\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\ +\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\ +\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\ +\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\ +\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\ +\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\ +\375\376\377$ diff --git a/test-bin/outputs/strings/all_bytes b/test-cmd/outputs/strings/all_bytes diff --git a/test-bin/outputs/strings/all_bytes_td b/test-cmd/outputs/strings/all_bytes_td diff --git a/test-bin/outputs/strings/all_bytes_to b/test-cmd/outputs/strings/all_bytes_to diff --git a/test-bin/outputs/strings/all_bytes_tx b/test-cmd/outputs/strings/all_bytes_tx diff --git a/test-bin/outputs/strings/true b/test-cmd/outputs/strings/true diff --git a/test-bin/outputs/strings/true_8 b/test-cmd/outputs/strings/true_8 diff --git a/test-bin/outputs/strings/true_8_td b/test-cmd/outputs/strings/true_8_td diff --git a/test-bin/outputs/strings/true_8_to b/test-cmd/outputs/strings/true_8_to diff --git a/test-bin/outputs/strings/true_8_tx b/test-cmd/outputs/strings/true_8_tx diff --git a/test-bin/outputs/strings/true_td b/test-cmd/outputs/strings/true_td diff --git a/test-bin/outputs/strings/true_to b/test-cmd/outputs/strings/true_to diff --git a/test-bin/outputs/strings/true_tx b/test-cmd/outputs/strings/true_tx diff --git a/test-bin/outputs/tee/hello_all_bytes b/test-cmd/outputs/tee/hello_all_bytes Binary files differ. diff --git a/test-bin/outputs/xcd/all_bytes b/test-cmd/outputs/xcd/all_bytes diff --git a/test-bin/outputs/xcd/null b/test-cmd/outputs/xcd/null diff --git a/test-cmd/pwd b/test-cmd/pwd @@ -0,0 +1,49 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case simple +simple_body() { + atf_check -o "inline:${PWD}\n" ../cmd/pwd + atf_check -o "inline:$(atf_get_srcdir)\n" ../cmd/pwd +} + +atf_test_case args +args_body() { + atf_check -s exit:1 -e "inline:usage: pwd\n" ../cmd/pwd -H +} + +atf_test_case enoent cleanup +enoent_body() { + mkdir -p "$(atf_get_srcdir)/remove-me" || exit 1 + cd "$(atf_get_srcdir)/remove-me" || exit 1 + + atf_check -o "inline:$(atf_get_srcdir)/remove-me\n" "$(atf_get_srcdir)/../cmd/pwd" + + rm -fr "$(atf_get_srcdir)/remove-me" || exit 1 + + atf_check -s exit:1 -e 'inline:getcwd: No such file or directory\n' "$(atf_get_srcdir)/../cmd/pwd" +} +enoent_cleanup() { + rm -fr "$(atf_get_srcdir)/remove-me" +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 sh -c '../cmd/pwd >/dev/full' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case simple + atf_add_test_case args + atf_add_test_case enoent + atf_add_test_case devfull +} diff --git a/test-cmd/seq b/test-cmd/seq @@ -0,0 +1,75 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case one +one_body() { + atf_check -o "inline:1\n" ../cmd/seq 1 + atf_check -o "inline:1\n2\n3\n4\n5\n" ../cmd/seq 5 + + atf_check -o "inline:1\n0\n-1\n" -- ../cmd/seq -- -1 + atf_check -o "inline:1\n0\n-1\n-2\n-3\n-4\n-5\n" -- ../cmd/seq -- -5 +} + +atf_test_case two +two_body() { + atf_check -o "inline:0\n1\n" ../cmd/seq 0 1 + atf_check -o "inline:0\n1\n2\n3\n4\n5\n" ../cmd/seq 0 5 + atf_check -o "inline:10\n11\n12\n13\n14\n15\n" ../cmd/seq 10 15 + + atf_check -o "inline:0\n-1\n" -- ../cmd/seq 0 -1 + atf_check -o "inline:0\n-1\n-2\n-3\n-4\n-5\n" -- ../cmd/seq 0 -5 + atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" -- ../cmd/seq -- -10 -15 + atf_check -o "inline:2\n1\n0\n-1\n-2\n" -- ../cmd/seq 2 -2 + atf_check -o "inline:-2\n-1\n0\n1\n2\n" -- ../cmd/seq -- -2 2 +} + +atf_test_case three +three_body() { + atf_check -o "inline:0\n1\n" ../cmd/seq 0 1 1 + atf_check -o "inline:0\n1\n2\n3\n4\n5\n" ../cmd/seq 0 1 5 + atf_check -o "inline:10\n11\n12\n13\n14\n15\n" ../cmd/seq 10 1 15 + + atf_check -o "inline:0\n2\n4\n" ../cmd/seq 0 2 5 + atf_check -o "inline:10\n12\n14\n" ../cmd/seq 10 2 15 + + atf_check -o "inline:0\n-1\n" -- ../cmd/seq 0 1 -1 + atf_check -o "inline:0\n-1\n-2\n-3\n-4\n-5\n" -- ../cmd/seq 0 1 -5 + atf_check -o "inline:-10\n-11\n-12\n-13\n-14\n-15\n" -- ../cmd/seq -- -10 1 -15 + + atf_check -o "inline:0\n-1\n" -- ../cmd/seq 0 -1 -1 + + atf_check -o "inline:0\n-2\n-4\n" -- ../cmd/seq 0 2 -5 + atf_check -o "inline:-10\n-12\n-14\n" -- ../cmd/seq -- -10 2 -15 +} + +atf_test_case noarg +noarg_body() { + atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../cmd/seq +} + +atf_test_case badflag +badflag_body() { + atf_check -s exit:1 -e 'inline:usage: seq [-w] [-s separator] [first [step]] last\n' ../cmd/seq -f +} + +atf_test_case limits +limits_body() { + atf_check ../cmd/seq 9223372036854775806 9223372036854775807 + atf_check -s exit:1 ../cmd/seq 9223372036854775806 9223372036854775808 + + atf_check ../cmd/seq -- -9223372036854775807 -9223372036854775808 + atf_check -s exit:1 ../cmd/seq -- -9223372036854775807 -9223372036854775809 +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + atf_add_test_case one + atf_add_test_case two + atf_add_test_case three + + atf_add_test_case noarg + atf_add_test_case badflag + #atf_add_test_case limits +} diff --git a/test-bin/shellcheck b/test-cmd/shellcheck diff --git a/test-cmd/sizeof b/test-cmd/sizeof @@ -0,0 +1,26 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case empty +empty_body() { + atf_check -o not-empty ../cmd/sizeof +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for printf()" + [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for printf()" + [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for printf()" + + atf_check -s exit:1 sh -c '../cmd/sizeof >/dev/full' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case empty + atf_add_test_case devfull +} diff --git a/test-cmd/sname b/test-cmd/sname @@ -0,0 +1,33 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case generic +generic_body() { + # sed is because of FreeBSD + atf_check -o "inline:\ +sysname=$(uname -s) +nodename=$(uname -n) +release=$(uname -r) +version=$(uname -v | sed 's; *$;;') +machine=$(uname -m) +" ../cmd/sname +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 -e 'inline:sname: No space left on device\n' sh -c '../cmd/sname >/dev/full' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case generic + atf_add_test_case devfull +} diff --git a/test-cmd/strings b/test-cmd/strings @@ -0,0 +1,123 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case allbytes +allbytes_body() { + atf_check -o file:outputs/strings/all_bytes ../cmd/strings inputs/all_bytes + atf_check -o file:outputs/strings/all_bytes ../cmd/strings <inputs/all_bytes + atf_check -o file:outputs/strings/all_bytes ../cmd/strings - <inputs/all_bytes +} + +atf_test_case trueelf +trueelf_body() { + atf_check -o file:outputs/strings/true ../cmd/strings inputs/strings/true + atf_check -o file:outputs/strings/true ../cmd/strings <inputs/strings/true + atf_check -o file:outputs/strings/true ../cmd/strings - <inputs/strings/true +} + +atf_test_case true8elf +true8elf_body() { + atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 inputs/strings/true + atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 <inputs/strings/true + atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 - <inputs/strings/true +} + +atf_test_case devnull +devnull_body() { + atf_check ../cmd/strings /dev/null + atf_check ../cmd/strings </dev/null + atf_check ../cmd/strings - </dev/null +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../cmd/strings inputs/strings/true >/dev/full' +} + +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' ../cmd/strings inputs/chmod_000 +} +noperm_cleanup() { + chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" + rm inputs/chmod_000 || atf_fail "rm chmod_000" +} + +atf_test_case octalformat +octalformat_body() { + atf_check -o file:outputs/strings/all_bytes_to ../cmd/strings -to inputs/all_bytes + atf_check ../cmd/strings -to /dev/null + atf_check -o file:outputs/strings/true_to ../cmd/strings -to inputs/strings/true + atf_check -o file:outputs/strings/true_8_to ../cmd/strings -to -n 8 inputs/strings/true +} + +atf_test_case hexformat +hexformat_body() { + atf_check -o file:outputs/strings/all_bytes_tx ../cmd/strings -tx inputs/all_bytes + atf_check ../cmd/strings -tx /dev/null + atf_check -o file:outputs/strings/true_tx ../cmd/strings -tx inputs/strings/true + atf_check -o file:outputs/strings/true_8_tx ../cmd/strings -tx -n 8 inputs/strings/true +} + +atf_test_case decformat +decformat_body() { + atf_check -o file:outputs/strings/all_bytes_td ../cmd/strings -td inputs/all_bytes + atf_check ../cmd/strings -td /dev/null + atf_check -o file:outputs/strings/true_td ../cmd/strings -td inputs/strings/true + atf_check -o file:outputs/strings/true_8_td ../cmd/strings -td -n 8 inputs/strings/true +} + +atf_test_case badformat +badformat_body() { + usage="strings: [-a] [-t format] [-n number] [file...]\n" + + atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt inputs/all_bytes + atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt /dev/null + atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt inputs/strings/true + atf_check -s exit:1 -e "inline:Unknown format: t\n${usage}" ../cmd/strings -tt -n 8 inputs/strings/true +} + +atf_test_case erange_n +erange_n_body() { + usage="strings: [-a] [-t format] [-n number] [file...]\n" + + atf_check -s exit:1 -e "inline:Minimal string length is too small: 0\n${usage}" -- ../cmd/strings -n 0 inputs/all_bytes + atf_check -s exit:1 -e "inline:Minimal string length is too large: 4097\n${usage}" -- ../cmd/strings -n 4097 inputs/all_bytes + atf_check -s exit:1 -e "inline:Minimal string length is invalid: f\n${usage}" -- ../cmd/strings -n f inputs/all_bytes + atf_check -s exit:1 -e "inline:Minimal string length is invalid: 42f\n${usage}" -- ../cmd/strings -n 42f inputs/all_bytes +} + +atf_test_case usage +usage_body() { + atf_check -s exit:1 -e 'inline:strings: [-a] [-t format] [-n number] [file...]\n' ../cmd/strings -t aa inputs/all_bytes +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case allbytes + atf_add_test_case trueelf + atf_add_test_case true8elf + atf_add_test_case devnull + + atf_add_test_case devfull + atf_add_test_case noperm + atf_add_test_case erange_n + + atf_add_test_case octalformat + atf_add_test_case hexformat + atf_add_test_case decformat + atf_add_test_case badformat + + atf_add_test_case usage +} diff --git a/test-cmd/tee b/test-cmd/tee @@ -0,0 +1,93 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case allinput +allinput_body() { + atf_check -o file:inputs/all_bytes ../cmd/tee <inputs/all_bytes + atf_check -o file:inputs/all_bytes ../cmd/tee - <inputs/all_bytes +} + +atf_test_case writefile +writefile_body() { + echo 'hello' > tmp_tee.log + atf_check -o file:inputs/all_bytes ../cmd/tee tmp_tee.log <inputs/all_bytes + atf_check -o empty -s exit:1 grep hello tmp_tee.log +} +writefile_cleanup() { + rm tmp_tee.log +} + +atf_test_case appendfile +appendfile_body() { + echo 'hello' > tmp_tee.log + atf_check -o file:inputs/all_bytes ../cmd/tee -a tmp_tee.log <inputs/all_bytes + atf_check -o file:outputs/tee/hello_all_bytes cat tmp_tee.log +} +appendfile_cleanup() { + rm tmp_tee.log +} + +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:Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/tee inputs/chmod_000 </dev/null +} +noperm_cleanup() { + chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" + rm inputs/chmod_000 || atf_fail "rm chmod_000" +} + +atf_test_case devfull +devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for fputs()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for fputs()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for fputs()" + + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:Error writing ‘<stdout>’: No space left on device\n' sh -c '../cmd/tee <inputs/all_bytes >/dev/full' + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:Error writing ‘<stdout>’: No space left on device\n' sh -c '../cmd/tee - <inputs/all_bytes >/dev/full' +} + +atf_test_case nullinput +nullinput_body() { + atf_check ../cmd/tee </dev/null +} + +atf_test_case writeslash +writeslash_body() { + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:Error opening ‘./’: Is a directory\n' ../cmd/tee ./ <inputs/all_bytes +} + +atf_test_case enoent +enoent_body() { + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/tee /var/empty/e/no/ent <inputs/all_bytes +} + +atf_test_case doubledash +doubledash_body() { + atf_check -o file:inputs/all_bytes -- ../cmd/tee -- <inputs/all_bytes + #atf_check -s exit:1 -e 'inline:Error opening ‘---’: No such file or directory\n' -o empty -- ../cmd/tee --- <inputs/all_bytes +} + + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case allinput + atf_add_test_case writefile + atf_add_test_case appendfile + atf_add_test_case noperm + atf_add_test_case devfull + atf_add_test_case nullinput + atf_add_test_case writeslash + atf_add_test_case enoent + atf_add_test_case doubledash +} diff --git a/test-bin/inputs/all_bytes b/test-cmd/tmp_tee.log Binary files differ. diff --git a/test-cmd/true b/test-cmd/true @@ -0,0 +1,25 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case basic +basic_body() { + atf_check ../cmd/true +} + +atf_test_case nohelp +nohelp_body() { + atf_check ../cmd/true --help +} + +atf_test_case devfull +devfull_body() { + atf_check ../cmd/true --help >/dev/full +} + +atf_init_test_cases() { + 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-cmd/tty b/test-cmd/tty @@ -0,0 +1,43 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case basic +basic_body() { + tty >/dev/null || atf_expect_fail "test environment not in a tty" + + atf_check -o 'not-inline:not a tty\n' ../cmd/tty + +} + +atf_test_case in_devnull +in_devnull_body() { + atf_check -s 'exit:1' -o 'inline:not a tty\n' ../cmd/tty </dev/null +} + +atf_test_case out_devnull +out_devnull_body() { + tty >/dev/null || atf_expect_fail "test environment not in a tty" + + atf_check -o 'not-inline:not a tty\n' sh -c '../cmd/tty >/dev/null' +} + +atf_test_case out_devfull +out_devfull_body() { + has_glibc && atf_expect_fail "glibc ignoring write errors for puts()" + [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()" + [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()" + + atf_check -s "exit:2" sh -c '../cmd/tty >/dev/full' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + + . ../test_functions.sh + + atf_add_test_case basic + atf_add_test_case in_devnull + atf_add_test_case out_devnull + atf_add_test_case out_devfull +} diff --git a/test-cmd/unlink b/test-cmd/unlink @@ -0,0 +1,24 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case basic cleanup +basic_body() { + touch inputs/unlink-this || atf_fail "touch inputs/unlink-this" + atf_check ../cmd/unlink inputs/unlink-this +} +basic_cleanup() { + rm -f inputs/unlink-this || atf_fail "rm -f inputs/unlink-this" +} + +atf_test_case enoent +enoent_body() { + # shellcheck disable=SC1112 + atf_check -s exit:1 -e 'inline:unlink: Cannot unlink ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/unlink /var/empty/e/no/ent +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case basic + atf_add_test_case enoent +} diff --git a/test-cmd/xcd b/test-cmd/xcd @@ -0,0 +1,54 @@ +#!/usr/bin/env atf-sh +# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> +# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only + +atf_test_case openfile +openfile_body() { + atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd inputs/all_bytes +} + +atf_test_case stdinput +stdinput_body() { + atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd <inputs/all_bytes + atf_check -o file:outputs/xcd/all_bytes ../cmd/xcd - <inputs/all_bytes +} + +atf_test_case nullfile +nullfile_body() { + atf_check -o file:outputs/xcd/null ../cmd/xcd /dev/null +} + +atf_test_case nullinput +nullinput_body() { + atf_check -o file:outputs/xcd/null ../cmd/xcd </dev/null +} + +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:' ../cmd/xcd inputs/chmod_000 +} +noperm_cleanup() { + chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000" + rm inputs/chmod_000 || atf_fail "rm chmod_000" +} + +atf_test_case devfull +devfull_body() { + # shellcheck disable=SC1112 + atf_check -s 'exit:1' -e 'inline:\nWrite error: No space left on device\n\nError closing ‘inputs/strings/true’: No space left on device\n' sh -c '../cmd/xcd inputs/strings/true >/dev/full' + atf_check -s 'exit:1' -e 'inline:\nWrite error: No space left on device\n' sh -c '../cmd/xcd <inputs/strings/true >/dev/full' + atf_check -s 'exit:1' -e 'inline:\nWrite error: No space left on device\n' sh -c '../cmd/xcd - <inputs/strings/true >/dev/full' +} + +atf_init_test_cases() { + cd "$(atf_get_srcdir)" || exit 1 + atf_add_test_case openfile + atf_add_test_case stdinput + atf_add_test_case nullfile + atf_add_test_case nullinput + atf_add_test_case noperm + atf_add_test_case devfull +} diff --git a/test-sbin/Kyuafile b/test-sbin/Kyuafile @@ -1,10 +0,0 @@ --- SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> --- SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only -syntax(2) - -test_suite("utils") - -basedir = fs.dirname(fs.dirname(current_kyuafile())) - --- 7,$|LC_ALL=C.UTF-8 sort -atf_test_program{name="memsys", required_files=basedir.."/sbin/memsys", timeout=1} diff --git a/test-sbin/memsys b/test-sbin/memsys @@ -1,48 +0,0 @@ -#!/usr/bin/env atf-sh -# SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me> -# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only - - -atf_test_case basic cleanup -basic_body() { - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - atf_check touch ./tmp-memsys - atf_check -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys /sys/power/state ../sbin/memsys - atf_check -o 'inline:mem' cat tmp-memsys -} -basic_cleanup() { - rm -f tmp-memsys -} - -atf_test_case chmod_000 cleanup -chmod_000_body() { - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - atf_check touch ./tmp-memsys.000 - atf_check chmod 000 ./tmp-memsys.000 - atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind ./tmp-memsys.000 /sys/power/state ../sbin/memsys - atf_check chmod 600 ./tmp-memsys.000 - atf_check -o empty cat tmp-memsys.000 -} -chmod_000_cleanup() { - rm -f tmp-memsys.000 -} - -atf_test_case devfull -devfull_body() { - command -v "${BWRAP:-bwrap}" >/dev/null 2>/dev/null || atf_skip "${BWRAP:-bwrap} command not found" - [ -n "${NO_BWRAP}" ] && atf_skip "'NO_BWRAP' set" - - atf_check -s exit:1 -e 'inline:memsys: open("/sys/power/state"): Permission denied\n' -- "${BWRAP:-bwrap}" --bind / / --bind /dev/full /sys/power/state ../sbin/memsys -} - -atf_init_test_cases() { - cd "$(atf_get_srcdir)" || exit 1 - - atf_add_test_case basic - atf_add_test_case chmod_000 - atf_add_test_case devfull -}