From d5170de79af683624266a9fbe9f3b981aad30e3e Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Fri, 19 Feb 2021 13:09:24 +0100 Subject: [PATCH 01/17] Add: 'Write testfile before running' behavior, to PlenaryTestFile --- plugin/plenary.vim | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugin/plenary.vim b/plugin/plenary.vim index a6ae381e..e8351f00 100644 --- a/plugin/plenary.vim +++ b/plugin/plenary.vim @@ -1,4 +1,3 @@ - " Set up neorocks if it is installed. lua pcall(function() require('plenary.neorocks').setup_paths() end) @@ -9,4 +8,12 @@ command! -nargs=1 -complete=file PlenaryBustedFile command! -nargs=+ -complete=file PlenaryBustedDirectory \ lua require('plenary.test_harness').test_directory_command(vim.fn.expand("")) -nnoremap PlenaryTestFile :lua require('plenary.test_harness').test_directory(vim.fn.expand("%:p")) +function! s:write_and_run_testfile() abort + if &filetype == 'lua' + :write + :lua require('plenary.test_harness').test_directory(vim.fn.expand("%:p")) + endif + return +endfunction + +nnoremap PlenaryTestFile :call write_and_run_testfile() From 8a2486e998d6aedbcd23f6e2940be67834726dd4 Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Fri, 19 Feb 2021 16:16:24 +0100 Subject: [PATCH 02/17] Preserve old keymap PlenaryTestFile and add PlenaryWriteAndRunTestFile --- plugin/plenary.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/plenary.vim b/plugin/plenary.vim index e8351f00..9177fde6 100644 --- a/plugin/plenary.vim +++ b/plugin/plenary.vim @@ -16,4 +16,5 @@ function! s:write_and_run_testfile() abort return endfunction -nnoremap PlenaryTestFile :call write_and_run_testfile() +nnoremap PlenaryWriteAndRunTestFile :call write_and_run_testfile() +nnoremap PlenaryTestFile :lua require('plenary.test_harness').test_directory(vim.fn.expand("%:p")) From b5b412242370fbe1f9b826d172110dfd1e97d5bf Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Fri, 19 Feb 2021 22:20:58 +0100 Subject: [PATCH 03/17] Update formatting of test results. --- lua/plenary/busted.lua | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 0705ea0c..8c20f908 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -81,42 +81,37 @@ local call_inner = function(desc, func) return ok, msg, desc_stack end -local color_table = { - yellow = 33, - green = 32, - red = 31, +local ansi_color_table = { + purple = 35, + yellow = 33, + green = 32, + red = 31, } local color_string = function(color, str) if not is_headless then + -- This is never being called return str end return string.format("%s[%sm%s%s[%sm", string.char(27), - color_table[color] or 0, + ansi_color_table[color] or 0, str, string.char(27), 0 ) end -local SUCCESS = color_string("green", "Success") -local FAIL = color_string("red", "Fail") -local PENDING = color_string("yellow", "Pending") - local HEADER = string.rep("=", 40) -mod.format_results = function(res) - local num_pass = #res.pass - local num_fail = #res.fail - local num_errs = #res.errs +mod.format_results = function(result) + + local num_pass = color_string("green", #result.pass) + local num_fail = color_string("red", #result.fail) + local num_errs = color_string("purple", #result.errs) - print("") - print(color_string("green", "Success: "), num_pass) - print(color_string("red", "Failed : "), num_fail) - print(color_string("red", "Errors : "), num_errs) - print(HEADER) + print(string.format(" %s successes / %s failures / %s errors", num_pass, num_fail, num_errs)) end mod.describe = function(desc, func) From 03bf6b7a807c2ceeeac39bcd4319a3751abe277f Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Sat, 20 Feb 2021 20:14:47 +0100 Subject: [PATCH 04/17] Changes to visual output --- lua/plenary/busted.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 8c20f908..a527dc26 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -103,7 +103,11 @@ local color_string = function(color, str) ) end -local HEADER = string.rep("=", 40) +local SUCCESS = color_string("green", "Success") +local FAIL = color_string("red", "Failure") +local PENDING = color_string("yellow", "Pending") + +local HORIZONTALRULER = string.rep("─", 80) mod.format_results = function(result) @@ -119,8 +123,8 @@ mod.describe = function(desc, func) results.fail = {} results.errs = {} - print("\n" .. HEADER) - print("Testing: ", debug.getinfo(2, 'Sl').source) + print("\n" .. HORIZONTALRULER .."\n ") + -- print("Testing: ", debug.getinfo(2, 'Sl').source) describe = mod.inner_describe local ok, msg = call_inner(desc, func) @@ -205,7 +209,8 @@ mod.it = function(desc, func) to_insert = results.fail test_result.msg = msg - print(FAIL, "||", table.concat(test_result.descriptions, " ")) + print(FAIL, " → ", "spec/foo/bar_spec.lua @ 7") + print(table.concat(test_result.descriptions, "\n")) print(indent(msg, 12)) else to_insert = results.pass @@ -236,10 +241,10 @@ mod.run = function(file) local ok, msg = pcall(dofile, file) if not ok then - print(HEADER) + print(HORIZONTALRULER) print("FAILED TO LOAD FILE") print(color_string("red", msg)) - print(HEADER) + print(HORIZONTALRULER) os.exit(2) end From f4d7dcc348417885843cd782a784758f2614c29e Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Sat, 20 Feb 2021 20:16:18 +0100 Subject: [PATCH 05/17] Add file --- lua/plenary/bustin.lua | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lua/plenary/bustin.lua diff --git a/lua/plenary/bustin.lua b/lua/plenary/bustin.lua new file mode 100644 index 00000000..5fff784b --- /dev/null +++ b/lua/plenary/bustin.lua @@ -0,0 +1,38 @@ +-- ✱◼●●●●●●●●●●●●●●● +-- 15 successes / 1 failure / 1 error / 0 pending : 0.022516 seconds + +-- Failure → spec/dotnet/foo_spec.lua @ 7 +-- Extract and return the properties of a test project from a 'project block' (as found in a .NET solution file): +-- get_project_path() : Should return the path of a Csharp project +-- spec/dotnet/foo_spec.lua:13: (number) 2 +-- Expected objects to be equal. +-- Passed in: +-- (string) 'TestProject\TestProject.csproj' +-- Expected: +-- (string) 'TestProject\oooTestProject.csproj' + +-- Error → spec/error_spec.lua:2: syntax error near +-- spec/error_spec.lua + + +-- == Spec Result Table =========================== +-- Status: +-- Fail, pending, success, error +-- Testfile/dir: +-- spec/dotnet/foo_spec.lua +-- Line number: +-- @ 7 +-- Description: +-- Extract and return the properties of a test project +-- get_project_path() : Should return the path of a Csharp project +-- Message: +-- Expected objects to be equal. +-- Passed in: +-- (string) 'TestProject\TestProject.csproj' +-- Expected: +-- (string) 'TestProject\oooTestProject.csproj' +-- Stack Trace: + +local M = {} + +return M From 629cbe193bd6937f88acc9c68bb782a77e9a2798 Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Sun, 21 Feb 2021 17:23:53 +0100 Subject: [PATCH 06/17] Refactor path names --- lua/plenary/test_harness.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 7d511238..13e37f8e 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -61,18 +61,18 @@ function harness.test_directory(directory, opts) local outputter = headless and print_output or nvim_output local paths = harness._find_files_to_run(directory) - for _, p in ipairs(paths) do - outputter(res.bufnr, "Scheduling: " .. p.filename) + for _, path in ipairs(paths) do + outputter(res.bufnr, "Scheduling: " .. path.filename) end local path_len = #paths local jobs = f.map( - function(p) + function(path) local args = { '--headless', '-c', - string.format('lua require("plenary.busted").run("%s")', p:absolute()) + string.format('lua require("plenary.busted").run("%s")', path:absolute()) } if opts.minimal_init ~= nil then @@ -152,11 +152,11 @@ function harness._run_path(test_type, directory) local bufnr = 0 local win_id = 0 - for _, p in pairs(paths) do + for _, path in pairs(paths) do print(" ") - print("Loading Tests For: ", p:absolute(), "\n") + print("Loading Tests For: ", path:absolute(), "\n") - local ok, _ = pcall(function() dofile(p:absolute()) end) + local ok, _ = pcall(function() dofile(path:absolute()) end) if not ok then print("Failed to load file") From 0fb0709179d5c34e3ebed0b6d555631ea22901ff Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Sun, 21 Feb 2021 17:25:02 +0100 Subject: [PATCH 07/17] wip --- lua/plenary/bustin.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lua/plenary/bustin.lua b/lua/plenary/bustin.lua index 5fff784b..b0332647 100644 --- a/lua/plenary/bustin.lua +++ b/lua/plenary/bustin.lua @@ -23,7 +23,7 @@ -- Line number: -- @ 7 -- Description: --- Extract and return the properties of a test project +-- Extract and return the properties of a test project -- get_project_path() : Should return the path of a Csharp project -- Message: -- Expected objects to be equal. @@ -35,4 +35,7 @@ local M = {} +M.run = function(file) + +end return M From 598ce0aa0a4131b1e6b715e8c3a688fff28fc2cc Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Mon, 22 Feb 2021 18:58:27 +0100 Subject: [PATCH 08/17] Add some more eye candy --- lua/plenary/busted.lua | 45 +++++++++++++++++++++--------------- lua/plenary/job.lua | 1 + lua/plenary/test_harness.lua | 6 ++--- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index a527dc26..f79be672 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -70,10 +70,9 @@ local call_inner = function(desc, func) local desc_stack = add_description(desc) add_new_each() local ok, msg = xpcall(func, function(msg) - -- debug.traceback - -- return vim.inspect(get_trace(nil, 3, msg)) local trace = get_trace(nil, 3, msg) - return trace.message .. "\n" .. trace.traceback + -- return trace.message .. "\n" .. trace.traceback + return trace.message end) clear_last_each() pop_description() @@ -82,6 +81,7 @@ local call_inner = function(desc, func) end local ansi_color_table = { + cyan = 36, purple = 35, yellow = 33, green = 32, @@ -89,20 +89,27 @@ local ansi_color_table = { } local color_string = function(color, str) - if not is_headless then - -- This is never being called - return str - end - - return string.format("%s[%sm%s%s[%sm", - string.char(27), - ansi_color_table[color] or 0, - str, - string.char(27), + if not is_headless then + -- This is never being called + return str + end + + return string.format("%s[%sm%s%s[%sm", + string.char(27), + ansi_color_table[color] or 0, + str, + string.char(27), 0 ) end +local bold_string = function(str) + local ansi_bold = "\027[1m" + local ansi_clear = "\027[0m" + + return ansi_bold .. str .. ansi_clear +end + local SUCCESS = color_string("green", "Success") local FAIL = color_string("red", "Failure") local PENDING = color_string("yellow", "Pending") @@ -203,18 +210,18 @@ mod.it = function(desc, func) -- TODO: We should figure out how to determine whether -- and assert failed or whether it was an error... - local to_insert, printed if not ok then to_insert = results.fail test_result.msg = msg - print(FAIL, " → ", "spec/foo/bar_spec.lua @ 7") - print(table.concat(test_result.descriptions, "\n")) - print(indent(msg, 12)) + print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7")) + print(bold_string(table.concat(test_result.descriptions, "\n"))) + print(indent("\n" .. msg, 7)) else - to_insert = results.pass - print(SUCCESS, "||", table.concat(test_result.descriptions, " ")) + -- No need to show passing tests + -- to_insert = results.pass + -- print(SUCCESS, "||", table.concat(test_result.descriptions, " ")) end table.insert(to_insert, test_result) diff --git a/lua/plenary/job.lua b/lua/plenary/job.lua index 27e5f00e..107c350b 100644 --- a/lua/plenary/job.lua +++ b/lua/plenary/job.lua @@ -67,6 +67,7 @@ end ---@field on_exit function : (self, code: number, signal: number) ---@field maximum_results number : stop processing results after this number ---@field writer Job|table|string : Job that writes to stdin of this job. + function Job:new(o) if not o then error(debug.traceback("Options are required for Job:new")) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 13e37f8e..e2117b20 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -9,7 +9,7 @@ local headless = require("plenary.nvim_meta").is_headless local harness = {} -local print_output = vim.schedule_wrap(function(_, ...) +local cli_output = vim.schedule_wrap(function(_, ...) for _, v in ipairs({...}) do io.stdout:write(tostring(v)) io.stdout:write("\n") @@ -38,7 +38,7 @@ function harness.test_directory_command(command) end function harness.test_directory(directory, opts) - print("Starting...") + print("Starting...\n") opts = vim.tbl_deep_extend('force', {winopts = {winblend = 3}}, opts or {}) local res = {} @@ -58,7 +58,7 @@ function harness.test_directory(directory, opts) vim.cmd('mode') end - local outputter = headless and print_output or nvim_output + local outputter = headless and cli_output or nvim_output local paths = harness._find_files_to_run(directory) for _, path in ipairs(paths) do From 416dffe66b2f06d5d1ea765cc797d08a1da56cd8 Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Tue, 23 Feb 2021 19:09:33 +0100 Subject: [PATCH 09/17] wip - Add filename and fail/error line in the test output header --- lua/plenary/busted.lua | 90 +++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index f79be672..260afba8 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -2,32 +2,65 @@ local dirname = function(p) return vim.fn.fnamemodify(p, ":h") end -local function get_trace(element, level, msg) - local function trimTrace(info) - local index = info.traceback:find('\n%s*%[C]') - info.traceback = info.traceback:sub(1, index) - return info - end - level = level or 3 - - local thisdir = dirname(debug.getinfo(1, 'Sl').source, ":h") - local info = debug.getinfo(level, 'Sl') - while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or - (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do - level = level + 1 - info = debug.getinfo(level, 'Sl') - end +-- local function get_trace(element, level, msg) +-- local function trimTrace(info) +-- -- print("info : " .. info.traceback) +-- -- local index = info.traceback:find('\n%s*%[C]') +-- local start_index = info.traceback:find('/') +-- local end_index = info.traceback:find(': in') +-- print("start : " .. start_index .. " index: " .. end_index) +-- info.traceback = info.traceback:sub(start_index, end_index) +-- print(info.traceback) +-- return info +-- end +-- level = level or 3 + +-- local thisdir = dirname(debug.getinfo(1, 'Sl').source, ":h") +-- local info = debug.getinfo(level, 'Sl') +-- while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or +-- (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do +-- level = level + 1 +-- info = debug.getinfo(level, 'Sl') +-- end + +-- info.traceback = debug.traceback('', level) +-- info.message = msg + +-- -- local file = busted.getFile(element) +-- -- local file = false +-- local file = false +-- -- return file and file.getTrace(file.name, info) or trimTrace(info) +-- return trimTrace(info) +-- end + +local function get_file_and_line_number(msg) + + local function trimTrace(info) + local start_index = info.traceback:find('/') + local end_index = info.traceback:find(': in') + print("start : " .. start_index .. " index: " .. end_index) + info.traceback = info.traceback:sub(start_index, end_index) + print(info.traceback) + return info + end + level = level or 3 + + local thisdir = dirname(debug.getinfo(1, 'Sl').source, ":h") + local info = debug.getinfo(level, 'Sl') + while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or + (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do + level = level + 1 + info = debug.getinfo(level, 'Sl') + end - info.traceback = debug.traceback('', level) - info.message = msg + info.traceback = debug.traceback('', level) + info.message = msg - -- local file = busted.getFile(element) - local file = false - return file and file.getTrace(file.name, info) or trimTrace(info) + return trimTrace(info) end - - +--[[ is_headless is always true +-- running in nvim or in terminal --]] local is_headless = require('plenary.nvim_meta').is_headless local print = function(...) @@ -70,8 +103,8 @@ local call_inner = function(desc, func) local desc_stack = add_description(desc) add_new_each() local ok, msg = xpcall(func, function(msg) - local trace = get_trace(nil, 3, msg) - -- return trace.message .. "\n" .. trace.traceback + -- local trace = get_trace(nil, 3, msg) + -- -- return trace.message .. "\n" .. trace.traceback return trace.message end) clear_last_each() @@ -110,7 +143,7 @@ local bold_string = function(str) return ansi_bold .. str .. ansi_clear end -local SUCCESS = color_string("green", "Success") +-- local SUCCESS = color_string("green", "Success") local FAIL = color_string("red", "Failure") local PENDING = color_string("yellow", "Pending") @@ -215,8 +248,11 @@ mod.it = function(desc, func) to_insert = results.fail test_result.msg = msg - print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7")) - print(bold_string(table.concat(test_result.descriptions, "\n"))) +-- print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7") .. "\n") + +local filename = get_file_and_line_number() + print(FAIL, " → " .. color_string("cyan", filename.traceback) .. "\n") + print(bold_string(table.concat(test_result.descriptions))) print(indent("\n" .. msg, 7)) else -- No need to show passing tests From e13cd174ad3c9ed8504b2f2954386dd76603b5ab Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Fri, 26 Feb 2021 12:35:40 +0100 Subject: [PATCH 10/17] Wip - Dump stdout lines into a test_result table, for better filtering --- lua/plenary/busted.lua | 106 ++++++++++++++++++---------------- lua/plenary/bustin.lua | 109 ++++++++++++++++++++++------------- lua/plenary/test_harness.lua | 69 ++++++++++++++++------ 3 files changed, 177 insertions(+), 107 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 260afba8..8d2c9e84 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -2,50 +2,19 @@ local dirname = function(p) return vim.fn.fnamemodify(p, ":h") end --- local function get_trace(element, level, msg) --- local function trimTrace(info) --- -- print("info : " .. info.traceback) --- -- local index = info.traceback:find('\n%s*%[C]') --- local start_index = info.traceback:find('/') --- local end_index = info.traceback:find(': in') --- print("start : " .. start_index .. " index: " .. end_index) --- info.traceback = info.traceback:sub(start_index, end_index) --- print(info.traceback) --- return info --- end --- level = level or 3 - --- local thisdir = dirname(debug.getinfo(1, 'Sl').source, ":h") --- local info = debug.getinfo(level, 'Sl') --- while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or --- (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do --- level = level + 1 --- info = debug.getinfo(level, 'Sl') --- end - --- info.traceback = debug.traceback('', level) --- info.message = msg - --- -- local file = busted.getFile(element) --- -- local file = false --- local file = false --- -- return file and file.getTrace(file.name, info) or trimTrace(info) --- return trimTrace(info) --- end - -local function get_file_and_line_number(msg) +local function get_trace(element, level, msg) local function trimTrace(info) local start_index = info.traceback:find('/') local end_index = info.traceback:find(': in') - print("start : " .. start_index .. " index: " .. end_index) info.traceback = info.traceback:sub(start_index, end_index) - print(info.traceback) + return info end + level = level or 3 - local thisdir = dirname(debug.getinfo(1, 'Sl').source, ":h") + local thisdir = dirname(debug.getinfo(1, 'Sl').source) local info = debug.getinfo(level, 'Sl') while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do @@ -56,9 +25,43 @@ local function get_file_and_line_number(msg) info.traceback = debug.traceback('', level) info.message = msg + -- local file = busted.getFile(element) + -- local file = false + -- local file = false + -- return file and file.getTrace(file.name, info) or trimTrace(info) return trimTrace(info) end +local function get_file_and_line_number() + + local function trimTrace(trace) + local start_index = trace:find('/') + local end_index = trace:find(': in') + trace = trace:sub(start_index, end_index) + + local split_str = vim.split(trace, ':') + local spec = {} + spec.file = split_str[1] + spec.linenumber = split_str[2] + + return spec + end + + local level = 3 + + local thisdir = dirname(debug.getinfo(1, 'Sl').source) + local info = debug.getinfo(level, 'Sl') + while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or + (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do + level = level + 1 + info = debug.getinfo(level, 'Sl') + end + + local trace = debug.traceback('', level) + + return trimTrace(trace) +end + --[[ is_headless is always true -- running in nvim or in terminal --]] local is_headless = require('plenary.nvim_meta').is_headless @@ -103,8 +106,8 @@ local call_inner = function(desc, func) local desc_stack = add_description(desc) add_new_each() local ok, msg = xpcall(func, function(msg) - -- local trace = get_trace(nil, 3, msg) - -- -- return trace.message .. "\n" .. trace.traceback + local trace = get_trace(nil, 3, msg) + -- return trace.message .. "\n" .. trace.traceback return trace.message end) clear_last_each() @@ -115,7 +118,7 @@ end local ansi_color_table = { cyan = 36, - purple = 35, + magenta = 35, yellow = 33, green = 32, red = 31, @@ -153,7 +156,7 @@ mod.format_results = function(result) local num_pass = color_string("green", #result.pass) local num_fail = color_string("red", #result.fail) - local num_errs = color_string("purple", #result.errs) + local num_errs = color_string("magenta", #result.errs) print(string.format(" %s successes / %s failures / %s errors", num_pass, num_fail, num_errs)) end @@ -245,19 +248,24 @@ mod.it = function(desc, func) -- and assert failed or whether it was an error... local to_insert, printed if not ok then - to_insert = results.fail - test_result.msg = msg + to_insert = results.fail + test_result.msg = msg + + -- print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7") .. "\n") + + local spec = get_file_and_line_number() + print("[STATUS: FAIL]") + print(FAIL, " → " .. color_string("cyan", spec.file) .. " @ " .. color_string("cyan", spec.linenumber) .. "\n") + print(bold_string(table.concat(test_result.descriptions))) --- print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7") .. "\n") + print("[MSG]") + print(indent("\n" .. msg, 7)) -local filename = get_file_and_line_number() - print(FAIL, " → " .. color_string("cyan", filename.traceback) .. "\n") - print(bold_string(table.concat(test_result.descriptions))) - print(indent("\n" .. msg, 7)) + print("[DOT]") else - -- No need to show passing tests - -- to_insert = results.pass - -- print(SUCCESS, "||", table.concat(test_result.descriptions, " ")) + print("[SUCCESS]") + print(SUCCESS, "||", table.concat(test_result.descriptions, " ")) + print("[DOT]") end table.insert(to_insert, test_result) diff --git a/lua/plenary/bustin.lua b/lua/plenary/bustin.lua index b0332647..0aff95cf 100644 --- a/lua/plenary/bustin.lua +++ b/lua/plenary/bustin.lua @@ -1,41 +1,72 @@ --- ✱◼●●●●●●●●●●●●●●● --- 15 successes / 1 failure / 1 error / 0 pending : 0.022516 seconds - --- Failure → spec/dotnet/foo_spec.lua @ 7 --- Extract and return the properties of a test project from a 'project block' (as found in a .NET solution file): --- get_project_path() : Should return the path of a Csharp project --- spec/dotnet/foo_spec.lua:13: (number) 2 --- Expected objects to be equal. --- Passed in: --- (string) 'TestProject\TestProject.csproj' --- Expected: --- (string) 'TestProject\oooTestProject.csproj' - --- Error → spec/error_spec.lua:2: syntax error near --- spec/error_spec.lua - - --- == Spec Result Table =========================== --- Status: --- Fail, pending, success, error --- Testfile/dir: --- spec/dotnet/foo_spec.lua --- Line number: --- @ 7 --- Description: --- Extract and return the properties of a test project --- get_project_path() : Should return the path of a Csharp project --- Message: --- Expected objects to be equal. --- Passed in: --- (string) 'TestProject\TestProject.csproj' --- Expected: --- (string) 'TestProject\oooTestProject.csproj' --- Stack Trace: - -local M = {} - -M.run = function(file) +local ansi_color_table = { + cyan = 36, + magenta = 35, + yellow = 33, + green = 32, + red = 31, +} +local color_string = function(color, str) + if not is_headless then + -- This is never being called + return str + end + + return string.format("%s[%sm%s%s[%sm", + string.char(27), + ansi_color_table[color] or 0, + str, + string.char(27), + 0 + ) end -return M + +local successDot = color_string('green', '●') +local failureDot = color_string('red', '◼') +local errorDot = color_string('magenta', '✱') +local pendingDot = color_string('yellow', '◌') + +local count = { + successesCount = 0, + pendingsCount = 0, + failuresCount = 0, + errorsCount = 0, +} + +local aggregate_dots = function(countresults, dotcolor) + for _,_ in pairs(count) do + + end + for i=0, countresults, 1 do + result_dots = result_dots .. dotcolor + end +end +local dots_builder = function() + + local result_dots = "" + for i=0, count.errors, 1 do + result_dots = result_dots .. errorDot + end + + for i=0, count.failures, 1 do + result_dots = result_dots .. failureDot + end + + for i=0, count.successes, 1 do + result_dots = result_dots .. successDot + end + + for i=0, count.pending, 1 do + result_dots = result_dots .. pendingDot + end + + return result_dots +end + +describe("Build String", function() + it("title", function() + local expected = "" + assert.is_equal(expected, aggregate_dots(3, successDot)) + end) +end) + diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index e2117b20..6d7bb40e 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -9,13 +9,32 @@ local headless = require("plenary.nvim_meta").is_headless local harness = {} -local cli_output = vim.schedule_wrap(function(_, ...) - for _, v in ipairs({...}) do - io.stdout:write(tostring(v)) - io.stdout:write("\n") - end - - vim.cmd [[mode]] +-- local tty_output = vim.schedule_wrap(function(_, ...) +-- for _, v in ipairs({...}) do +-- io.stdout:write(tostring(v)) +-- io.stdout:write("\n") +-- end + +-- vim.cmd [[mode]] +-- end) + +local test_res = {} + +local tty_output = vim.schedule_wrap(function(_, ...) + local res = {} + for _, v in ipairs({...}) do + local line = v + if string.match(line, 'Failure') then + -- print(line .. "\n") + -- io.stdout:write(line, "\n") + -- table.insert(res, line) + res.status = line + end + -- print("ToString cli_output : " .. v) + -- io.stdout:write("\n") + end + table.insert(test_res, res) + vim.cmd [[mode]] end) local nvim_output = vim.schedule_wrap(function(bufnr, ...) @@ -58,21 +77,22 @@ function harness.test_directory(directory, opts) vim.cmd('mode') end - local outputter = headless and cli_output or nvim_output + local outputter = headless and tty_output or nvim_output local paths = harness._find_files_to_run(directory) - for _, path in ipairs(paths) do - outputter(res.bufnr, "Scheduling: " .. path.filename) + for _, p in ipairs(paths) do + outputter(res.bufnr, "Scheduling: " .. p.filename) end + local path_len = #paths local jobs = f.map( - function(path) + function(p) local args = { '--headless', '-c', - string.format('lua require("plenary.busted").run("%s")', path:absolute()) + string.format('lua require("plenary.busted").run("%s")', p:absolute()) } if opts.minimal_init ~= nil then @@ -100,10 +120,10 @@ function harness.test_directory(directory, opts) end, on_exit = vim.schedule_wrap(function(j_self, _, _) - if path_len ~= 1 then - outputter(res.bufnr, unpack(j_self:stderr_result())) - outputter(res.bufnr, unpack(j_self:result())) - end + if path_len ~= 1 then + outputter(res.bufnr, unpack(j_self:stderr_result())) + outputter(res.bufnr, unpack(j_self:result())) + end vim.cmd('mode') end) @@ -128,6 +148,17 @@ function harness.test_directory(directory, opts) vim.wait(100) log.debug("Done...") + print("Table.len... " .. #test_res) + print("Result... " .. tostring(test_res)) + -- print("key: " .. test_res[2]) + + for _,res in pairs(test_res) do + -- io.stdout:write("Write: ", tostring(res[1]), " \n") + io.stdout:write("Write: ", tostring(res.status), " \n") + if res[1] ~= nil then + end + end + if headless then if f.any(function(_, v) return v.code ~= 0 end, jobs) then os.exit(1) @@ -152,11 +183,11 @@ function harness._run_path(test_type, directory) local bufnr = 0 local win_id = 0 - for _, path in pairs(paths) do + for _, p in pairs(paths) do print(" ") - print("Loading Tests For: ", path:absolute(), "\n") + print("Loading Tests For: ", p:absolute(), "\n") - local ok, _ = pcall(function() dofile(path:absolute()) end) + local ok, _ = pcall(function() dofile(p:absolute()) end) if not ok then print("Failed to load file") From a7393b9c29f62012d7969dc9a9625641273b0a3c Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Sat, 27 Feb 2021 09:39:45 +0100 Subject: [PATCH 11/17] Wip --- lua/plenary/busted.lua | 8 ++--- lua/plenary/test_harness.lua | 58 +++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 8d2c9e84..7d94d60c 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -254,18 +254,16 @@ mod.it = function(desc, func) -- print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7") .. "\n") local spec = get_file_and_line_number() - print("[STATUS: FAIL]") + print("{STATUS: FAIL}") print(FAIL, " → " .. color_string("cyan", spec.file) .. " @ " .. color_string("cyan", spec.linenumber) .. "\n") print(bold_string(table.concat(test_result.descriptions))) - print("[MSG]") + print("{MSG}") print(indent("\n" .. msg, 7)) - print("[DOT]") else - print("[SUCCESS]") + print("{STATUS: SUCCESS}") print(SUCCESS, "||", table.concat(test_result.descriptions, " ")) - print("[DOT]") end table.insert(to_insert, test_result) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 6d7bb40e..a874329a 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -19,21 +19,57 @@ local harness = {} -- end) local test_res = {} - +local res = {} local tty_output = vim.schedule_wrap(function(_, ...) - local res = {} - for _, v in ipairs({...}) do - local line = v - if string.match(line, 'Failure') then - -- print(line .. "\n") - -- io.stdout:write(line, "\n") - -- table.insert(res, line) - res.status = line + + local ismsg = false + local msgcount = 0 + + for _, line in ipairs({...}) do + + local clear_results = function() + res = { + status = nil, + header = nil, + message = nil, + } + end + + if string.match(line, '{STATUS: SUCCESS}') then + clear_results() + res.status = 'success' + elseif string.match(line, '{STATUS: ERROR}') then + clear_results() + res.status = 'error' + elseif string.match(line, '{STATUS: PENDING}') then + clear_results() + res.status = 'pending' + elseif string.match(line, '{STATUS: FAIL}') then + clear_results() + res.status = 'fail' + elseif string.match(line, '{MSG}') or ismsg then + if msgcount == 0 then + ismsg = true + res.message = "" + end + msgcount = msgcount + 1 + if msgcount > 1 then + local msg = res.message + res.message = msg .. line + print("RESMESSAGE: " .. res.message) + io.write("RESMESSAGE: " .. res.message) + end end - -- print("ToString cli_output : " .. v) - -- io.stdout:write("\n") + + -- print("line: " .. tostring(line)) + print("status : " .. tostring(res.status)) + + end table.insert(test_res, res) + + -- print("ToString cli_output : " .. v) + -- io.stdout:write("\n") vim.cmd [[mode]] end) From df605c319f2b5e689b294ea71e8360ec3f2b6cb5 Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Mon, 1 Mar 2021 17:21:25 +0100 Subject: [PATCH 12/17] Refactor --- lua/plenary/busted.lua | 158 +++++++++++++++++----------------- lua/plenary/busted_reader.lua | 49 +++++++++++ lua/plenary/test_harness.lua | 126 ++++++++++++++++----------- 3 files changed, 205 insertions(+), 128 deletions(-) create mode 100644 lua/plenary/busted_reader.lua diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 7d94d60c..62575b4a 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -4,62 +4,62 @@ end local function get_trace(element, level, msg) - local function trimTrace(info) - local start_index = info.traceback:find('/') - local end_index = info.traceback:find(': in') - info.traceback = info.traceback:sub(start_index, end_index) - - return info - end - - level = level or 3 - - local thisdir = dirname(debug.getinfo(1, 'Sl').source) - local info = debug.getinfo(level, 'Sl') - while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or - (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do - level = level + 1 - info = debug.getinfo(level, 'Sl') - end - - info.traceback = debug.traceback('', level) - info.message = msg - - -- local file = busted.getFile(element) - -- local file = false - -- local file = false - -- return file and file.getTrace(file.name, info) or trimTrace(info) - return trimTrace(info) + local function trimTrace(info) + local start_index = info.traceback:find('/') + local end_index = info.traceback:find(': in') + info.traceback = info.traceback:sub(start_index, end_index) + + return info + end + + level = level or 3 + + local thisdir = dirname(debug.getinfo(1, 'Sl').source) + local info = debug.getinfo(level, 'Sl') + while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or + (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do + level = level + 1 + info = debug.getinfo(level, 'Sl') + end + + info.traceback = debug.traceback('', level) + info.message = msg + + -- local file = busted.getFile(element) + -- local file = false + -- local file = false + -- return file and file.getTrace(file.name, info) or trimTrace(info) + return trimTrace(info) end local function get_file_and_line_number() - local function trimTrace(trace) - local start_index = trace:find('/') - local end_index = trace:find(': in') - trace = trace:sub(start_index, end_index) + local function trimTrace(trace) + local start_index = trace:find('/') + local end_index = trace:find(': in') + trace = trace:sub(start_index, end_index) - local split_str = vim.split(trace, ':') - local spec = {} - spec.file = split_str[1] - spec.linenumber = split_str[2] + local split_str = vim.split(trace, ':') + local spec = {} + spec.file = split_str[1] + spec.linenumber = split_str[2] - return spec - end + return spec + end - local level = 3 + local level = 3 - local thisdir = dirname(debug.getinfo(1, 'Sl').source) - local info = debug.getinfo(level, 'Sl') - while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or - (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do - level = level + 1 - info = debug.getinfo(level, 'Sl') - end + local thisdir = dirname(debug.getinfo(1, 'Sl').source) + local info = debug.getinfo(level, 'Sl') + while info.what == 'C' or info.short_src:match('luassert[/\\].*%.lua$') or + (info.source:sub(1,1) == '@' and thisdir == dirname(info.source)) do + level = level + 1 + info = debug.getinfo(level, 'Sl') + end - local trace = debug.traceback('', level) + local trace = debug.traceback('', level) - return trimTrace(trace) + return trimTrace(trace) end --[[ is_headless is always true @@ -117,37 +117,38 @@ local call_inner = function(desc, func) end local ansi_color_table = { - cyan = 36, - magenta = 35, - yellow = 33, - green = 32, - red = 31, + cyan = 36, + magenta = 35, + yellow = 33, + green = 32, + red = 31, } local color_string = function(color, str) - if not is_headless then - -- This is never being called - return str - end - - return string.format("%s[%sm%s%s[%sm", - string.char(27), - ansi_color_table[color] or 0, - str, - string.char(27), - 0 + if not is_headless then + -- This is never being called + return str + end + + return string.format("%s[%sm%s%s[%sm", + string.char(27), + ansi_color_table[color] or 0, + str, + string.char(27), + 0 ) end local bold_string = function(str) - local ansi_bold = "\027[1m" - local ansi_clear = "\027[0m" + local ansi_bold = "\027[1m" + local ansi_clear = "\027[0m" - return ansi_bold .. str .. ansi_clear + return ansi_bold .. str .. ansi_clear end -- local SUCCESS = color_string("green", "Success") local FAIL = color_string("red", "Failure") +local SUCCESS = color_string("green", "Success") local PENDING = color_string("yellow", "Pending") local HORIZONTALRULER = string.rep("─", 80) @@ -166,7 +167,7 @@ mod.describe = function(desc, func) results.fail = {} results.errs = {} - print("\n" .. HORIZONTALRULER .."\n ") + print("\n" .. HORIZONTALRULER .."\n ") -- print("Testing: ", debug.getinfo(2, 'Sl').source) describe = mod.inner_describe @@ -248,22 +249,25 @@ mod.it = function(desc, func) -- and assert failed or whether it was an error... local to_insert, printed if not ok then - to_insert = results.fail - test_result.msg = msg + to_insert = results.fail + test_result.msg = msg + + -- print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7") .. "\n") + + print("{SPEC: FAIL}") + local spec = get_file_and_line_number() - -- print(FAIL, " → " .. color_string("cyan", "spec/foo/bar_spec.lua @ 7") .. "\n") + print(FAIL, " → " .. color_string("cyan", spec.file) .. " @ " .. color_string("cyan", spec.linenumber) .. "\n") - local spec = get_file_and_line_number() - print("{STATUS: FAIL}") - print(FAIL, " → " .. color_string("cyan", spec.file) .. " @ " .. color_string("cyan", spec.linenumber) .. "\n") - print(bold_string(table.concat(test_result.descriptions))) + print(bold_string(table.concat(test_result.descriptions))) + print(indent("\n" .. msg, 7)) - print("{MSG}") - print(indent("\n" .. msg, 7)) + print("{ENDOFSPEC}") else - print("{STATUS: SUCCESS}") - print(SUCCESS, "||", table.concat(test_result.descriptions, " ")) + print("{SPEC: SUCCESS}") + print(SUCCESS, " → ", table.concat(test_result.descriptions, " ")) + print("{ENDOFSPEC}") end table.insert(to_insert, test_result) diff --git a/lua/plenary/busted_reader.lua b/lua/plenary/busted_reader.lua new file mode 100644 index 00000000..f36c5a09 --- /dev/null +++ b/lua/plenary/busted_reader.lua @@ -0,0 +1,49 @@ +BustedOutputReader = {} + + local spec_results = {} + local current_spec = {} + + local function set_spec_status(line, find_str, status_str) + if line:find(find_str) then + current_spec.status = status_str + return true + end + end + + local is_spec_result + local cat_line + + local function reset() + current_spec, cat_line, is_spec_result = {}, nil, nil + end + + BustedOutputReader.output_to_table = function(...) + + for _, line in ipairs({...}) do + + if is_spec_result then + + if line:find('{ENDOFSPEC}') then + current_spec.content = cat_line + table.insert(spec_results, current_spec) + + reset() + else + if not cat_line then cat_line = "" end + cat_line = cat_line .. line + end + end + + if not is_spec_result then + is_spec_result = set_spec_status(line, '{SPEC: FAIL}', 'failed') or + set_spec_status(line, '{SPEC: ERROR}', 'error') or + set_spec_status(line, '{SPEC: SUCCESS}', 'success') or + set_spec_status(line, '{SPEC: PENDING}', 'pending') + end + end + + return spec_results +end + +return BustedOutputReader + diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index a874329a..3c5e817a 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -19,57 +19,84 @@ local harness = {} -- end) local test_res = {} -local res = {} -local tty_output = vim.schedule_wrap(function(_, ...) - - local ismsg = false - local msgcount = 0 - for _, line in ipairs({...}) do - - local clear_results = function() - res = { - status = nil, - header = nil, - message = nil, - } - end - - if string.match(line, '{STATUS: SUCCESS}') then - clear_results() - res.status = 'success' - elseif string.match(line, '{STATUS: ERROR}') then - clear_results() - res.status = 'error' - elseif string.match(line, '{STATUS: PENDING}') then - clear_results() - res.status = 'pending' - elseif string.match(line, '{STATUS: FAIL}') then - clear_results() - res.status = 'fail' - elseif string.match(line, '{MSG}') or ismsg then - if msgcount == 0 then - ismsg = true - res.message = "" - end - msgcount = msgcount + 1 - if msgcount > 1 then - local msg = res.message - res.message = msg .. line - print("RESMESSAGE: " .. res.message) - io.write("RESMESSAGE: " .. res.message) - end - end +local tty_output = vim.schedule_wrap(function(_, ...) - -- print("line: " .. tostring(line)) - print("status : " .. tostring(res.status)) + print("TTY_Output\n") + -- local res = {} + -- local is_msg + + -- for _, line in ipairs({...}) do + + -- -- local clear_results = function() + -- -- res = { + -- -- status = nil, + -- -- header = nil, + -- -- message = nil, + -- -- } + -- -- end + + -- io.stdout:write(tostring(line)) + -- io.stdout:write("\n") + -- -- if line:find('{STATUS: SUCCESS}') then + -- -- -- clear_results() + -- -- res.status = 'success' + -- -- end + -- -- if line:find('{STATUS: ERROR}') then + -- -- -- clear_results() + -- -- res.status = 'error' + -- -- end + -- -- if line:find('{STATUS: PENDING}') then + -- -- -- clear_results() + -- -- res.status = 'pending' + -- -- end + -- -- if line:find('{STATUS: FAIL}') then + -- -- res.status = 'fail' + -- -- print("Status: " .. tostring(res.status) .. "\n") + -- -- end + -- -- if line:find('{MSG}') or is_msg then + -- -- if not is_msg then + -- -- is_msg = true + -- -- res.message = "" + -- -- end + -- -- if line:find('{ENDMSG}') then + -- -- res.message = res.message:gsub('{MSG}', '') + -- -- print("Msg: " .. tostring(res.message) .. "\n") + -- -- is_msg = false + -- -- end + -- -- if is_msg then + -- -- local msg = res.message + -- -- res.message = msg .. line + -- -- end + -- -- end + -- -- if line:find('{ENDOFTEST}') then + -- -- table.insert(test_res, res) + -- -- res = nil + -- -- end + + -- -- print("line: " .. tostring(line)) + -- -- print("status : " .. tostring(res.status)) + + -- -- io.stdout:write("Status::::: ", tostring(res.status), " \n") + + -- -- io.stdout:write("MSG:::::::: ", tostring(res.message), " \n") + + -- end + + -- for _,v in pairs(res) do + -- print("Status: " .. tostring(v.status)) + -- print("Message: " .. tostring(v.message)) + -- -- io.stdout:write("Status: ", tostring(v.status), " \n") + -- -- io.stdout:write("MSG: ", tostring(v.message), " \n") + -- end - end - table.insert(test_res, res) -- print("ToString cli_output : " .. v) -- io.stdout:write("\n") + local read = require('plenary.busted_reader') + local results = read.output_to_table(...) + table.insert(test_res, results) vim.cmd [[mode]] end) @@ -184,15 +211,12 @@ function harness.test_directory(directory, opts) vim.wait(100) log.debug("Done...") - print("Table.len... " .. #test_res) - print("Result... " .. tostring(test_res)) - -- print("key: " .. test_res[2]) + print("Table.len... " .. #test_res .. "\n") - for _,res in pairs(test_res) do + for _, res in pairs(test_res) do -- io.stdout:write("Write: ", tostring(res[1]), " \n") - io.stdout:write("Write: ", tostring(res.status), " \n") - if res[1] ~= nil then - end + -- io.stdout:write("Write: ", tostring(res.status), " \n") + -- print("res table" .. tostring(res)) end if headless then From a99ba27ec2b5a02c7d5ac092efd96b9a7e32638c Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Tue, 2 Mar 2021 00:24:42 +0100 Subject: [PATCH 13/17] Add busted score... bullets and textual --- lua/plenary/busted_dots.lua | 64 +++++++++++++++++++++++++++ lua/plenary/busted_reader.lua | 4 +- lua/plenary/test_harness.lua | 83 +++-------------------------------- 3 files changed, 72 insertions(+), 79 deletions(-) create mode 100644 lua/plenary/busted_dots.lua diff --git a/lua/plenary/busted_dots.lua b/lua/plenary/busted_dots.lua new file mode 100644 index 00000000..5976e4ec --- /dev/null +++ b/lua/plenary/busted_dots.lua @@ -0,0 +1,64 @@ +local ansi_color_table = { + cyan = 36, + magenta = 35, + yellow = 33, + green = 32, + red = 31, +} + +local color_string = function(color, str) + return string.format("%s[%sm%s%s[%sm", + string.char(27), + ansi_color_table[color] or 0, + str, + string.char(27), + 0 + ) +end + +local successDot = color_string('green', '●') +local failureDot = color_string('red', '◼') +local errorDot = color_string('magenta', '✱') +local pendingDot = color_string('yellow', '◌') + +local function generate_dots(results, status_str, dot) + local dot_count = 0 + for _, spec in pairs(results) do + if spec.status == status_str then + io.stdout:write(dot) + dot_count = dot_count + 1 + end + end + return dot_count +end + +local function generate_score(n_succ, n_fail, n_err, n_pend) + + local success = n_succ == 1 and ' success' or ' successes' + local fail = n_fail == 1 and ' failure' or ' failures' + local error = n_err == 1 and ' error' or ' errors' + + local score = + color_string('green', n_succ) .. success .. ' /' .. + color_string('red', n_fail) .. fail .. ' /' .. + color_string('magenta', n_err) .. error .. ' /' .. + color_string('yellow', n_pend) .. ' pending' + + io.stdout:write(score) +end + +local Score = {} + +function Score.draw(results) + + local n_pend = generate_dots(results, 'pending', pendingDot) + local n_err = generate_dots(results, 'error', errorDot) + local n_fail = generate_dots(results, 'failed', failureDot) + local n_succ = generate_dots(results, 'success', successDot) + + io.stdout:write('\n') + generate_score(n_succ, n_fail, n_err, n_pend) + io.stdout:write('\n\n') +end + +return Score diff --git a/lua/plenary/busted_reader.lua b/lua/plenary/busted_reader.lua index f36c5a09..09b9f78a 100644 --- a/lua/plenary/busted_reader.lua +++ b/lua/plenary/busted_reader.lua @@ -19,7 +19,7 @@ BustedOutputReader = {} BustedOutputReader.output_to_table = function(...) - for _, line in ipairs({...}) do + for _, line in pairs({...}) do if is_spec_result then @@ -30,7 +30,7 @@ BustedOutputReader = {} reset() else if not cat_line then cat_line = "" end - cat_line = cat_line .. line + cat_line = cat_line .. line .. '\n' end end diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 3c5e817a..e6d7c29e 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -22,81 +22,9 @@ local test_res = {} local tty_output = vim.schedule_wrap(function(_, ...) - print("TTY_Output\n") - -- local res = {} - -- local is_msg - - -- for _, line in ipairs({...}) do - - -- -- local clear_results = function() - -- -- res = { - -- -- status = nil, - -- -- header = nil, - -- -- message = nil, - -- -- } - -- -- end - - -- io.stdout:write(tostring(line)) - -- io.stdout:write("\n") - -- -- if line:find('{STATUS: SUCCESS}') then - -- -- -- clear_results() - -- -- res.status = 'success' - -- -- end - -- -- if line:find('{STATUS: ERROR}') then - -- -- -- clear_results() - -- -- res.status = 'error' - -- -- end - -- -- if line:find('{STATUS: PENDING}') then - -- -- -- clear_results() - -- -- res.status = 'pending' - -- -- end - -- -- if line:find('{STATUS: FAIL}') then - -- -- res.status = 'fail' - -- -- print("Status: " .. tostring(res.status) .. "\n") - -- -- end - -- -- if line:find('{MSG}') or is_msg then - -- -- if not is_msg then - -- -- is_msg = true - -- -- res.message = "" - -- -- end - -- -- if line:find('{ENDMSG}') then - -- -- res.message = res.message:gsub('{MSG}', '') - -- -- print("Msg: " .. tostring(res.message) .. "\n") - -- -- is_msg = false - -- -- end - -- -- if is_msg then - -- -- local msg = res.message - -- -- res.message = msg .. line - -- -- end - -- -- end - -- -- if line:find('{ENDOFTEST}') then - -- -- table.insert(test_res, res) - -- -- res = nil - -- -- end - - -- -- print("line: " .. tostring(line)) - -- -- print("status : " .. tostring(res.status)) - - -- -- io.stdout:write("Status::::: ", tostring(res.status), " \n") - - -- -- io.stdout:write("MSG:::::::: ", tostring(res.message), " \n") - - -- end - - -- for _,v in pairs(res) do - -- print("Status: " .. tostring(v.status)) - -- print("Message: " .. tostring(v.message)) - -- -- io.stdout:write("Status: ", tostring(v.status), " \n") - -- -- io.stdout:write("MSG: ", tostring(v.message), " \n") - -- end - - - - -- print("ToString cli_output : " .. v) - -- io.stdout:write("\n") local read = require('plenary.busted_reader') - local results = read.output_to_table(...) - table.insert(test_res, results) + test_res = read.output_to_table(...) + vim.cmd [[mode]] end) @@ -211,11 +139,12 @@ function harness.test_directory(directory, opts) vim.wait(100) log.debug("Done...") - print("Table.len... " .. #test_res .. "\n") + local dots = require('plenary.busted_dots') + dots.draw(test_res) for _, res in pairs(test_res) do - -- io.stdout:write("Write: ", tostring(res[1]), " \n") - -- io.stdout:write("Write: ", tostring(res.status), " \n") + -- io.stdout:write(tostring(res.status), " \n") + io.stdout:write(res.content, " \n") -- print("res table" .. tostring(res)) end From f6befefaa66e6150484136167011cee5acaebe24 Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Tue, 2 Mar 2021 08:55:02 +0100 Subject: [PATCH 14/17] Refactor --- lua/plenary/test_harness.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index e6d7c29e..36f8ef8c 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -142,9 +142,9 @@ function harness.test_directory(directory, opts) local dots = require('plenary.busted_dots') dots.draw(test_res) - for _, res in pairs(test_res) do + for _, spec in pairs(test_res) do -- io.stdout:write(tostring(res.status), " \n") - io.stdout:write(res.content, " \n") + io.stdout:write(spec.content, " \n") -- print("res table" .. tostring(res)) end From 96dc3e0a678ba51d2b2f282e33eec694ced9e57c Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Tue, 2 Mar 2021 08:56:42 +0100 Subject: [PATCH 15/17] Add space between separators in score text --- lua/plenary/busted_dots.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/plenary/busted_dots.lua b/lua/plenary/busted_dots.lua index 5976e4ec..b4fba71f 100644 --- a/lua/plenary/busted_dots.lua +++ b/lua/plenary/busted_dots.lua @@ -39,9 +39,9 @@ local function generate_score(n_succ, n_fail, n_err, n_pend) local error = n_err == 1 and ' error' or ' errors' local score = - color_string('green', n_succ) .. success .. ' /' .. - color_string('red', n_fail) .. fail .. ' /' .. - color_string('magenta', n_err) .. error .. ' /' .. + color_string('green', n_succ) .. success .. ' / ' .. + color_string('red', n_fail) .. fail .. ' / ' .. + color_string('magenta', n_err) .. error .. ' / ' .. color_string('yellow', n_pend) .. ' pending' io.stdout:write(score) From 07cccdc5b9258878df893ddcf2868d87c0ed21ed Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Tue, 2 Mar 2021 09:55:12 +0100 Subject: [PATCH 16/17] Small changes to nvim output --- lua/plenary/bustin.lua | 72 ------------------------------------ lua/plenary/test_harness.lua | 10 +++-- 2 files changed, 7 insertions(+), 75 deletions(-) delete mode 100644 lua/plenary/bustin.lua diff --git a/lua/plenary/bustin.lua b/lua/plenary/bustin.lua deleted file mode 100644 index 0aff95cf..00000000 --- a/lua/plenary/bustin.lua +++ /dev/null @@ -1,72 +0,0 @@ -local ansi_color_table = { - cyan = 36, - magenta = 35, - yellow = 33, - green = 32, - red = 31, -} - -local color_string = function(color, str) - if not is_headless then - -- This is never being called - return str - end - - return string.format("%s[%sm%s%s[%sm", - string.char(27), - ansi_color_table[color] or 0, - str, - string.char(27), - 0 - ) -end - -local successDot = color_string('green', '●') -local failureDot = color_string('red', '◼') -local errorDot = color_string('magenta', '✱') -local pendingDot = color_string('yellow', '◌') - -local count = { - successesCount = 0, - pendingsCount = 0, - failuresCount = 0, - errorsCount = 0, -} - -local aggregate_dots = function(countresults, dotcolor) - for _,_ in pairs(count) do - - end - for i=0, countresults, 1 do - result_dots = result_dots .. dotcolor - end -end -local dots_builder = function() - - local result_dots = "" - for i=0, count.errors, 1 do - result_dots = result_dots .. errorDot - end - - for i=0, count.failures, 1 do - result_dots = result_dots .. failureDot - end - - for i=0, count.successes, 1 do - result_dots = result_dots .. successDot - end - - for i=0, count.pending, 1 do - result_dots = result_dots .. pendingDot - end - - return result_dots -end - -describe("Build String", function() - it("title", function() - local expected = "" - assert.is_equal(expected, aggregate_dots(3, successDot)) - end) -end) - diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index 36f8ef8c..9e77ba4a 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -34,6 +34,10 @@ local nvim_output = vim.schedule_wrap(function(bufnr, ...) end for _, v in ipairs({...}) do + + local skip = v:find('{SPEC:') or v:find('{ENDOFSPEC}') + if skip then return end + vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, {v}) end end) @@ -48,7 +52,7 @@ function harness.test_directory_command(command) end function harness.test_directory(directory, opts) - print("Starting...\n") + print("Start Busting...\n") opts = vim.tbl_deep_extend('force', {winopts = {winblend = 3}}, opts or {}) local res = {} @@ -72,10 +76,10 @@ function harness.test_directory(directory, opts) local paths = harness._find_files_to_run(directory) for _, p in ipairs(paths) do - outputter(res.bufnr, "Scheduling: " .. p.filename) + local headless_ctx = headless and 'Scheduling: ' or 'Current file: ' + outputter(res.bufnr, headless_ctx .. p.filename) end - local path_len = #paths local jobs = f.map( From adf05741e7efcd4301668eecc4621eda273d3bd8 Mon Sep 17 00:00:00 2001 From: Mathijs Bakker Date: Thu, 4 Mar 2021 10:18:30 +0100 Subject: [PATCH 17/17] Solve merge conflicts and fix 'output' path to be relative --- lua/plenary/busted.lua | 5 +++-- lua/plenary/test_harness.lua | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lua/plenary/busted.lua b/lua/plenary/busted.lua index 629b8dc5..11e75556 100644 --- a/lua/plenary/busted.lua +++ b/lua/plenary/busted.lua @@ -1,3 +1,5 @@ +local Path = require('plenary.path') + local dirname = function(p) return vim.fn.fnamemodify(p, ":h") end @@ -273,8 +275,7 @@ clear = mod.clear assert = require("luassert") mod.run = function(file) - print("\n" .. HEADER) - print("Testing: ", file) + -- print("Testing: ", file) local ok, msg = pcall(dofile, file) diff --git a/lua/plenary/test_harness.lua b/lua/plenary/test_harness.lua index b03ae477..df985bc1 100644 --- a/lua/plenary/test_harness.lua +++ b/lua/plenary/test_harness.lua @@ -76,8 +76,9 @@ function harness.test_directory(directory, opts) local paths = harness._find_files_to_run(directory) for _, p in ipairs(paths) do - local headless_ctx = headless and 'Scheduling: ' or 'Current file: ' - outputter(res.bufnr, headless_ctx .. p.filename) + local headless_ctx = headless and 'Scheduling: ' or 'Current: ' + local rel_path = Path.make_relative(p) + outputter(res.bufnr, headless_ctx .. rel_path) end local path_len = #paths