aboutsummaryrefslogtreecommitdiffstats
path: root/test/lua/busted/modules/configuration_loader.lua
blob: f437a04cd0e60891328f5c4ac7e3ca2e9296f5cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
return function()
  local tablex = require 'pl.tablex'

  -- Function to load the .busted configuration file if available
  local loadBustedConfigurationFile = function(configFile, config, defaults)
    if type(configFile) ~= 'table' then
      return config, '.busted file does not return a table.'
    end

    local defaults = defaults or {}
    local run = config.run or defaults.run

    if run and run ~= '' then
      local runConfig = configFile[run]

      if type(runConfig) == 'table' then
        config = tablex.merge(runConfig, config, true)
      else
        return config, 'Task `' .. run .. '` not found, or not a table.'
      end
    end

    if type(configFile.default) == 'table' then
      config = tablex.merge(configFile.default, config, true)
    end

    config = tablex.merge(defaults, config, true)

    return config
  end

  return loadBustedConfigurationFile
end