S-S-X / mineunit

Minetest core / engine libraries for regression tests
Other
10 stars 6 forks source link

Allow accessing private mod variables #66

Open S-S-X opened 2 years ago

S-S-X commented 2 years ago

This should allow retrieving local variables and functions for validation and unit tests.

For example could be mineunit:get_local("init.lua", "secretdata") to get local secretdata = "internal stuff" defined in mod init.lua.

Internal functions could be tested with

it("returns Hello World", function()
  local fn = mineunit:get_local("init.lua", "hello")
  assert.is_function(fn)
  assert.equals("Hello World", fn("World"))
end)

When mod init.lua contains

local function hello(msg)
  return "Hello " .. msg
end
S-S-X commented 2 years ago

This might not be that good idea after all, sure it would allow testing internal API / functions / variables but is harder to keep track of, might be confusing (when tests fail even while API is completely fine) and possibly encourages worse tests and worse API design.

Also I'm not sure if there's any legitimate uses for this feature.