From 4a460fab31090260f66b2f02a9617e01a8c702bf Mon Sep 17 00:00:00 2001 From: hobovsky Date: Tue, 14 Feb 2023 18:23:56 +0100 Subject: [PATCH 1/4] Improve output of failed tests --- spec/example_spec.lua | 29 ++++++++++++++++++++++++++ src/busted/outputHandlers/codewars.lua | 7 +++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/spec/example_spec.lua b/spec/example_spec.lua index ab4bd4d..388d0b1 100644 --- a/spec/example_spec.lua +++ b/spec/example_spec.lua @@ -24,5 +24,34 @@ describe("Busted unit testing framework", function() it("should provide some shortcuts to common functions", function() assert.are.unique({{ thing = 1 }, { thing = 2 }, { thing = 3 }}) end) + + it("should present failed assertions with FAILED", function() + assert.falsy(0) + end) + + describe("should present errors in IT with LOG", function() + it("IT with an error", function() + local nilobj = nil + nilobj.test() + assert.falsy(0) + end) + end) + + describe("should present errors in describe with ERROR", function() + + local nilobj = nil + nilobj.test() + + it("dummy IT", function() + assert.falsy(0) + end) + end) + + describe("should present errors in IT titles with ERROR", function() + local nilobj = nil + it("it block with ERROR" .. nilobj.test(), function() + assert.falsy(0) + end) + end) end) end) diff --git a/src/busted/outputHandlers/codewars.lua b/src/busted/outputHandlers/codewars.lua index 33e58fe..5346d32 100644 --- a/src/busted/outputHandlers/codewars.lua +++ b/src/busted/outputHandlers/codewars.lua @@ -29,9 +29,9 @@ return function(options) end local function onTestFailure(element, parent, message, debug) - print('\nTest Failed') -- remove '/home/codewarrior/lua/fixture.lua:\d+: ' from message - print('\n' .. escape(message:sub(message:find(' ') + 1))) + local msg = escape(message:sub(message:find(' ') + 1)) + print('\nTest Failed<:LF:>' .. msg) return nil, true end @@ -43,8 +43,7 @@ return function(options) local function onError(element, parent, message, debug) if element.descriptor ~= 'it' then - print('\nError') - print('\n' .. escape(message)) + print('\nError<:LF:>' .. escape(message)) end return nil, true end From fdf0b9466d0a1bb77b156ea80b0bbe4ca4f5c562 Mon Sep 17 00:00:00 2001 From: hobovsky Date: Tue, 14 Feb 2023 23:42:49 +0100 Subject: [PATCH 2/4] Apply remarks from review --- src/busted/outputHandlers/codewars.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/busted/outputHandlers/codewars.lua b/src/busted/outputHandlers/codewars.lua index 5346d32..a1d89c5 100644 --- a/src/busted/outputHandlers/codewars.lua +++ b/src/busted/outputHandlers/codewars.lua @@ -31,7 +31,7 @@ return function(options) local function onTestFailure(element, parent, message, debug) -- remove '/home/codewarrior/lua/fixture.lua:\d+: ' from message local msg = escape(message:sub(message:find(' ') + 1)) - print('\nTest Failed<:LF:>' .. msg) + print('\n' .. msg) return nil, true end From 98f059eb4041d2b80ac2d8f456d0028a56264a6f Mon Sep 17 00:00:00 2001 From: hobovsky Date: Wed, 15 Feb 2023 00:40:14 +0100 Subject: [PATCH 3/4] Add example test case with custom assertion message --- spec/example_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/example_spec.lua b/spec/example_spec.lua index 388d0b1..de963d1 100644 --- a/spec/example_spec.lua +++ b/spec/example_spec.lua @@ -29,6 +29,10 @@ describe("Busted unit testing framework", function() assert.falsy(0) end) + it("should present failed assertions with custom message", function() + assert.are.same(13, 42, "Incorrect answer for input n=10") + end) + describe("should present errors in IT with LOG", function() it("IT with an error", function() local nilobj = nil From a5e1be56119fb084897b91dbf72930d6d540df99 Mon Sep 17 00:00:00 2001 From: hobovsky Date: Wed, 15 Feb 2023 00:50:48 +0100 Subject: [PATCH 4/4] Support newlines in titles of groups and tests --- spec/example_spec.lua | 10 ++++++++++ src/busted/outputHandlers/codewars.lua | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spec/example_spec.lua b/spec/example_spec.lua index de963d1..379f2b5 100644 --- a/spec/example_spec.lua +++ b/spec/example_spec.lua @@ -58,4 +58,14 @@ describe("Busted unit testing framework", function() end) end) end) + + describe("Should support newlines\nin group titles", function() + it("Should support newlines\nin test titles", function() + assert.truthy(0, "Should support newlines\nin assertion messages") + end) + it("Should support newlines\nin errors", function() + error("Error message with...\n a newline") + assert.truthy(0) + end) + end) end) diff --git a/src/busted/outputHandlers/codewars.lua b/src/busted/outputHandlers/codewars.lua index a1d89c5..4f7a83c 100644 --- a/src/busted/outputHandlers/codewars.lua +++ b/src/busted/outputHandlers/codewars.lua @@ -6,7 +6,7 @@ return function(options) end local function onDescribeStart(element, parent) - print('\n' .. element.name) + print('\n' .. escape(element.name)) return nil, true end local function onDescribeEnd(element, parent) @@ -16,7 +16,7 @@ return function(options) end local function onTestStart(element, parent) - print('\n' .. element.name) + print('\n' .. escape(element.name)) return nil, true end local function onTestEnd(element, parent, status, trace)