@@ -41,18 +41,85 @@ describe(':mksession', function()
4141command (' split' )
4242command (' terminal' )
4343command (' split' )
44- command (' mksession' .. session_file )
44+ command (' mksession' .. session_file )
4545command (' %bwipeout!' )
4646
4747-- Create a new test instance of Nvim.
4848clear ()
4949-- Restore session.
50- command (' source' .. session_file )
50+ command (' source' .. session_file )
5151
5252eq (funcs .winbufnr (1 ),funcs .winbufnr (2 ))
5353neq (funcs .winbufnr (1 ),funcs .winbufnr (3 ))
5454end )
5555
56+ -- common testing procedure for testing "sessionoptions-=terminal"
57+ local function test_terminal_session_disabled (expected_buf_count )
58+ command (' set sessionoptions-=terminal' )
59+
60+ command (' mksession' .. session_file )
61+
62+ -- Create a new test instance of Nvim.
63+ clear ()
64+
65+ -- Restore session.
66+ command (' source' .. session_file )
67+
68+ eq (expected_buf_count ,# meths .list_bufs ())
69+ end
70+
71+ it (
72+ ' do not restore :terminal if not set in sessionoptions, terminal in current window #13078' ,
73+ function ()
74+ local tmpfile_base = file_prefix .. ' -tmpfile'
75+ command (' edit' .. tmpfile_base )
76+ command (' terminal' )
77+
78+ local buf_count = # meths .list_bufs ()
79+ eq (2 ,buf_count )
80+
81+ eq (' terminal' ,meths .buf_get_option (0 ,' buftype' ))
82+
83+ test_terminal_session_disabled (2 )
84+
85+ -- no terminal should be set. As a side effect we end up with a blank buffer
86+ eq (' ' ,meths .buf_get_option (meths .list_bufs ()[1 ],' buftype' ))
87+ eq (' ' ,meths .buf_get_option (meths .list_bufs ()[2 ],' buftype' ))
88+ end
89+ )
90+
91+ it (' do not restore :terminal if not set in sessionoptions, terminal hidden #13078' ,function ()
92+ command (' terminal' )
93+ local terminal_bufnr = meths .get_current_buf ()
94+
95+ local tmpfile_base = file_prefix .. ' -tmpfile'
96+ -- make terminal hidden by opening a new file
97+ command (' edit' .. tmpfile_base .. ' 1' )
98+
99+ local buf_count = # meths .list_bufs ()
100+ eq (2 ,buf_count )
101+
102+ eq (1 ,funcs .getbufinfo (terminal_bufnr )[1 ].hidden )
103+
104+ test_terminal_session_disabled (1 )
105+
106+ -- no terminal should exist here
107+ neq (' ' ,meths .buf_get_name (meths .list_bufs ()[1 ]))
108+ end )
109+
110+ it (' do not restore :terminal if not set in sessionoptions, only buffer #13078' ,function ()
111+ command (' terminal' )
112+ eq (' terminal' ,meths .buf_get_option (0 ,' buftype' ))
113+
114+ local buf_count = # meths .list_bufs ()
115+ eq (1 ,buf_count )
116+
117+ test_terminal_session_disabled (1 )
118+
119+ -- no terminal should be set
120+ eq (' ' ,meths .buf_get_option (0 ,' buftype' ))
121+ end )
122+
56123it (' restores tab-local working directories' ,function ()
57124local tmpfile_base = file_prefix .. ' -tmpfile'
58125local cwd_dir = funcs .getcwd ()
@@ -102,27 +169,27 @@ describe(':mksession', function()
102169
103170it (' restores CWD for :terminal buffers #11288' ,function ()
104171local cwd_dir = funcs .fnamemodify (' .' ,' :p:~' ):gsub ([[ [\/]*$]] ,' ' )
105- cwd_dir = cwd_dir :gsub ([[ \]] ,' /' )-- :mksession always uses unix slashes.
106- local session_path = cwd_dir .. ' /' .. session_file
172+ cwd_dir = cwd_dir :gsub ([[ \]] ,' /' )-- :mksession always uses unix slashes.
173+ local session_path = cwd_dir .. ' /' .. session_file
107174
108- command (' cd' .. tab_dir )
175+ command (' cd' .. tab_dir )
109176command (' terminal' )
110- command (' cd' .. cwd_dir )
111- command (' mksession' .. session_path )
177+ command (' cd' .. cwd_dir )
178+ command (' mksession' .. session_path )
112179command (' %bwipeout!' )
113180if iswin ()then
114- sleep (100 )-- Make sure all child processes have exited.
181+ sleep (100 )-- Make sure all child processes have exited.
115182end
116183
117184-- Create a new test instance of Nvim.
118185clear ()
119- command (' silent source' .. session_path )
186+ command (' silent source' .. session_path )
120187
121- local expected_cwd = cwd_dir .. ' /' .. tab_dir
122- matches (' ^term://' .. pesc (expected_cwd ).. ' //%d+:' ,funcs .expand (' %' ))
188+ local expected_cwd = cwd_dir .. ' /' .. tab_dir
189+ matches (' ^term://' .. pesc (expected_cwd ).. ' //%d+:' ,funcs .expand (' %' ))
123190command (' %bwipeout!' )
124191if iswin ()then
125- sleep (100 )-- Make sure all child processes have exited.
192+ sleep (100 )-- Make sure all child processes have exited.
126193end
127194end )
128195
@@ -134,10 +201,10 @@ describe(':mksession', function()
134201
135202local screen
136203local cwd_dir = funcs .fnamemodify (' .' ,' :p:~' ):gsub ([[ [\/]*$]] ,' ' )
137- local session_path = cwd_dir .. ' /' .. session_file
204+ local session_path = cwd_dir .. ' /' .. session_file
138205
139206screen = Screen .new (50 ,6 )
140- screen :attach ({rgb = false })
207+ screen :attach ({rgb = false })
141208local expected_screen = [[
142209 ^/ |
143210 |
@@ -153,15 +220,15 @@ describe(':mksession', function()
153220-- Verify that the terminal's working directory is "/".
154221screen :expect (expected_screen )
155222
156- command (' cd' .. cwd_dir )
157- command (' mksession' .. session_path )
223+ command (' cd' .. cwd_dir )
224+ command (' mksession' .. session_path )
158225command (' %bwipeout!' )
159226
160227-- Create a new test instance of Nvim.
161228clear ()
162229screen = Screen .new (50 ,6 )
163- screen :attach ({rgb = false })
164- command (' silent source' .. session_path )
230+ screen :attach ({rgb = false })
231+ command (' silent source' .. session_path )
165232
166233-- Verify that the terminal's working directory is "/".
167234screen :expect (expected_screen )
@@ -179,7 +246,7 @@ describe(':mksession', function()
179246height = 3 ,
180247row = 0 ,
181248col = 1 ,
182- style = ' minimal'
249+ style = ' minimal' ,
183250 }
184251meths .open_win (buf ,false ,config )
185252local cmdheight = meths .get_option (' cmdheight' )