diff options
author | 2024-08-07 10:13:53 +0100 | |
---|---|---|
committer | 2024-08-11 11:10:56 +0100 | |
commit | a56d2680c5f2a3dfa2a402fe138641721d42df24 (patch) | |
tree | a06d9f9b7504f9568a90103ddf6367b74ecfff7d | |
parent | Avoid a subshell for is_identifier() (diff) | |
download | gentoo-functions-a56d2680c5f2a3dfa2a402fe138641721d42df24.tar.gz gentoo-functions-a56d2680c5f2a3dfa2a402fe138641721d42df24.tar.bz2 gentoo-functions-a56d2680c5f2a3dfa2a402fe138641721d42df24.zip |
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@plushkava.net>
Signed-off-by: Sam James <sam@gentoo.org>
-rwxr-xr-x | test-functions | 3 |
1 files changed, 1 insertions, 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 "$@" |