Skip to content

Commit 1bc720a

Browse files
authored
Remove quotes from nested tests names (nvim-neotest#76)
1 parent 1757961 commit 1bc720a

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

lua/neotest-go/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,22 @@ function adapter.prepare_results(tree, lines, go_root, go_module)
234234
}
235235
file_id = value.id
236236
else
237-
local normalized_id = utils.normalize_id(value.id, go_root, go_module)
237+
-- to remove quotes, for example three_level_nested_test.go::TestOdd::"odd"::5_is_odd
238+
local value_id = value.id:gsub('%"', "")
239+
local normalized_id = utils.normalize_id(value_id, go_root, go_module)
238240
local test_result = tests[normalized_id]
239241
-- file level node
240242
if test_result then
241243
local fname = async.fn.tempname()
242244
fn.writefile(test_result.output, fname)
243-
results[value.id] = {
245+
results[value_id] = {
244246
status = test_result.status,
245247
short = table.concat(test_result.output, ""),
246248
output = fname,
247249
}
248250
local errors = utils.get_errors_from_test(test_result, utils.get_filename_from_id(value.id))
249251
if errors then
250-
results[value.id].errors = errors
252+
results[value_id].errors = errors
251253
end
252254
if test_result.status == test_statuses.fail and file_id then
253255
results[file_id].status = test_statuses.fail

lua/spec/neotest-go/init_spec.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,51 @@ describe("prepare_results", function()
302302
end
303303
end
304304
)
305+
async.it(
306+
"check that all nested results are in three_level_nested_test.go, quotes should be removed from keys",
307+
-- three_level_nested_test.go::TestOdd::odd::5_is_odd
308+
-- not three_level_nested_test.go::TestOdd::"odd"::5_is_odd
309+
function()
310+
local tests_folder = vim.loop.cwd() .. "/neotest_go"
311+
local test_file = tests_folder .. "/three_level_nested_test.go"
312+
local positions = plugin.discover_positions(test_file)
313+
314+
local expected_keys = {
315+
test_file,
316+
test_file .. "::TestOdd",
317+
test_file .. "::TestOdd::odd",
318+
test_file .. "::TestOdd::odd::7_is_odd",
319+
test_file .. "::TestOdd::odd::5_is_odd",
320+
}
321+
-- we should run test from module root
322+
local command = {
323+
"cd",
324+
tests_folder,
325+
"&&",
326+
"go",
327+
"test",
328+
"-v",
329+
"-json",
330+
"",
331+
"-count=1",
332+
"-timeout=60s",
333+
"./...",
334+
}
335+
local handle = io.popen(table.concat(command, " "))
336+
local result = handle:read("*a")
337+
handle:close()
338+
339+
local lines = {}
340+
for s in result:gmatch("[^\r\n]+") do
341+
table.insert(lines, s)
342+
end
343+
local processed_results = plugin.prepare_results(positions, lines, tests_folder, "neotest_go")
344+
for _, v in pairs(expected_keys) do
345+
assert.has_property(v, processed_results)
346+
end
347+
end
348+
)
349+
305350
async.it("check that we have correct file level test result status", function()
306351
local tests_folder = vim.loop.cwd() .. "/neotest_go"
307352
local test_cases = {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import "testing"
4+
5+
func TestOdd(t *testing.T) {
6+
t.Run("odd", func(t *testing.T) {
7+
t.Run("5 is odd", func(t *testing.T) {
8+
if 5%2 != 1 {
9+
t.Error("5 is actually odd")
10+
}
11+
})
12+
t.Run("7 is odd", func(t *testing.T) {
13+
if 7%2 != 1 {
14+
t.Error("7 is actually odd")
15+
}
16+
})
17+
18+
})
19+
20+
}

0 commit comments

Comments
 (0)