LuaUnit is a popular unit-testing framework for Lua, with an interface typical of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms (Jenkins, Maven, ...).
I'm developing some lua code on OpenWrt 22.03 (latest for my device) which has Lua 5.1.5. I downloaded the luaunit.lua (version 3.4) file to my device, but when running I got the error
luaunit.lua:247: bad argument #1 to 'randomseed' (integer expected, got number)
It seems that the line below returns a number that is bigger than a 32 bit signed integer:
math.floor(os.clock()*1E11)
The initial value of the os.clock() is several hundred ms e.g. 0.07.
Suggestion - use modulus to force range within 32 bit range (and this worked for me)
math.floor((os.clock()*1E11) % 2147483647)
I'm developing some lua code on OpenWrt 22.03 (latest for my device) which has Lua 5.1.5. I downloaded the luaunit.lua (version 3.4) file to my device, but when running I got the error
luaunit.lua:247: bad argument #1 to 'randomseed' (integer expected, got number)
It seems that the line below returns a number that is bigger than a 32 bit signed integer:
math.floor(os.clock()*1E11)
The initial value of the os.clock() is several hundred ms e.g. 0.07. Suggestion - use modulus to force range within 32 bit range (and this worked for me)
math.floor((os.clock()*1E11) % 2147483647)
I noticed there was a related PR here
OpenWRT details
root@host:~# cat /etc/openwrt_release DISTRIB_ID='OpenWrt' DISTRIB_RELEASE='22.03.4' DISTRIB_REVISION='r20123-38ccc47687' DISTRIB_TARGET='ath79/nand' DISTRIB_ARCH='mips_24kc' DISTRIB_DESCRIPTION='OpenWrt 22.03.4 r20123-38ccc47687' DISTRIB_TAINTS='busybox'
Lua details
root@host:~# lua -v Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio (double int32)