local utils = require 'busted.utils'

return function()
  local loadHelper = function(helper, hpath, options, busted)
    local success, err = pcall(function()
      if helper:match('%.lua$') or helper:match('%.moon$') then
        dofile(utils.normpath(hpath))
      else
        require(helper)
      end
    end)

    if not success then
      busted.publish({ 'error', 'helper' }, { descriptor = 'helper', name = helper }, nil, err, {})
    end
  end

  return loadHelper
end

local utils = require 'busted.utils'
local hasMoon, moonscript = pcall(require, 'moonscript')

return function()
  local loadHelper = function(helper, hpath, options, busted)
    local success, err = pcall(function()
      if helper:match('%.lua$') then
        dofile(utils.normpath(hpath))
      elseif hasMoon and helper:match('%.moon$') then
        moonscript.dofile(utils.normpath(hpath))
      else
        require(helper)
      end
    end)

    if not success then
      busted.publish({ 'error', 'helper' }, { descriptor = 'helper', name = helper }, nil, err, {})
    end
  end

  return loadHelper
end

Support loading helper moonscript files
Support loading helper moonscript files
