ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: [Wireshark-dev] Hints needed on how to write a negative Lua test ...

From: Richard Sharpe <realrichardsharpe@xxxxxxxxx>
Date: Tue, 16 Oct 2018 20:46:44 -0700
Hi folks,

I added the following change to tests/lua/tvb.lua:

--- test/lua/tvb.lua    2018-10-16 20:24:27.603826969 -0700
+++ ../tvb.lua  2018-10-16 20:24:19.060549963 -0700
@@ -198,6 +198,21 @@

 print("test_proto ProtoFields registered")

+local new_range_string = {
+  { 0, 200, "The first part", "too many" },
+  { 201, 233, "The second part" },
+  { 234, 255, "The last part" },
+}
+
+local test_field = ProtoField.uint8 ("test.basic.too_many", "Basic
uint8 with too many items in a table", base.RANGE_STRING,
new_range_string)
+
+local new_pfields = { test_field }
+
+if pcall(function() test_proto.fields = new_pfields end) then
+    error("Range string has too many items but was accepted!")
+else
+    print("Invalid range string failed to register as expected")
+end

 local getfield =
 {
-----------------------

and it fails as expected, but it causes the tests to fail. I thought
that pcall would allow me to capture the error and handle it.

Is that not the case?

-- 
Regards,
Richard Sharpe
(何以解憂?唯有杜康。--曹操)(传说杜康是酒的发明者)