diff options
author | Hadriel Kaplan <hadrielk@yahoo.com> | 2014-02-17 11:45:57 -0500 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2014-02-21 02:06:18 +0000 |
commit | 5b7f00178f45149ecdce204f1c71c1598ceedac1 (patch) | |
tree | ff32e3f6f27171b50569b159b96ae3ef1498a27f /test/lua/verify_globals.lua | |
parent | 9246a709bf826f2cc64581b25fbf1ebafa330db6 (diff) |
Add test suite for verifying Lua global variables/tables of previous releases have not disappeared.
Several bugs have been introduced due to changing of perl scripts or #define names, such
that things exported into Lua have dissapeared or changed unintentionally. This commit
adds a test suite which compares the Lua global table with the ones from previous
releases (1.8 and 1.10), to verify nothing has gone missing. New items can be added, but
old ones cannot go away. The added script to verify these things, called 'verify_globals.lua',
also has the ability to display what's new - i.e., what was not in the olrder releases.
Lastly, this commit also fixes a bug: MENU_STAT_ENDPOINT became MENU_STAT_ENDPOINT_LIST
due to a change in the make-init-lua.pl perl script in this 1.11 release.
Change-Id: Ic46172904256dc535b0fe4543237c07dddb3b9b5
Reviewed-on: https://code.wireshark.org/review/242
Reviewed-by: Evan Huus <eapache@gmail.com>
Diffstat (limited to 'test/lua/verify_globals.lua')
-rw-r--r-- | test/lua/verify_globals.lua | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/test/lua/verify_globals.lua b/test/lua/verify_globals.lua new file mode 100644 index 0000000000..b9e78f813b --- /dev/null +++ b/test/lua/verify_globals.lua @@ -0,0 +1,121 @@ +-- verify_globals.lua + +-- need the path to find inspect.lua +local old_path = package.path +package.path = "lua/?.lua;" .. package.path + +local inspect = require("inspect") + +package.path = old_path + +-- ignore things that change on different machines or every release +-- the following items still have to exist, but their values don't have to match +local filter = { + -- differences by machine + "DATA_DIR", + "USER_DIR", + "package.cpath", + "package.path", + "package.loaded", + "run_user_scripts_when_superuser", + "running_superuser", + + -- differences in Lua versions + "_VERSION", + "package.config", + } + +-- the following items don't have to exist +local ignore = { + -- not sure why this was removed in wireshark 1.11, but it was + "TreeItem.set_expert_flags", + + -- in Lua 5.1 only + "debug.getfenv", + "debug.setfenv", + "gcinfo", + "getfenv", + "io.gfind", + "setfenv", + "math.mod", + "newproxy", + "string.gfind", + "table.foreach", + "table.foreachi", + "table.getn", + "table.setn", + + -- in Lua 5.2+ only + "bit32", + "debug.getuservalu", + "debug.setuservalu", + "debug.upvalueid", + "debug.upvaluejoin", + "package.searchers", + "package.searchpath", + "rawlen", + "table.pack", + "table.unpack", + +} + + +local arg={...} -- get passed-in args + +-- arg1 = filename to read in +-- arg2 = 'verify' to verify all of read-in file is in _G (default); 'new' to output all items in _G that are not in read-in file +-- arg3 = 'nometa' to ignore metatables + +print("-- Wireshark version: " .. get_version()) + +if #arg == 0 then + -- no args, so just output globals + print(inspect(_G, { serialize = true, filter = inspect.makeFilter(filter) })) + return +end + +local file = assert(io.open(arg[1], "r")) +local input = file:read("*all") +input = inspect.marshal(input) + +local nometa = false +if #arg > 2 and arg[3] == "nometa" then + nometa = true +end + +if #arg == 1 or arg[2] == "verify" then + print(string.rep("\n", 2)) + print("Verifying input file '"..arg[1].."' is contained within the global table") + local ret, diff = inspect.compare(input, _G, { + ['filter'] = inspect.makeFilter(filter), + ['ignore'] = inspect.makeFilter(ignore), + ['nonumber'] = true, + ['nometa'] = nometa + }) + if not ret then + print("Comparison failed - global table does not have all the items in the input file!") + print(string.rep("\n", 2)) + print(string.rep("-", 80)) + print("Differences are:") + print(inspect(diff)) + else + print("\n-----------------------------\n") + print("All tests passed!\n\n") + end + return +elseif #arg > 1 and arg[2] == "new" then + local ret, diff = inspect.compare(_G, input, { + ['filter'] = inspect.makeFilter(filter), + ['ignore'] = inspect.makeFilter(ignore), + ['nonumber'] = true, + ['keep'] = true, + ['nometa'] = nometa + }) + if not ret then + print(inspect(diff)) + else + print("\n-----------------------------\n") + print("No new items!\n\n") + end +end + |