commit:     a56d2680c5f2a3dfa2a402fe138641721d42df24
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Wed Aug  7 09:13:53 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Aug 11 10:10:56 2024 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=a56d2680

test-functions: check numerical bounds with awk in test_srandom()

Use awk(1) to test whether the numbers produced by the srandom()
function are within bounds. One cannot necesarily rely upon the shell to
perform this task. Consider mksh(1) as a case in point. Contrary to the
specification, it implements integers as signed int rather than signed
long. Consequently, it can only handle numbers between -2147483648 and
2147483647, resulting in easily reproducible test failures caused by
overflow.

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

 test-functions | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/test-functions b/test-functions
index fd3f176..4b2f7f9 100755
--- a/test-functions
+++ b/test-functions
@@ -427,8 +427,7 @@ test_srandom() {
                number=$(srandom)
                test_description="srandom ($(( row += 1 ))/5: ${number:-blank})"
                is_int "${number}" \
-               && test "${number}" -ge 0 \
-               && test "${number}" -le 4294967295
+               && awk -v "n=${number}" 'BEGIN { exit !(n >= 0 && n <= 
4294967295) }'
        }
 
        iterate_tests 2 "$@"

Reply via email to