Skip to content

Commit 1ae194f

Browse files
committed
Added unit test for suppress history
1 parent 67e9a2f commit 1ae194f

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

tmuxp/testsuite/workspacebuilder.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
import tempfile
1515
import time
1616
import unittest
17+
import subprocess
1718

1819
import kaptan
1920

2021
from .helpers import TmuxTestCase
2122
from .. import Window, config, exc
22-
from .._compat import text_type
23+
from .._compat import text_type, console_to_str
2324
from ..workspacebuilder import WorkspaceBuilder
2425

2526
logger = logging.getLogger(__name__)
@@ -214,6 +215,63 @@ def test_focus_pane_index(self):
214215
self.assertEqual(p.get('pane_current_path'), pane_path)
215216

216217

218+
class SuppressHistoryTest(TmuxTestCase):
219+
yaml_config = """
220+
session_name: sampleconfig
221+
start_directory: '~'
222+
suppress_history: false
223+
windows:
224+
- window_name: inHistory
225+
panes:
226+
- echo inHistory
227+
- window_name: isMissing
228+
suppress_history: true
229+
panes:
230+
- echo isMissing
231+
"""
232+
def test_suppress_history(self):
233+
s = self.session
234+
sconfig = kaptan.Kaptan(handler='yaml')
235+
sconfig = sconfig.import_config(self.yaml_config).get()
236+
sconfig = config.expand(sconfig)
237+
sconfig = config.trickle(sconfig)
238+
239+
builder = WorkspaceBuilder(sconf=sconfig)
240+
builder.build(session=self.session)
241+
time.sleep(0.2) # give .bashrc, etc. time to load
242+
243+
s.server._update_windows()
244+
for w in s.windows:
245+
w.server._update_panes()
246+
w.select_window()
247+
for p in w.panes:
248+
p.select_pane()
249+
250+
# Print the last-in-history command in the pane
251+
self.session.cmd('send-keys', ' fc -ln -1')
252+
self.session.cmd('send-keys', 'Enter')
253+
time.sleep(0.01) # give fc time to run
254+
255+
# Get the contents of the pane
256+
self.session.cmd('capture-pane')
257+
captured_pane = self.session.cmd('show-buffer')
258+
self.session.cmd('delete-buffer')
259+
260+
# Parse the sent and last-in-history commands
261+
sent_cmd = captured_pane.stdout[0].strip()
262+
history_cmd = captured_pane.stdout[-2].strip()
263+
264+
# If it was in the history, sent == history
265+
if 'inHistory' in sent_cmd:
266+
self.assertEqual(sent_cmd, history_cmd)
267+
# Otherwise, sent != history
268+
elif 'isMissing' in sent_cmd:
269+
self.assertNotEqual(sent_cmd, history_cmd)
270+
# Something went wrong
271+
else:
272+
self.assertTrue(False)
273+
274+
217275
class WindowOptions(TmuxTestCase):
218276

219277
yaml_config = """
@@ -895,5 +953,6 @@ def suite():
895953
suite.addTest(unittest.makeSuite(WindowAutomaticRename))
896954
suite.addTest(unittest.makeSuite(WindowIndexTest))
897955
suite.addTest(unittest.makeSuite(WindowOptions))
956+
suite.addTest(unittest.makeSuite(SuppressHistoryTest))
898957
suite.addTest(unittest.makeSuite(EnvironmentVariables))
899958
return suite

0 commit comments

Comments
 (0)