commit: e327aa07cef8f2ffa6484122cf4aaae22dab6a86
parent f8c8153c76bc5250fc96f4dbd13256eb2a4bca21
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 2 Mar 2022 19:58:18 +0100
tests: Add has_glibc and has_musl functions
Diffstat:
7 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/test-bin/basename b/test-bin/basename
@@ -32,10 +32,7 @@ usage_body() {
atf_test_case devfull
devfull_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
- atf_expect_fail "glibc ignoring write errors for puts()"
- fi
+ 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()"
@@ -60,6 +57,9 @@ doubledash_body() {
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
diff --git a/test-bin/date b/test-bin/date
@@ -26,10 +26,7 @@ echolike_body() {
atf_test_case devfull
devfull_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
- atf_expect_fail "glibc ignoring write errors for puts()"
- fi
+ 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()"
@@ -43,6 +40,9 @@ utc_body() {
atf_init_test_cases() {
cd "$(atf_get_srcdir)" || exit 1
+
+ . ../test_functions.sh
+
atf_add_test_case noargs
atf_add_test_case epoch
atf_add_test_case rfc3339
diff --git a/test-bin/errno b/test-bin/errno
@@ -11,20 +11,16 @@ noargs_body() {
atf_test_case devfull
devfull_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
- atf_expect_fail "glibc ignoring write errors for puts()"
- fi
+ 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 -o "inline:usage: errno <number>\n" sh -c '../bin/errno 1 >/dev/full'
+ atf_check -s exit:1 sh -c '../bin/errno 1 >/dev/full'
}
atf_test_case einval
einval_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
+ if has_glibc; then
atf_check -s exit:0 -o "inline:Unknown error -1\n" ../bin/errno -1
else
atf_check -s exit:1 -e "inline:errno: strerror: Invalid argument\n" ../bin/errno -1
@@ -33,6 +29,9 @@ einval_body() {
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
diff --git a/test-bin/strings b/test-bin/strings
@@ -29,10 +29,7 @@ devnull_body() {
atf_test_case devfull
devfull_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
- atf_expect_fail "glibc ignoring write errors for puts()"
- fi
+ 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()"
@@ -83,6 +80,8 @@ usage_body() {
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
diff --git a/test-bin/tee b/test-bin/tee
@@ -39,15 +39,12 @@ noperm_cleanup() {
atf_test_case devfull
devfull_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
- atf_expect_fail "glibc ignoring write errors for fputs()"
- fi
+ 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()"
- atf_check -s exit:1 -e 'inline:Error writing: No space left on device\n' sh -c '../bin/tee <inputs/all_bytes >/dev/full'
- atf_check -s exit:1 -e 'inline:Error writing: No space left on device\n' sh -c '../bin/tee - <inputs/all_bytes >/dev/full'
+ 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_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
@@ -80,6 +77,9 @@ doubledash_body() {
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
diff --git a/test-bin/tty b/test-bin/tty
@@ -21,10 +21,7 @@ out_devnull_body() {
atf_test_case out_devfull
out_devfull_body() {
- if test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
- then
- atf_expect_fail "glibc ignoring write errors for puts()"
- fi
+ 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()"
@@ -35,6 +32,9 @@ out_devfull_body() {
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
diff --git a/test_functions.sh b/test_functions.sh
@@ -0,0 +1,7 @@
+has_glibc() {
+ test -f /usr/include/features.h && grep -q '#define\W__GLIBC__' /usr/include/features.h
+}
+
+has_musl() {
+ command -v ldd && ldd 2>&1 | grep -q musl
+}