logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: 4e8b536118f87ce6afe62812445c5d156f405410
parent 287fe45b053c0712bddf646940316a27299f1334
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 15 Mar 2022 13:42:24 +0100

test-bin/sizeof: Add

Diffstat:

Mbin/sizeof.c26+++++++++++++++++++++-----
Mtest-bin/Kyuafile1+
Atest-bin/sizeof21+++++++++++++++++++++
3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/bin/sizeof.c b/bin/sizeof.c @@ -13,22 +13,38 @@ static void print_size(size_t size, char *type) { - printf("sizeof(%s) == %zd bytes; %zd bits\n", type, size, size * CHAR_BIT); + int ret = printf("sizeof(%s) == %zd bytes; %zd bits\n", type, size, size * CHAR_BIT); + if(ret < 0) + { + exit(1); + } } int main(void) { - int c; + int c, ret; - printf("CHAR_BIT == %d\n", CHAR_BIT); + ret = printf("CHAR_BIT == %d\n", CHAR_BIT); + if(ret < 0) + { + exit(1); + } c = sizeof(int); /* flawfinder: ignore. Not given by user but by a macro */ - printf(FORMAT_M, "int", c, c * CHAR_BIT, INT_MIN, INT_MAX); + ret = printf(FORMAT_M, "int", c, c * CHAR_BIT, INT_MIN, INT_MAX); + if(ret < 0) + { + exit(1); + } c = sizeof(char); /* flawfinder: ignore. Not given by user but by a macro */ - printf(FORMAT_M, "char", c, c * CHAR_BIT, CHAR_MIN, CHAR_MAX); + ret = printf(FORMAT_M, "char", c, c * CHAR_BIT, CHAR_MIN, CHAR_MAX); + if(ret < 0) + { + exit(1); + } print_size(sizeof(uint8_t), "uint8_t"); print_size(sizeof(short), "short"); diff --git a/test-bin/Kyuafile b/test-bin/Kyuafile @@ -21,6 +21,7 @@ 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} diff --git a/test-bin/sizeof b/test-bin/sizeof @@ -0,0 +1,21 @@ +#!/usr/bin/env atf-sh +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 fputc()" + + 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 +}