logo

utils-std

Collection of commonly available Unix tools
commit: db468cfb5af3c7524f8ae3d689e02557d46022cf
parent a476bc45fdd2b9462f7f86745c8b7025cd3923fe
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon,  6 May 2024 05:51:48 +0200

test-lib/symbolize_mode: Roll TAP producer

Diffstat:

MMakefile2+-
Mtest-lib/Kyuafile2+-
Mtest-lib/symbolize_mode.c47++++++++++++++++++++++++++---------------------
3 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/Makefile b/Makefile @@ -94,7 +94,7 @@ test-lib/strtodur: test-lib/strtodur.c lib/strtodur.c Makefile $(CC) -std=c99 $(CFLAGS) $(ATF_CFLAGS) -o $@ test-lib/strtodur.c lib/strtodur.c $(LDFLAGS) $(ATF_LIBS) test-lib/symbolize_mode: test-lib/symbolize_mode.c lib/symbolize_mode.c Makefile - $(CC) -std=c99 $(CFLAGS) $(ATF_CFLAGS) -o $@ test-lib/symbolize_mode.c lib/symbolize_mode.c $(LDFLAGS) $(ATF_LIBS) + $(CC) -std=c99 $(CFLAGS) -o $@ test-lib/symbolize_mode.c lib/symbolize_mode.c $(LDFLAGS) $(LDSTATIC) test-lib/truncation: test-lib/truncation.c lib/truncation.c Makefile $(CC) -std=c99 $(CFLAGS) $(ATF_CFLAGS) -o $@ test-lib/truncation.c lib/truncation.c $(LDFLAGS) $(ATF_LIBS) diff --git a/test-lib/Kyuafile b/test-lib/Kyuafile @@ -7,5 +7,5 @@ test_suite("utils-std libs") -- 7,$|LC_ALL=C.UTF-8 sort tap_test_program{name="mode"} atf_test_program{name="strtodur"} -atf_test_program{name="symbolize_mode"} +tap_test_program{name="symbolize_mode"} atf_test_program{name="truncation"} diff --git a/test-lib/symbolize_mode.c b/test-lib/symbolize_mode.c @@ -3,35 +3,40 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L -#include <atf-c.h> +#include "../lib/mode.h" #include <assert.h> -#include <signal.h> // SIGABRT -#include <sys/stat.h> // umask +#include <stdio.h> // printf +#include <string.h> // strcmp -#include "../lib/mode.h" +int counter = 0; +int err = 0; -ATF_TC(examples); -ATF_TC_HEAD(examples, tc) -{ - atf_tc_set_md_var(tc, "descr", "some usual examples"); -} -ATF_TC_BODY(examples, tc) +static void +t_symbolize_mode(mode_t mode, char *expected) { char str[11] = ""; - - symbolize_mode(0040000, str); - ATF_CHECK_STREQ("d---------", str); - - symbolize_mode(0040755, str); - ATF_CHECK_STREQ("drwxr-xr-x", str); + symbolize_mode(mode, str); + if(strcmp(str, expected) == 0) + { + printf("ok %d - %7o -> %s\n", ++counter, mode, expected); + return; + } - symbolize_mode(0020644, str); - ATF_CHECK_STREQ("crw-r--r--", str); + err = 1; + printf("not ok %d - %7o -> %s\n", ++counter, mode, expected); + printf("# Got: %s\n", str); } -ATF_TP_ADD_TCS(tp) +int +main() { - ATF_TP_ADD_TC(tp, examples); + int plan = 3; + printf("1..%d\n", plan); + + t_symbolize_mode(0040000, "d---------"); + t_symbolize_mode(0040755, "drwxr-xr-x"); + t_symbolize_mode(0020644, "crw-r--r--"); - return atf_no_error(); + assert(counter == plan); + return err; }