|
14 | 14 | import tempfile |
15 | 15 | import time |
16 | 16 | import unittest |
| 17 | +import subprocess |
17 | 18 |
|
18 | 19 | import kaptan |
19 | 20 |
|
20 | 21 | from .helpers import TmuxTestCase |
21 | 22 | from .. import Window, config, exc |
22 | | -from .._compat import text_type |
| 23 | +from .._compat import text_type, console_to_str |
23 | 24 | from ..workspacebuilder import WorkspaceBuilder |
24 | 25 |
|
25 | 26 | logger = logging.getLogger(__name__) |
@@ -214,6 +215,63 @@ def test_focus_pane_index(self): |
214 | 215 | self.assertEqual(p.get('pane_current_path'), pane_path) |
215 | 216 |
|
216 | 217 |
|
| 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 | + |
217 | 275 | class WindowOptions(TmuxTestCase): |
218 | 276 |
|
219 | 277 | yaml_config = """ |
@@ -895,5 +953,6 @@ def suite(): |
895 | 953 | suite.addTest(unittest.makeSuite(WindowAutomaticRename)) |
896 | 954 | suite.addTest(unittest.makeSuite(WindowIndexTest)) |
897 | 955 | suite.addTest(unittest.makeSuite(WindowOptions)) |
| 956 | + suite.addTest(unittest.makeSuite(SuppressHistoryTest)) |
898 | 957 | suite.addTest(unittest.makeSuite(EnvironmentVariables)) |
899 | 958 | return suite |
0 commit comments