commit:     b675ffe825a13789f240d94312e8cff472c34418
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Feb 12 09:19:07 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 12 18:12:40 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b675ffe8

test-functions: Add a test for the yesno() function

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 test-functions | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/test-functions b/test-functions
index 9f4dfc5..df838f7 100755
--- a/test-functions
+++ b/test-functions
@@ -181,6 +181,44 @@ test_is_int() {
                iterate_tests 2 "$@"
 }
 
+test_yesno() {
+       set -- \
+               0  yes \
+               0  YES \
+               0  Yes \
+               0  true \
+               0  TRUE \
+               0  true \
+               0  on \
+               0  ON \
+               0  On \
+               0  1 \
+               1  no \
+               1  NO \
+               1  No \
+               1  false \
+               1  FALSE \
+               1  False \
+               1  off \
+               1  OFF \
+               1  Off \
+               1  0 \
+               1  not_a_nameref \
+               1  not-a-valid-nameref \
+               1  '_"; set -- yes # code injection' \
+               0  truthful_nameref
+
+               truthful_nameref=yes
+
+               callback() {
+                       shift
+                       test_description="yesno $(print_args "$@")"
+                       yesno "$@"
+               }
+
+               iterate_tests 2 "$@"
+}
+
 iterate_tests() {
        slice_width=$1
        shift
@@ -246,5 +284,6 @@ test_is_older_than || rc=1
 test_get_bootparam || rc=1
 test_esyslog || rc=1
 test_is_int || rc=1
+test_yesno || rc=1
 cleanup_tmpdir
 exit "${rc}"

Reply via email to