11local api = vim .api
22local luv = vim .uv and vim .uv or vim .loop
3- local config = require (" competitest.config" )
43local utils = require (" competitest.utils" )
5- local ui = require (" competitest.runner_ui" )
64
75--- System command with arguments
86--- @class (exact ) competitest.SystemCommand
@@ -11,7 +9,6 @@ local ui = require("competitest.runner_ui")
119
1210--- Running testcase process status
1311--- @class (exact ) competitest.TCRunner.testcase_status.process
14- --- @field cmd competitest.SystemCommand
1512--- @field stdin uv.uv_pipe_t
1613--- @field stdout uv.uv_pipe_t
1714--- @field stderr uv.uv_pipe_t
@@ -25,7 +22,7 @@ local ui = require("competitest.runner_ui")
2522--- @field expout string[] ? expected output lines
2623--- @field stdout string[] stdout lines
2724--- @field stderr string[] stderr lines
28- --- @field tcnum integer | string testcase number or identifier
25+ --- @field tcnum integer | " Compile " testcase number or identifier
2926--- @field status " " | " RUNNING" | " TIMEOUT" | " KILLED" | " SIG x" | " RET x" | " FAILED" | " CORRECT" | " WRONG" | " DONE"
3027--- @field hlgroup string testcase status highlight group
3128--- @field timelimit integer ? maximum execution time in milliseconds , or ` nil` if there ' s no time limit
@@ -48,7 +45,7 @@ local ui = require("competitest.runner_ui")
4845--- @field tcdata table<integer , competitest.TCRunner.testcase_status> testcases status , data and results
4946--- @field private compile boolean whether compilation is needed in the current run or not
5047--- @field private next_tc integer index of next unprocessed testcase to run
51- --- @field restore_winid integer ? bring the cursor to the given window when testcases runner UI is closed
48+ --- @field ui_restore_winid integer ? bring the cursor to the given window when testcases runner UI is closed
5249--- @field private ui competitest.RunnerUI ?
5350local TCRunner = {}
5451TCRunner .__index = TCRunner --- @diagnostic disable-line : inject-field
@@ -81,7 +78,7 @@ function TCRunner:new(bufnr)
8178 return { exec = exec , args = args }
8279 end
8380
84- local buf_cfg = config .get_buffer_config (bufnr )
81+ local buf_cfg = require ( " competitest. config" ) .get_buffer_config (bufnr )
8582 local compile_command = nil
8683 if buf_cfg .compile_command [filetype ] then
8784 compile_command = eval_command (buf_cfg .compile_command [filetype ])
@@ -228,7 +225,6 @@ function TCRunner:execute_testcase(tcindex, cmd, dir, callback)
228225 --- @type competitest.TCRunner.testcase_status.process
229226 --- @diagnostic disable-next-line : missing-fields
230227 local process = {
231- cmd = cmd ,
232228 stdin = assert (luv .new_pipe (false ), " CompetiTest.nvim: TCRunner:execute_testcase: process stdin pipe creation failed" ),
233229 stdout = assert (luv .new_pipe (false ), " CompetiTest.nvim: TCRunner:execute_testcase: process stdout pipe creation failed" ),
234230 stderr = assert (luv .new_pipe (false ), " CompetiTest.nvim: TCRunner:execute_testcase: process stderr pipe creation failed" ),
@@ -237,8 +233,8 @@ function TCRunner:execute_testcase(tcindex, cmd, dir, callback)
237233
238234 utils .create_directory (dir )
239235 --- @diagnostic disable-next-line : missing-fields
240- process .handle , process .pid = luv .spawn (process . cmd .exec , {
241- args = process . cmd .args ,
236+ process .handle , process .pid = luv .spawn (cmd .exec , {
237+ args = cmd .args ,
242238 cwd = dir ,
243239 stdio = { process .stdin , process .stdout , process .stderr },
244240 }, function (code , signal )
@@ -279,7 +275,7 @@ function TCRunner:execute_testcase(tcindex, cmd, dir, callback)
279275 end
280276 end )
281277 if not process .handle then
282- utils .notify (" TCRunner:execute_testcase: failed to spawn process using '" .. process . cmd .exec .. " ' (" .. process .pid .. " )." )
278+ utils .notify (" TCRunner:execute_testcase: failed to spawn process using '" .. cmd .exec .. " ' (" .. process .pid .. " )." )
283279 tc .status = " FAILED"
284280 tc .hlgroup = " CompetiTestWarning"
285281 tc .time = - 1
@@ -358,6 +354,8 @@ function TCRunner:execute_testcase(tcindex, cmd, dir, callback)
358354 tc .hlgroup = " CompetiTestRunning"
359355 tc .running = true
360356 tc .killed = false
357+ tc .exit_code = nil
358+ tc .exit_signal = nil
361359 self :update_ui (true )
362360end
363361
@@ -392,7 +390,7 @@ function TCRunner:show_ui()
392390 return
393391 end
394392 if not self .ui then
395- self .ui = ui :new (self )
393+ self .ui = require ( " competitest.runner_ui " ) :new (self )
396394 end
397395 self .ui :show_ui ()
398396 self .ui :update_ui ()
401399--- Set or update `restore_winid`
402400--- @param restore_winid integer bring the cursor to the given window after runner is closed
403401function TCRunner :set_restore_winid (restore_winid )
404- self .restore_winid = restore_winid
402+ self .ui_restore_winid = restore_winid
405403 if self .ui then
406404 self .ui .restore_winid = restore_winid
407405 end
0 commit comments