Skip to content

Commit

Permalink
Simplify query, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed Dec 23, 2024
1 parent fa82ea0 commit 7904a7d
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 18 deletions.
20 changes: 4 additions & 16 deletions lua/neotest-busted/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,11 @@ function BustedNeotestAdapter.discover_positions(path)
arguments: (arguments (_) @test.name (function_definition))
) (#match? @func_name "^it$")) @test.definition
;; pending blocks constrained to have a describe as a parent
;; pending blocks
((function_call
name: (identifier) @func_name1 (#match? @func_name1 "^describe$")
arguments: (arguments
(_) @namespace.name
(function_definition
parameters: (parameters)
body: (block
((function_call
name: (identifier) @func_name2
arguments: (arguments (_) @test.name (function_definition)?)
) (#match? @func_name2 "^pending$")
) @test.definition
)
)
)
)) @namespace.definition
name: (identifier) @func_name
arguments: (arguments (string) @test.name)
) (#match? @func_name "^pending$")) @test.definition
;; custom async blocks
((function_call
Expand Down
74 changes: 74 additions & 0 deletions test_files/expected_pending_tree.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
local path = "./test_files/pending_spec.lua"

return {
{
id = path,
name = "pending_spec.lua",
path = path,
range = { 0, 0, 14, 0 },
type = "file",
},
{
{
id = path .. '::"top-level pending"',
name = '"top-level pending"',
path = path,
range = { 0, 0, 0, 28 },
type = "test",
},
},
{
{
id = path .. '::"pending tests"',
name = '"pending tests"',
path = path,
range = { 2, 0, 13, 4 },
type = "namespace",
},
{
{
id = path .. '::"pending tests"::"pending 1"',
name = '"pending 1"',
path = path,
range = { 3, 4, 5, 8 },
type = "test",
},
{
{
id = path .. '::"pending tests"::"pending 1"::"finish this test later"',
name = '"finish this test later"',
path = path,
range = { 4, 8, 4, 41 },
type = "test",
},
},
},
{
{
id = path .. '::"pending tests"::"pending 2"',
name = '"pending 2"',
path = path,
range = { 7, 4, 10, 8 },
type = "test",
},
{
{
id = path .. '::"pending tests"::"pending 2"::"this test does not run"',
name = '"this test does not run"',
path = path,
range = { 8, 8, 9, 12 },
type = "test",
},
},
},
{
{
id = path .. '::"pending tests"::"pending 3"',
name = '"pending 3"',
path = path,
range = { 12, 4, 12, 24 },
type = "test",
},
},
},
}
4 changes: 2 additions & 2 deletions test_files/pending_spec.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
pending("top-level pending")

describe("pending tests", function()
it("pending 1", function()
pending("finish this test later")
error("this should not run")
end)

pending("pending 2", function()
it("this test does not run", function()
error("this should not run")
end)
end)

Expand Down
12 changes: 12 additions & 0 deletions tests/adapter_discover_positions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ describe("adapter.discover_positions", function()
assert.are.same(cache:size(), 0)
end)

async.it("discovers pending tests", function()
local positions = adapter.discover_positions("./test_files/pending_spec.lua"):to_list()

local expected_tree = require("./test_files/expected_pending_tree")
assert.are.same(positions, expected_tree)

---@diagnostic disable-next-line: undefined-field
local cache = adapter.get_parametric_test_cache()

assert.are.same(cache:size(), 0)
end)

async.it("discovers parametric test positions", function()
local path = "./test_files/parametric_tests_spec.lua"

Expand Down

0 comments on commit 7904a7d

Please sign in to comment.