Skip to content

Commit

Permalink
(mini.test) Allow '\n' in names of test sets and cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
echasnovski committed Sep 24, 2023
1 parent 6ccd3f8 commit 323b54b
Show file tree
Hide file tree
Showing 9 changed files with 340 additions and 277 deletions.
4 changes: 2 additions & 2 deletions lua/mini/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ H.set_to_testcases = function(set, template, hooks_once)

local cur_template = H.extend_template(template, {
args = args,
desc = key,
desc = type(key) == 'string' and key:gsub('\n', '\\n') or key,
hooks = { pre = hooks.pre_case, post = hooks.post_case },
data = data,
})
Expand Down Expand Up @@ -2023,7 +2023,7 @@ H.buffer_reporter.set_lines = function(buf_id, lines, start, finish)
local new_lines, hl_ranges = {}, {}
for i, l in ipairs(lines) do
local n_removed = 0
local new_l = l:gsub('()(\27%[.-m)(.-)\27%[0m', function(...)
local new_l = l:gsub('\n', '\\n'):gsub('()(\27%[.-m)(.-)\27%[0m', function(...)
local dots = { ... }
local left = dots[1] - n_removed
table.insert(
Expand Down
3 changes: 3 additions & 0 deletions tests/dir-test/testref_reporters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ T['second group']['fail with notes'] = function()
MiniTest.add_note('Failed note #2')
error('Custom error after note #2', 0)
end

T['third group with \n in name'] = new_set()
T['third group with \n in name']['case with \n in name'] = function() MiniTest.add_note('Passed note #3') end
--stylua: ignore end

return T

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
--|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|---------|
01|Total number of cases: 8
01|Total number of cases: 9
02|Total number of groups: 1
03|
04|tests/dir-test/testref_reporters.lua: oOxXoOxX
04|tests/dir-test/testref_reporters.lua: oOxXoOxXO
05|
06|Fails (4) and Notes (4)
06|Fails (4) and Notes (5)
07|NOTE in tests/dir-test/testref_reporters.lua | first group | pass with notes: Passed note
08|
09|FAIL in tests/dir-test/testref_reporters.lua | first group | fail: Custom error
Expand All @@ -27,10 +27,10 @@
26| tests/dir-test/testref_reporters.lua:21
27|NOTE in tests/dir-test/testref_reporters.lua | second group | fail with notes: Failed note #2
28|
29|
30|[Process exited 1]
29|NOTE in tests/dir-test/testref_reporters.lua | third group with \n in name | case with \n in name: Passed note #3
30|
31|
32|
32|[Process exited 1]
33|
34|
35| 1,1 All
Expand All @@ -39,7 +39,7 @@
01|000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
02|000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
03|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
04|111111111111111111111111111111111111112233223311111111111111111111111111111111111111111111111111111111111111111111111111
04|111111111111111111111111111111111111112233223321111111111111111111111111111111111111111111111111111111111111111111111111
05|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
06|000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
07|222211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
Expand All @@ -64,10 +64,10 @@
26|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
27|333311111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
28|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
29|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
30|111111111111111111411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
29|222211111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
30|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
31|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
32|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
32|111111111111111111411111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
33|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
34|111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
35|444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
Loading

0 comments on commit 323b54b

Please sign in to comment.