Skip to content

Commit

Permalink
Add DAP Strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenprater committed Nov 27, 2024
1 parent 5623b9a commit e992e43
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 9 deletions.
61 changes: 52 additions & 9 deletions lua/neotest-minitest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,37 @@ function NeotestAdapter.build_spec(args)
table.insert(script_args, "--")
end

local function dap_strategy(command)
local port = math.random(49152, 65535)
port = config.port or port

local rdbg_args = {
"-O",
"--port",
port,
"-c",
"-e",
"cont",
"--",
}

for i = 1, #command do
rdbg_args[#rdbg_args + 1] = command[i]
end

return {
name = "Neotest Debugger",
type = "ruby",
bundle = "bundle",
localfs = true,
request = "attach",
args = rdbg_args,
command = "rdbg",
cwd = "${workspaceFolder}",
port = port,
}
end

if position.type == "file" then run_by_filename() end

if position.type == "test" or position.type == "namespace" then run_by_name() end
Expand All @@ -142,15 +173,27 @@ function NeotestAdapter.build_spec(args)
"-v",
})

return {
cwd = nil,
command = command,
context = {
results_path = results_path,
pos_id = position.id,
name_mappings = name_mappings,
},
}
if args.strategy == "dap" then
return {
command = command,
context = {
results_path = results_path,
pos_id = position.id,
name_mappings = name_mappings,
},
strategy = dap_strategy(command),
}
else
return {
cwd = nil,
command = command,
context = {
results_path = results_path,
pos_id = position.id,
name_mappings = name_mappings,
},
}
end
end

function NeotestAdapter._parse_test_output(output, name_mappings)
Expand Down
40 changes: 40 additions & 0 deletions tests/adapter/classic_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,46 @@ local plugin = require("neotest-minitest")
local async = require("nio.tests")

describe("Classic Test", function()
describe("build_spec", function()
async.it("should build a spec", function()
local test_path = vim.loop.cwd() .. "/tests/minitest_examples/classic_test.rb"
local tree = plugin.discover_positions(test_path)

local spec = plugin.build_spec({
tree = tree,
strategy = "dap",
})

local expected_strategy = {
args = {
"-O",
"--port",
62164,
"-c",
"-e",
"cont",
"--",
"bundle",
"exec",
"ruby",
"-Itest",
vim.loop.cwd() .. "/tests/minitest_examples/classic_test.rb",
"-v",
},
bundle = "bundle",
command = "rdbg",
cwd = "${workspaceFolder}",
localfs = true,
name = "Neotest Debugger",
port = 62164,
request = "attach",
type = "ruby",
}

assert.are.same(spec.strategy, expected_strategy)
end)
end)

describe("discovers_positions", function()
async.it("should discover the position of the test", function()
local test_path = vim.loop.cwd() .. "/tests/minitest_examples/classic_test.rb"
Expand Down

0 comments on commit e992e43

Please sign in to comment.