From a5ffa54ee71c9819fc413fdf118774b1db21a1df Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Fri, 13 Feb 2026 15:07:37 +0100 Subject: align error handling --- spec/02-random_spec.lua | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'spec/02-random_spec.lua') diff --git a/spec/02-random_spec.lua b/spec/02-random_spec.lua index db5d5ce..7b2eea6 100644 --- a/spec/02-random_spec.lua +++ b/spec/02-random_spec.lua @@ -155,24 +155,27 @@ describe("Random:", function() end) - it("returns nil and error for empty interval (m > n)", function() - local v, err = system.rnd(10, 5) - assert.is_falsy(v) - assert.are.equal("interval is empty", err) + it("throws for empty interval (m > n), like math.random", function() + local ok_math, _ = pcall(math.random, 10, 5) + assert.is_falsy(ok_math, "math.random(10, 5) should error") + local ok_rnd, _ = pcall(system.rnd, 10, 5) + assert.is_falsy(ok_rnd, "rnd(10, 5) should throw like math.random") end) - it("returns nil and error for invalid one-arg (m < 1, m ~= 0)", function() - local v, err = system.rnd(-1) - assert.is_falsy(v) - assert.are.equal("interval is empty", err) + it("throws for invalid one-arg (m < 1, m ~= 0), like math.random", function() + local ok_math, _ = pcall(math.random, -1) + assert.is_falsy(ok_math, "math.random(-1) should error") + local ok_rnd, _ = pcall(system.rnd, -1) + assert.is_falsy(ok_rnd, "rnd(-1) should throw like math.random") end) - it("returns nil and error for wrong number of arguments", function() - local v, err = system.rnd(1, 2, 3) - assert.is_falsy(v) - assert.are.equal("wrong number of arguments", err) + it("throws for wrong number of arguments, like math.random", function() + local ok_math, _ = pcall(math.random, 1, 2, 3) + assert.is_falsy(ok_math, "math.random(1, 2, 3) should error") + local ok_rnd, _ = pcall(system.rnd, 1, 2, 3) + assert.is_falsy(ok_rnd, "rnd(1, 2, 3) should throw like math.random") end) end) -- cgit v1.2.3-55-g6feb