From 52f9e58b8f0d14d8173a1a8bfb82b64da7d43464 Mon Sep 17 00:00:00 2001 From: Jack Lawson Date: Thu, 14 Aug 2014 20:52:15 -0700 Subject: [PATCH] Really suppress pending --- busted/init.lua | 30 +++++++++++++++---------- busted/outputHandlers/base.lua | 14 ++++++++++-- busted/outputHandlers/junit.lua | 2 +- busted/outputHandlers/plainTerminal.lua | 2 +- busted/outputHandlers/utfTerminal.lua | 2 +- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/busted/init.lua b/busted/init.lua index c1231dc3..229039a1 100644 --- a/busted/init.lua +++ b/busted/init.lua @@ -72,30 +72,36 @@ return function(busted) busted.publish({ 'describe', 'end' }, describe, parent) end - local it = function(it) + local it = function(element) local finally - if not it.env then it.env = {} end + if not element.env then element.env = {} end - it.env.finally = function(fn) + element.env.finally = function(fn) finally = fn end - local parent = busted.context.parent(it) + local parent = busted.context.parent(element) execAll('before_each', parent, true) - busted.publish({ 'test', 'start' }, it, parent) - local res = busted.safe('it', it.run, it) - if not it.env.done then - busted.publish({ 'test', 'end' }, it, parent, res and 'success' or 'failure') - if finally then busted.safe('finally', finally, it) end + + busted.publish({ 'test', 'start' }, element, parent) + busted.publish({ 'test', 'foo' }, element, parent) + + local res = busted.safe('element', element.run, element) + if not element.env.done then + local trace = busted.getTrace(element, 3) + busted.publish({ 'test', 'end' }, element, parent, res and 'success' or 'failure', trace) + if finally then busted.safe('finally', finally, element) end dexecAll('after_each', parent, true) end end - local pending = function(pending) - local trace = busted.getTrace(pending, 3) - busted.publish({ 'test', 'end' }, pending, busted.context.parent(pending), 'pending', trace) + local pending = function(element) + local parent = busted.context.parent(pending) + local trace = busted.getTrace(element, 3) + busted.publish({ 'test', 'start' }, element, parent) + busted.publish({ 'test', 'end' }, element, parent, 'pending', trace) end busted.register('file', file) diff --git a/busted/outputHandlers/base.lua b/busted/outputHandlers/base.lua index 2b4baf58..f2d6f4e6 100644 --- a/busted/outputHandlers/base.lua +++ b/busted/outputHandlers/base.lua @@ -11,8 +11,13 @@ return function(busted) inProgress = {} } + handler.cancelOnPending = function(element) + return not (element.descriptor == 'pending' and handler.options.suppressPending) + end + handler.subscribe = function(handler, options) require('busted.languages.en') + handler.options = options if options.language ~= 'en' then require('busted.languages.' .. options.language) @@ -20,8 +25,8 @@ return function(busted) busted.subscribe({ 'suite', 'start' }, handler.baseSuiteStart) busted.subscribe({ 'suite', 'end' }, handler.baseSuiteEnd) - busted.subscribe({ 'test', 'start' }, handler.baseTestStart) - busted.subscribe({ 'test', 'end' }, handler.baseTestEnd) + busted.subscribe({ 'test', 'start' }, handler.baseTestStart, { predicate = handler.cancelOnPending }) + busted.subscribe({ 'test', 'end' }, handler.baseTestEnd, { predicate = handler.cancelOnPending }) busted.subscribe({ 'error' }, handler.baseError) end @@ -72,11 +77,16 @@ return function(busted) end handler.baseTestStart = function(element, parent) + if element.descriptor == 'pending' and handler.options.suppressPending then + return nil, false + end + handler.inProgress[tostring(element)] = {} return nil, true end handler.baseTestEnd = function(element, parent, status, debug) + local insertTable local id = tostring(element) diff --git a/busted/outputHandlers/junit.lua b/busted/outputHandlers/junit.lua index 4f125992..c11df0db 100644 --- a/busted/outputHandlers/junit.lua +++ b/busted/outputHandlers/junit.lua @@ -63,7 +63,7 @@ return function(options, busted) busted.subscribe({ 'suite', 'start' }, handler.suiteStart) busted.subscribe({ 'suite', 'end' }, handler.suiteEnd) - busted.subscribe({ 'test', 'end' }, handler.testEnd) + busted.subscribe({ 'test', 'end' }, handler.testEnd, { predicate = handler.cancelOnPending }) busted.subscribe({ 'error', 'file' }, handler.errorFile) return handler diff --git a/busted/outputHandlers/plainTerminal.lua b/busted/outputHandlers/plainTerminal.lua index c7024a97..00eeaf3d 100644 --- a/busted/outputHandlers/plainTerminal.lua +++ b/busted/outputHandlers/plainTerminal.lua @@ -142,7 +142,7 @@ return function(options, busted) return nil, true end - busted.subscribe({ 'test', 'end' }, handler.testEnd) + busted.subscribe({ 'test', 'end' }, handler.testEnd, { predicate = handler.cancelOnPending }) busted.subscribe({ 'suite', 'end' }, handler.suiteEnd) busted.subscribe({ 'error', 'file' }, handler.error) busted.subscribe({ 'error', 'describe' }, handler.error) diff --git a/busted/outputHandlers/utfTerminal.lua b/busted/outputHandlers/utfTerminal.lua index 792f02d6..5af344ef 100644 --- a/busted/outputHandlers/utfTerminal.lua +++ b/busted/outputHandlers/utfTerminal.lua @@ -143,7 +143,7 @@ return function(options, busted) return nil, true end - busted.subscribe({ 'test', 'end' }, handler.testEnd) + local s = busted.subscribe({ 'test', 'end' }, handler.testEnd, { predicate = handler.cancelOnPending }) busted.subscribe({ 'suite', 'end' }, handler.suiteEnd) busted.subscribe({ 'error', 'file' }, handler.error) busted.subscribe({ 'error', 'describe' }, handler.error)