summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-08-22 20:07:18 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-08-22 20:08:41 +0200
commit1204839cc27af071582b8f6c88530b6840f56f72 (patch)
tree74bf065e10e79a0cf3691faa5e31cc5e03d73473
parentb7832766c7225e6f455462eb92ee392249d4c737 (diff)
Shell: implement pwd command
Changelog: Implemented `pwd` command in shell interpreter.
-rw-r--r--src/Script/Shell.hs7
-rw-r--r--test/asset/shell/working-directory.et4
-rw-r--r--test/script/shell.et14
3 files changed, 25 insertions, 0 deletions
diff --git a/src/Script/Shell.hs b/src/Script/Shell.hs
index 91bdcb0..fbb92af 100644
--- a/src/Script/Shell.hs
+++ b/src/Script/Shell.hs
@@ -154,6 +154,13 @@ executeCommand sei@ShellExecInfo {..} st pstdin pstdout pstderr scmd@ShellComman
executeCommandProcess :: ShellExecInfo -> ShellState -> Handle -> Handle -> Handle -> [ Text ] -> Text -> TestRun ( TestRun ProcessStatus, ShellState )
executeCommandProcess ShellExecInfo {..} st@ShellState {..} pstdin pstdout pstderr args = \case
+ "pwd"
+ | [] <- args -> do
+ liftIO $ hPutStrLn pstdout shellWorkingDirectory
+ return ( return (Exited ExitSuccess), st )
+ | otherwise -> do
+ liftIO $ hPutStrLn pstderr $ "pwd: too many arguments"
+ return ( return (Exited (ExitFailure (-1))), st )
cmd -> liftIO $ do
(_, _, _, phandle) <- createProcess_ "shell"
(proc (T.unpack cmd) (map T.unpack args))
diff --git a/test/asset/shell/working-directory.et b/test/asset/shell/working-directory.et
new file mode 100644
index 0000000..e1732ee
--- /dev/null
+++ b/test/asset/shell/working-directory.et
@@ -0,0 +1,4 @@
+test Test:
+ node n
+ shell on n as sh:
+ pwd
diff --git a/test/script/shell.et b/test/script/shell.et
index 00826c8..2c09aa4 100644
--- a/test/script/shell.et
+++ b/test/script/shell.et
@@ -98,3 +98,17 @@ test ShellPipe:
with p:
expect /run-done/
+
+
+test ShellWorkingDirectory:
+ spawn as p
+ with p:
+ send "load ${scripts.path}/working-directory.et"
+ local:
+ expect /(load-.*)/ capture done
+ guard (done == "load-done")
+ flush
+
+ send "run *"
+
+ expect from p /child-stdout sh (\/.*)/ capture orig_pwd