Skip to content

Commit 70a38ab

Browse files
committed
chore: test for nested test, test commands
1 parent b955680 commit 70a38ab

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

lua/spec/neotest-go/init_spec.lua

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe("discover_positions", function()
134134
id = vim.loop.cwd() .. "/neotest_go/cases_test.go",
135135
name = "cases_test.go",
136136
path = vim.loop.cwd() .. "/neotest_go/cases_test.go",
137-
range = { 0, 0, 49, 0 },
137+
range = { 0, 0, 55, 0 },
138138
type = "file",
139139
},
140140
{
@@ -169,7 +169,7 @@ describe("discover_positions", function()
169169
id = vim.loop.cwd() .. "/neotest_go/cases_test.go::TestAdd",
170170
name = "TestAdd",
171171
path = vim.loop.cwd() .. "/neotest_go/cases_test.go",
172-
range = { 35, 0, 48, 1 },
172+
range = { 35, 0, 54, 1 },
173173
type = "test",
174174
},
175175
{
@@ -190,6 +190,24 @@ describe("discover_positions", function()
190190
type = "test",
191191
},
192192
},
193+
{
194+
{
195+
id = vim.loop.cwd() .. "/neotest_go/cases_test.go::TestAdd::test_three",
196+
name = '"test three"',
197+
path = vim.loop.cwd() .. "/neotest_go/cases_test.go",
198+
range = { 44, 1, 48, 3 },
199+
type = "test",
200+
},
201+
{
202+
{
203+
id = vim.loop.cwd() .. "/neotest_go/cases_test.go::TestAdd::\"test three\"::test_four",
204+
name = '"test four"',
205+
path = vim.loop.cwd() .. "/neotest_go/cases_test.go",
206+
range = { 45, 2, 47, 4 },
207+
type = "test",
208+
},
209+
},
210+
},
193211
},
194212
}
195213

@@ -334,7 +352,7 @@ describe("prepare_results", function()
334352
table.insert(lines, s)
335353
end
336354
local processed_results =
337-
plugin.prepare_results(positions, lines, tests_folder, "neotest_go")
355+
plugin.prepare_results(positions, lines, tests_folder, "neotest_go")
338356

339357
assert.equals(test_result.status, processed_results[test_file].status)
340358
end)
@@ -349,8 +367,8 @@ describe("build_spec", function()
349367

350368
local args = { tree = tree }
351369
local expected_command = "cd "
352-
.. vim.loop.cwd()
353-
.. "/neotest_go && go test -v -json -count=1 -timeout=60s ./"
370+
.. vim.loop.cwd()
371+
.. "/neotest_go && go test -v -json -count=1 -timeout=60s ./"
354372
local result = plugin.build_spec(args)
355373
assert.are.same(expected_command, result.command)
356374
assert.are.same(path, result.context.file)
@@ -361,23 +379,36 @@ describe("build_spec", function()
361379

362380
local args = { tree = tree }
363381
local expected_command = "cd "
364-
.. vim.loop.cwd()
365-
.. "/neotest_go && go test -v -json -count=1 -timeout=60s --run ^TestAddOne$ ./"
382+
.. vim.loop.cwd()
383+
.. "/neotest_go && go test -v -json -count=1 -timeout=60s -run ^TestAddOne$ ./"
366384
local result = plugin.build_spec(args)
367385
assert.are.same(expected_command, result.command)
368386
assert.are.same(path, result.context.file)
369387
end)
370388

371-
-- This test is overwriting plugin global state, keep it at end of the file or face the consequences ¯\_(ツ)_/¯
389+
async.it("build specification for single nested test", function()
390+
local path = vim.loop.cwd() .. "/neotest_go/cases_test.go"
391+
local tree = plugin.discover_positions(path)
392+
local test_tree = tree:children()[2]:children()[3]:children()[1]
393+
394+
local args = { tree = test_tree }
395+
local expected_command = "cd "
396+
.. vim.loop.cwd()
397+
.. "/neotest_go && go test -v -json -count=1 -timeout=60s -run ^TestAdd/test_three/test_four$ ./"
398+
local result = plugin.build_spec(args)
399+
assert.are.same(expected_command, result.command)
400+
assert.are.same(path, result.context.file)
401+
end)
402+
-- This test is overwriting plugin global state, keep it at end of the file or face the consequences ¯\_(ツ)_/¯
372403
async.it("build specification for many_table_test.go recuresive run", function()
373404
local plugin_with_recursive_run = require("neotest-go")({ recursive_run = true })
374405
local path = vim.loop.cwd() .. "/neotest_go/many_table_test.go"
375406
local tree = plugin.discover_positions(path)
376407

377408
local args = { tree = tree }
378409
local expected_command = "cd "
379-
.. vim.loop.cwd()
380-
.. "/neotest_go && go test -v -json -count=1 -timeout=60s ./..."
410+
.. vim.loop.cwd()
411+
.. "/neotest_go && go test -v -json -count=1 -timeout=60s ./..."
381412
local result = plugin_with_recursive_run.build_spec(args)
382413
assert.are.same(expected_command, result.command)
383414
assert.are.same(path, result.context.file)

neotest_go/cases_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ func TestAdd(t *testing.T) {
4242
assert.Equal(t, 5, add(1, 2))
4343
})
4444

45+
t.Run("test three", func(t *testing.T) {
46+
t.Run("test four", func(t *testing.T) {
47+
assert.Equal(t, 3, add(1, 2))
48+
})
49+
})
50+
4551
variable := "string"
4652
t.Run(variable, func(t *testing.T) {
4753
assert.Equal(t, 3, add(1, 2))

0 commit comments

Comments
 (0)