@@ -35,7 +35,7 @@ local function run_and_wait_until_initialized(conf, server)
3535 -- wait for initialize and launch requests
3636 return (session and session .initialized and # server .spy .requests == 2 )
3737 end , 100 )
38- return dap .session ()
38+ return assert ( dap .session (), " Must have session after run " )
3939end
4040
4141describe (' dap with fake server' , function ()
@@ -937,3 +937,39 @@ describe('progress support', function()
937937 assert .are .same (' Running: Launch file' , progress .status ())
938938 end )
939939end )
940+
941+
942+ describe (" run_last" , function ()
943+ local server
944+ before_each (function ()
945+ server = require (' tests.server' ).spawn ()
946+ dap .adapters .dummy = server .adapter
947+ end )
948+ after_each (function ()
949+ server .stop ()
950+ dap .terminate ()
951+ end )
952+
953+ it (' can repeat run_last and it always clears session' , function ()
954+ server .client .initialize = function (self , request )
955+ self :send_response (request , {
956+ supportsTerminateRequest = true ,
957+ })
958+ self :send_event (" initialized" , {})
959+ end
960+
961+ run_and_wait_until_initialized (config , server )
962+ server .spy .clear ()
963+ dap .run_last ()
964+ wait (function () return # server .spy .requests == 3 end )
965+ local commands = vim .tbl_map (function (x ) return x .command end , server .spy .requests )
966+ assert .are .same ({" terminate" , " initialize" , " launch" }, commands )
967+ assert .are .same (1 , vim .tbl_count (dap .sessions ()))
968+
969+ dap .run_last ()
970+ wait (function () return # server .spy .requests == 3 end )
971+ commands = vim .tbl_map (function (x ) return x .command end , server .spy .requests )
972+ assert .are .same ({" terminate" , " initialize" , " launch" }, commands )
973+ assert .are .same (1 , vim .tbl_count (dap .sessions ()))
974+ end )
975+ end )
0 commit comments