From e4a8a54430200f30266e4b524a119412584f7e73 Mon Sep 17 00:00:00 2001 From: Sainan Date: Thu, 7 Sep 2023 18:20:13 +0200 Subject: [PATCH] Improve "this should raise a warning" testing --- testes/pluto/basic.pluto | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/testes/pluto/basic.pluto b/testes/pluto/basic.pluto index b259465ec2..b29837c2ac 100644 --- a/testes/pluto/basic.pluto +++ b/testes/pluto/basic.pluto @@ -1,8 +1,19 @@ +print "Welcome to the test suite." + +-- Testing warnings do - local a = 1 - local a = 2 + local function assert_warn(code) + local had_warn = false + setwarnf(function(msg) + had_warn = true + end) + load(code)() + assert(had_warn) + end + assert_warn([[local a; local a]]) -- var-shadow + assert_warn([[local a = 69; local b: string = a]]) -- type mismatch in local-to-local assignment + assert_warn([[g = 69; local l: string = g]]) -- type mismatch in global-to-local assignment end -print "Welcome to the test suite. There should have been exactly 1 parser warning." -- Testing type hints (there should be no warnings here) do