File: configuration_loader.lua

package info (click to toggle)
lua-busted 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 820 kB
  • sloc: sh: 198; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 989 bytes parent folder | download | duplicates (5)
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
35
local tablex = require 'pl.tablex'

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

    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 nil, 'Task `' .. run .. '` not found, or not a table.'
      end
    elseif type(configFile.default) == 'table' then
      config = tablex.merge(configFile.default, config, true)
    end

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

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

    return config
  end

  return loadBustedConfigurationFile
end