diff options
| author | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-02-13 15:20:06 +0100 |
|---|---|---|
| committer | Thijs Schreijer <thijs@thijsschreijer.nl> | 2026-02-13 15:20:06 +0100 |
| commit | c074cf4362c2d591cdab9cdc1609e29ebfb3ca40 (patch) | |
| tree | f50a1a963dfe4acf11dc797cfbe6d52a65cd290e /spec/02-random_spec.lua | |
| parent | a5ffa54ee71c9819fc413fdf118774b1db21a1df (diff) | |
| download | luasystem-c074cf4362c2d591cdab9cdc1609e29ebfb3ca40.tar.gz luasystem-c074cf4362c2d591cdab9cdc1609e29ebfb3ca40.tar.bz2 luasystem-c074cf4362c2d591cdab9cdc1609e29ebfb3ca40.zip | |
exclude LuaJIT for erro testsfeat/rnd
Diffstat (limited to 'spec/02-random_spec.lua')
| -rw-r--r-- | spec/02-random_spec.lua | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/spec/02-random_spec.lua b/spec/02-random_spec.lua index 7b2eea6..6a8ea5b 100644 --- a/spec/02-random_spec.lua +++ b/spec/02-random_spec.lua | |||
| @@ -49,6 +49,7 @@ describe("Random:", function() | |||
| 49 | describe("rnd()", function() | 49 | describe("rnd()", function() |
| 50 | 50 | ||
| 51 | local has_math_type = type(math.type) == "function" | 51 | local has_math_type = type(math.type) == "function" |
| 52 | local is_luajit = (type(jit) == "table" and jit.version ~= nil) | ||
| 52 | 53 | ||
| 53 | it("with no args returns a number in [0, 1)", function() | 54 | it("with no args returns a number in [0, 1)", function() |
| 54 | local v, err = system.rnd() | 55 | local v, err = system.rnd() |
| @@ -155,28 +156,36 @@ describe("Random:", function() | |||
| 155 | end) | 156 | end) |
| 156 | 157 | ||
| 157 | 158 | ||
| 158 | it("throws for empty interval (m > n), like math.random", function() | 159 | if not is_luajit then |
| 159 | local ok_math, _ = pcall(math.random, 10, 5) | 160 | -- LuaJIT's math.random does not raise errors for these invalid-argument |
| 160 | assert.is_falsy(ok_math, "math.random(10, 5) should error") | 161 | -- cases (it accepts empty intervals, negatives, extra args, etc.), |
| 161 | local ok_rnd, _ = pcall(system.rnd, 10, 5) | 162 | -- while stock Lua does. We only run these strict "throws like math.random" |
| 162 | assert.is_falsy(ok_rnd, "rnd(10, 5) should throw like math.random") | 163 | -- checks on non-LuaJIT runtimes. |
| 163 | end) | ||
| 164 | 164 | ||
| 165 | it("throws for empty interval (m > n), like math.random", function() | ||
| 166 | local ok_math, _ = pcall(math.random, 10, 5) | ||
| 167 | assert.is_falsy(ok_math, "math.random(10, 5) should error") | ||
| 168 | local ok_rnd, _ = pcall(system.rnd, 10, 5) | ||
| 169 | assert.is_falsy(ok_rnd, "rnd(10, 5) should throw like math.random") | ||
| 170 | end) | ||
| 165 | 171 | ||
| 166 | it("throws for invalid one-arg (m < 1, m ~= 0), like math.random", function() | ||
| 167 | local ok_math, _ = pcall(math.random, -1) | ||
| 168 | assert.is_falsy(ok_math, "math.random(-1) should error") | ||
| 169 | local ok_rnd, _ = pcall(system.rnd, -1) | ||
| 170 | assert.is_falsy(ok_rnd, "rnd(-1) should throw like math.random") | ||
| 171 | end) | ||
| 172 | 172 | ||
| 173 | it("throws for invalid one-arg (m < 1, m ~= 0), like math.random", function() | ||
| 174 | local ok_math, _ = pcall(math.random, -1) | ||
| 175 | assert.is_falsy(ok_math, "math.random(-1) should error") | ||
| 176 | local ok_rnd, _ = pcall(system.rnd, -1) | ||
| 177 | assert.is_falsy(ok_rnd, "rnd(-1) should throw like math.random") | ||
| 178 | end) | ||
| 173 | 179 | ||
| 174 | it("throws for wrong number of arguments, like math.random", function() | 180 | |
| 175 | local ok_math, _ = pcall(math.random, 1, 2, 3) | 181 | it("throws for wrong number of arguments, like math.random", function() |
| 176 | assert.is_falsy(ok_math, "math.random(1, 2, 3) should error") | 182 | local ok_math, _ = pcall(math.random, 1, 2, 3) |
| 177 | local ok_rnd, _ = pcall(system.rnd, 1, 2, 3) | 183 | assert.is_falsy(ok_math, "math.random(1, 2, 3) should error") |
| 178 | assert.is_falsy(ok_rnd, "rnd(1, 2, 3) should throw like math.random") | 184 | local ok_rnd, _ = pcall(system.rnd, 1, 2, 3) |
| 179 | end) | 185 | assert.is_falsy(ok_rnd, "rnd(1, 2, 3) should throw like math.random") |
| 186 | end) | ||
| 187 | |||
| 188 | end | ||
| 180 | 189 | ||
| 181 | end) | 190 | end) |
| 182 | 191 | ||
