Skip to content

Commit 5e22a2e

Browse files
authored
fix: put outputs in nvim's tempdir (#36)
This fixes neotest-vstest leaving lots of guid-named files in /tmp. Instead, the individual test outputs are put into nvim's tempdir which is removed when nvim exits.
1 parent baa54a3 commit 5e22a2e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lua/neotest-vstest/vstest/client.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@ function M.run_tests(runner, ids)
9494
local result_stream_path = nio.fn.tempname()
9595
lib.files.write(result_stream_path, "")
9696

97+
local output_dir_path = nio.fn.tempname()
98+
local mkdir_err, _ = nio.uv.fs_mkdir(output_dir_path, 493) -- tonumber('755', 8)
99+
assert(not mkdir_err, mkdir_err)
100+
97101
local command = vim
98102
.iter({
99103
"run-tests",
100104
result_stream_path,
101105
result_path,
102106
process_output_path,
107+
output_dir_path,
103108
ids,
104109
})
105110
:flatten()
@@ -130,6 +135,10 @@ function M.debug_tests(runner, ids)
130135
local result_stream_path = nio.fn.tempname()
131136
lib.files.write(result_stream_path, "")
132137

138+
local output_dir_path = nio.fn.tempname()
139+
local mkdir_err, _ = nio.uv.fs_mkdir(output_dir_path, 493) -- tonumber('755', 8)
140+
assert(not mkdir_err, mkdir_err)
141+
133142
local pid_path = nio.fn.tempname()
134143

135144
local command = vim
@@ -140,6 +149,7 @@ function M.debug_tests(runner, ids)
140149
result_stream_path,
141150
result_path,
142151
process_output_path,
152+
output_dir_path,
143153
ids,
144154
})
145155
:flatten()

scripts/run_tests.fsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ module TestDiscovery =
6262
{| StreamPath = args[0]
6363
OutputPath = args[1]
6464
ProcessOutput = args[2]
65-
Ids = args[3..] |> Array.map Guid.Parse |}
65+
OutputDirPath = args[3]
66+
Ids = args[4..] |> Array.map Guid.Parse |}
6667
|> ValueOption.Some
6768
else
6869
ValueOption.None
@@ -77,7 +78,8 @@ module TestDiscovery =
7778
StreamPath = args[2]
7879
OutputPath = args[3]
7980
ProcessOutput = args[4]
80-
Ids = args[5..] |> Array.map Guid.Parse |}
81+
OutputDirPath = args[5]
82+
Ids = args[6..] |> Array.map Guid.Parse |}
8183
|> ValueOption.Some
8284
else
8385
ValueOption.None
@@ -139,7 +141,7 @@ module TestDiscovery =
139141

140142
member __.HandleRawMessage(_) = ()
141143

142-
type PlaygroundTestRunHandler(streamOutputPath, outputFilePath, processOutputPath) =
144+
type PlaygroundTestRunHandler(streamOutputPath, outputFilePath, processOutputPath, outputDirPath) =
143145
let resultsDictionary = ConcurrentDictionary()
144146
let processOutputWriter = new StreamWriter(processOutputPath, append = true)
145147

@@ -194,7 +196,7 @@ module TestDiscovery =
194196
let neoTestResult =
195197
{ status = outcome
196198
short = $"{result.TestCase.DisplayName}:{outcome}"
197-
output = Path.GetTempPath() + Guid.NewGuid().ToString()
199+
output = Path.Join(outputDirPath, Guid.NewGuid().ToString())
198200
errors = errors }
199201

200202
File.WriteAllText(neoTestResult.output, result.ToString())
@@ -302,7 +304,7 @@ module TestDiscovery =
302304
let testCases = getTestCases args.Ids
303305

304306
use testHandler =
305-
new PlaygroundTestRunHandler(args.StreamPath, args.OutputPath, args.ProcessOutput)
307+
new PlaygroundTestRunHandler(args.StreamPath, args.OutputPath, args.ProcessOutput, args.OutputDirPath)
306308
// spawn as task to allow running concurrent tests
307309
do! r.RunTestsAsync(testCases, sourceSettings, testHandler)
308310
Console.WriteLine($"Done running tests for ids: ")
@@ -318,7 +320,7 @@ module TestDiscovery =
318320
let testCases = getTestCases args.Ids
319321

320322
use testHandler =
321-
new PlaygroundTestRunHandler(args.StreamPath, args.OutputPath, args.ProcessOutput)
323+
new PlaygroundTestRunHandler(args.StreamPath, args.OutputPath, args.ProcessOutput, args.OutputDirPath)
322324

323325
let debugLauncher = DebugLauncher(args.PidPath, args.AttachedPath)
324326
Console.WriteLine($"Starting {Seq.length testCases} tests in debug-mode")

0 commit comments

Comments
 (0)