-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handling multilines results with custom output handler
Lazily `require` JSON module in output handler We `require` the output handler in Neovim in order to get the full path to its source. This executes all top-level statements of the handler, including any `require` calls. If one of the required modules is not installed (in this case `dkjson`) an error is raised. The solution is to move the `require` call into the function call of the module. The module will not be called by Neovim, but by busted, and the dkjson module will be present in that context. Add commentary (motivation) to output handler Undo stylistic changes Shorten name of `output_handler_path` variable Makes it easier to read. Search for last result line containing the marker Rename marker variable The variable is already scoped to the output handler, so the name can be something short. Add tests which write to standard output These tests are meant to be run from within Neovim. Add test for when output contains result marker This is why it is important to search for the output marker backwards.
- Loading branch information
Showing
19 changed files
with
213 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
---This is a modified version of the standard JSON output handler from busted. | ||
---The main difference is that this handler inserts an explicit separator | ||
---before the JSON result output. The reason is that busted writes both the | ||
---standard output from tests and the result of running tests to standard | ||
---output, potentially mixing the two on the same line. | ||
|
||
local io_write = io.write | ||
local io_flush = io.flush | ||
|
||
local M = {} | ||
|
||
---Prefix to mark the line containing test results as opposed to the standard | ||
---output of the test | ||
M.marker = '::NEOTEST_LINE::' | ||
|
||
---Full path to this module so it can be referenced by Neovim. We have no | ||
---control over the working directory of the Neovim process, so the output | ||
---handler has to know its own absolute file path. Neovim can then require the | ||
---handler as a module and get this information. | ||
M.source = debug.getinfo(1).source:sub(2) | ||
|
||
function M:__call(_options) | ||
local json = require('dkjson') | ||
local busted = require('busted') | ||
local handler = require('busted.outputHandlers.base')() | ||
|
||
handler.suiteEnd = function() | ||
local error_info = { | ||
pendings = handler.pendings, | ||
successes = handler.successes, | ||
failures = handler.failures, | ||
errors = handler.errors, | ||
duration = handler.getDuration(), | ||
} | ||
local ok, result = pcall(json.encode, error_info) | ||
|
||
io_write('\n' .. M.marker) | ||
|
||
if ok then | ||
io_write(result) | ||
else | ||
io_write('Failed to encode test results to json: ' .. result) | ||
end | ||
|
||
io_write('\n') | ||
io_flush() | ||
|
||
return nil, true | ||
end | ||
|
||
busted.subscribe({ 'suite', 'end' }, handler.suiteEnd) | ||
|
||
return handler | ||
end | ||
|
||
return setmetatable(M, M) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.