Skip to content

Commit 9ce85b0

Browse files
authored
fix(test_harness): floating results window (#520)
* Resolved invalid escape sequence error caused by Windows backslash in filepaths. * PlenaryBustedDirectory now works with no path issues, and the PlenaryTestFile keymap now properly tests only the file. * Refactored test running and floating window logic out into _test_paths and made test_directory only responsible for passing a list of test files to the new _test_paths function. Finally added a test_file function which calls _test_paths with only one path: the current file. * Update fix to be unique to Windows machines. For some reason, Path:absolute behaves differently on Linux.
1 parent 4cd4c29 commit 9ce85b0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lua/plenary/test_harness.lua

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ function harness.test_directory_command(command)
4040
return harness.test_directory(directory, opts)
4141
end
4242

43-
function harness.test_directory(directory, opts)
44-
print "Starting..."
45-
directory = directory:gsub("\\", "/")
43+
local function test_paths(paths, opts)
4644
local minimal = not opts or not opts.init or opts.minimal or opts.minimal_init
4745

4846
opts = vim.tbl_deep_extend("force", {
@@ -78,10 +76,7 @@ function harness.test_directory(directory, opts)
7876

7977
local outputter = headless and print_output or get_nvim_output(res.job_id)
8078

81-
local paths = harness._find_files_to_run(directory)
82-
8379
local path_len = #paths
84-
8580
local failure = false
8681

8782
local jobs = vim.tbl_map(function(p)
@@ -183,6 +178,25 @@ function harness.test_directory(directory, opts)
183178
end
184179
end
185180

181+
function harness.test_directory(directory, opts)
182+
print "Starting..."
183+
directory = directory:gsub("\\", "/")
184+
local paths = harness._find_files_to_run(directory)
185+
186+
-- Paths work strangely on Windows, so lets have abs paths
187+
if vim.fn.has "win32" == 1 or vim.fn.has "win64" == 1 then
188+
paths = vim.tbl_map(function(p)
189+
return Path:new(directory, p.filename)
190+
end, paths)
191+
end
192+
193+
test_paths(paths, opts)
194+
end
195+
196+
function harness.test_file(filepath)
197+
test_paths { Path:new(filepath) }
198+
end
199+
186200
function harness._find_files_to_run(directory)
187201
local finder
188202
if vim.fn.has "win32" == 1 or vim.fn.has "win64" == 1 then

plugin/plenary.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
" Create command for running busted
33
command! -nargs=1 -complete=file PlenaryBustedFile
4-
\ lua require('plenary.busted').run(vim.fn.expand([[<args>]]))
4+
\ lua require('plenary.test_harness').test_file([[<args>]])
55

66
command! -nargs=+ -complete=file PlenaryBustedDirectory
77
\ lua require('plenary.test_harness').test_directory_command([[<args>]])
88

9-
nnoremap <Plug>PlenaryTestFile :lua require('plenary.test_harness').test_directory(vim.fn.expand("%:p"))<CR>
9+
nnoremap <Plug>PlenaryTestFile :lua require('plenary.test_harness').test_file(vim.fn.expand("%:p"))<CR>

0 commit comments

Comments
 (0)