aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-14 22:06:27 +0200
committeruser <user@clank>2026-08-14 22:06:27 +0200
commit360ee83a9bae4d06db1ab7747ef984cd7292883d (patch)
treedf0c65da1753f288d875483538b3f6517628d289 /tests
parentsl0ppty: walk the row, not screen_at() (diff)
downloadslosh-360ee83a9bae4d06db1ab7747ef984cd7292883d.tar.gz
slosh-360ee83a9bae4d06db1ab7747ef984cd7292883d.tar.xz
slosh-360ee83a9bae4d06db1ab7747ef984cd7292883d.zip
sl0ppty: expand ~ in a path that a config file wrote
`cwd="~/dev/api"` is in the README, in config/layout.example.kdl, and did nothing. `~` is a shell thing, and no shell has touched a path that arrives from a layout file -- so it went to chdir() literally, failed, and left the pane in whatever directory the session happened to be started from. The pane still ran, so nothing looked wrong until you typed `ls`. path_expand() handles `~` and `~/...` against $HOME and returns everything else untouched, including `~user`, which needs the password database and is not worth linking it in for -- returned unchanged rather than half-expanded into something wrong. Applied where a layout's cwd is read, which is one place because a pane inherits its tab's. Found while documenting a shader directory that was about to have exactly the same bug.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_layout_files.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_layout_files.py b/tests/test_layout_files.py
index 4adfbef..f396b07 100644
--- a/tests/test_layout_files.py
+++ b/tests/test_layout_files.py
@@ -142,6 +142,34 @@ def test_cwd():
os.unlink(s._layout_path)
+def test_cwd_expands_a_tilde():
+ """`~` is a shell thing, and no shell has touched a path in a layout file.
+
+ Unexpanded it reached chdir() literally, failed, and left the pane in
+ whatever directory the session was started from — with the pane running,
+ so nothing looked wrong until you typed `ls`."""
+ home = tempfile.mkdtemp(prefix="sl0ppty-home-")
+ text = """
+ layout {
+ tab name="t" {
+ pane cwd="~" command="pwd; cat"
+ pane cwd="~/sub" command="pwd; cat"
+ }
+ }
+ """
+ os.mkdir(os.path.join(home, "sub"))
+ with session_with(text, cols=76, rows=14, env={"HOME": home}) as s:
+ s.settle()
+ panes = s.panes()
+ snap = s.snapshot()
+ check("~ is the home directory",
+ home in snap.pane_text(panes[0]), repr(snap.pane_text(panes[0])))
+ check("and ~/sub is under it",
+ os.path.join(home, "sub") in snap.pane_text(panes[1]),
+ repr(snap.pane_text(panes[1])))
+ os.unlink(s._layout_path)
+
+
def test_apply_over_the_api():
"""How `sl0ppi up` will add a project tab to a running session."""
with Session(SH, cols=70, rows=14) as s:
@@ -206,6 +234,7 @@ if __name__ == "__main__":
test_suspended()
test_declared_purposes_are_locked()
test_cwd()
+ test_cwd_expands_a_tilde()
test_apply_over_the_api()
test_bad_layouts()
sys.exit(report())