Skip to content

Commit 3f66cf1

Browse files
committed
tests: add warning and setWarnF tests
Test that the warning handler works
1 parent a027e21 commit 3f66cf1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/ziglua.zig

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,24 @@ test "panic fn" {
22962296
try expectEqual(@as(?CFn, null), lua.atPanic(panicFn));
22972297
}
22982298

2299+
test "warn fn" {
2300+
var lua = try Lua.init(testing.allocator);
2301+
defer lua.deinit();
2302+
2303+
lua.warning("this message is going to the void", false);
2304+
2305+
const warnFn = wrap(struct {
2306+
fn inner(data: ?*anyopaque, msg: []const u8, to_cont: bool) void {
2307+
_ = data;
2308+
_ = to_cont;
2309+
if (!std.mem.eql(u8, msg, "this will be caught by the warnFn")) panic("test failed", .{});
2310+
}
2311+
}.inner);
2312+
2313+
lua.setWarnF(warnFn, null);
2314+
lua.warning("this will be caught by the warnFn", false);
2315+
}
2316+
22992317
test "concat" {
23002318
var lua = try Lua.init(testing.allocator);
23012319
defer lua.deinit();
@@ -2480,12 +2498,10 @@ test "refs" {
24802498
_ = Lua.setIUserValue;
24812499
_ = Lua.setMetatable;
24822500
_ = Lua.setTable;
2483-
_ = Lua.setWarnF;
24842501
_ = Lua.toClose;
24852502
_ = Lua.toPointer;
24862503
_ = Lua.toUserdata;
24872504
_ = Lua.upvalueIndex;
2488-
_ = Lua.warning;
24892505
_ = Lua.xMove;
24902506
_ = Lua.yield;
24912507
_ = Lua.yieldCont;

0 commit comments

Comments
 (0)