|
1 | 1 | """Test for libtmux Window object."""
|
2 | 2 | import logging
|
| 3 | +import shutil |
| 4 | +import time |
3 | 5 | import typing as t
|
4 | 6 |
|
5 | 7 | import pytest
|
@@ -310,3 +312,45 @@ def test_empty_window_name(session: Session) -> None:
|
310 | 312 | "#{==:#{session_name}," + session.name + "}",
|
311 | 313 | )
|
312 | 314 | assert "''" in cmd.stdout
|
| 315 | + |
| 316 | + |
| 317 | +@pytest.mark.skipif( |
| 318 | + has_lt_version("3.0"), |
| 319 | + reason="needs -e flag for split-window which was introduced in 3.0", |
| 320 | +) |
| 321 | +def test_split_window_with_environment(session: Session) -> None: |
| 322 | + env = shutil.which("env") |
| 323 | + assert env is not None, "Cannot find usable `env` in Path." |
| 324 | + |
| 325 | + window = session.new_window(window_name="split_window_with_environment") |
| 326 | + pane = window.split_window( |
| 327 | + shell=f"{env} PS1='$ ' sh", |
| 328 | + environment={"ENV_VAR": "pane"}, |
| 329 | + ) |
| 330 | + assert pane is not None |
| 331 | + # wait a bit for the prompt to be ready as the test gets flaky otherwise |
| 332 | + time.sleep(0.05) |
| 333 | + pane.send_keys("echo $ENV_VAR") |
| 334 | + assert pane.capture_pane() == ["$ echo $ENV_VAR", "pane", "$"] |
| 335 | + |
| 336 | + |
| 337 | +@pytest.mark.skipif( |
| 338 | + has_gte_version("3.0"), |
| 339 | + reason="3.0 has the -e flag on split-window", |
| 340 | +) |
| 341 | +def test_split_window_with_environment_logs_warning_for_old_tmux( |
| 342 | + session: Session, |
| 343 | + caplog: pytest.LogCaptureFixture, |
| 344 | +) -> None: |
| 345 | + env = shutil.which("env") |
| 346 | + assert env is not None, "Cannot find usable `env` in Path." |
| 347 | + |
| 348 | + window = session.new_window(window_name="split_window_with_environment") |
| 349 | + window.split_window( |
| 350 | + shell=f"{env} PS1='$ ' sh", |
| 351 | + environment={"ENV_VAR": "pane"}, |
| 352 | + ) |
| 353 | + |
| 354 | + assert any( |
| 355 | + "Cannot set up environment" in record.msg for record in caplog.records |
| 356 | + ), "Warning missing" |
0 commit comments