File: cl_output_handler.lua

package info (click to toggle)
lua-busted 2.0~rc12-1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 656 kB
  • ctags: 310
  • sloc: sh: 191; makefile: 6
file content (26 lines) | stat: -rw-r--r-- 886 bytes parent folder | download | duplicates (2)
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
-- supporting testfile; belongs to 'cl_spec.lua'

return function(options)
  local busted = require 'busted'
  local handler = require 'busted.outputHandlers.base'()
  local cli = require 'cliargs'
  local args = options.arguments

  cli:set_name('cl_output_handler')
  cli:flag('--time', 'show timestamps')
  cli:option('--time-format=FORMAT', 'format string according to strftime', '!%a %b %d %H:%M:%S %Y')

  local cliArgs = cli:parse(args)

  handler.testEnd = function(element, parent, status, debug)
    local showTime = cliArgs.time
    local timeFormat = cliArgs['time-format']
    local timestamp = showTime and ('[' .. os.date(timeFormat, 123456) .. '] ') or ''

    print(string.format("%s[%8s] %s", timestamp, status, handler.getFullName(element)))
  end

  busted.subscribe({ 'test', 'end' }, handler.testEnd, { predicate = handler.cancelOnPending })

  return handler
end