Skip to content

Commit

Permalink
Fix json output (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergii4 authored Feb 24, 2024
1 parent 1757961 commit 6a2f996
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lua/neotest-go/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ function adapter.prepare_results(tree, lines, go_root, go_module)
}
file_id = value.id
else
local normalized_id = utils.normalize_id(value.id, go_root, go_module)
-- mitigates `value.id` such as jsonoutput_test.go::Test_Level_1::"Level 2"::Level_3'
local value_id = value.id:gsub('%"', ""):gsub(" ", "_")
local normalized_id = utils.normalize_id(value_id, go_root, go_module)
local test_result = tests[normalized_id]
-- file level node
if test_result then
Expand Down
3 changes: 1 addition & 2 deletions lua/neotest-go/output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ function M.marshal_gotest_output(lines)
-- if a new file and line number is present in the current line, use this info from now on
-- begin collection log data with everything after the file:linenumber
local new_test_file, new_line_number = utils.get_test_file_info(parsed.Output)
testfile, linenumber = new_test_file, new_line_number
if new_test_file and new_line_number then
testfile = new_test_file
linenumber = new_line_number
if not tests[testname].file_output[testfile] then
tests[testname].file_output[testfile] = {}
end
Expand Down
41 changes: 41 additions & 0 deletions lua/spec/neotest-go/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,47 @@ describe("prepare_results", function()
end
end
)

async.it("check that all nested results are in three_level_nested_test.go", function()
local tests_folder = vim.loop.cwd() .. "/neotest_go"
local test_file = tests_folder .. "/three_level_nested_test.go"
local positions = plugin.discover_positions(test_file)

local expected_keys = {
test_file,
test_file .. "::TestOdd",
test_file .. "::TestOdd::odd",
test_file .. '::TestOdd::"odd"::7_is_odd',
test_file .. '::TestOdd::"odd"::5_is_odd',
test_file .. '::TestOdd::"odd"::"5 is odd"::9_is_odd',
}
-- we should run test from module root
local command = {
"cd",
tests_folder,
"&&",
"go",
"test",
"-v",
"-json",
"",
"-count=1",
"-timeout=60s",
"./...",
}
local handle = io.popen(table.concat(command, " "))
local result = handle:read("*a")
handle:close()
local lines = {}
for s in result:gmatch("[^\r\n]+") do
table.insert(lines, s)
end
local processed_results = plugin.prepare_results(positions, lines, tests_folder, "neotest_go")
for _, v in pairs(expected_keys) do
assert.has_property(v, processed_results)
end
end)

async.it("check that we have correct file level test result status", function()
local tests_folder = vim.loop.cwd() .. "/neotest_go"
local test_cases = {}
Expand Down
25 changes: 25 additions & 0 deletions neotest_go/three_level_nested_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package main

import "testing"

func TestOdd(t *testing.T) {
t.Run("odd", func(t *testing.T) {
t.Run("5 is odd", func(t *testing.T) {
if 5%2 != 1 {
t.Error("5 is actually odd")
}
t.Run("9 is odd", func(t *testing.T) {
if 9%2 != 1 {
t.Error("5 is actually odd")
}
})
})
t.Run("7 is odd", func(t *testing.T) {
if 7%2 != 1 {
t.Error("7 is actually odd")
}
})

})

}

0 comments on commit 6a2f996

Please sign in to comment.