demonnic / muddler

A build tool for Mudlet package developers
MIT License
40 stars 12 forks source link

Mudlet test helper #18

Closed demonnic closed 3 years ago

demonnic commented 3 years ago

Adds new "outputFile" key to mfile, which when true causes muddler to write a .output file to the root of your project when it is done building. This file contains a simple json object with the package name and the file location.

Also adds a new Muddler mpackage you can install in Mudlet which allows for reloading muddler packages when they are built, by adding a filewatch for the .output file and using the pkgname/path to drive a basic lifecycle. This lifecycle is intended to be develop time only, which is to say things you want to have happen when testing the package which you don't necessarily want to happen on pkg removal/install on your users machine, such as test object setup or teardown, running test functions, etc.

The most basic of these might look like this:

myCIhelper = myCIhelper or Muddler:new({
  path = "/home/demonnic/gitbox/MDK"
})

And is enough to cause Mudlet to uninstall and reinstall the MDK mpackage created when I run muddler in /home/demonnic/gitbox/MDK. All available options are:

The actual helper for MDK I'm using right now is setup like this

local function killMDK()
  for pkgName, _ in pairs(package.loaded) do
    if pkgName:find("MDK") then
      debugc("Uncaching lua package " .. pkgName)
      package.loaded[pkgName] = nil
    end
  end
end
local function create_helper()
  if MDKhelper then MDKhelper:stop() end
  MDKhelper = Muddler:new({
    path = "/home/demonnic/gitbox/MDK",
    postremove = killMDK,
  })
end

if not MDKhelper then
  registerAnonymousEventHandler("sysLoadEvent", create_helper)
end

And the output in the error console

image