Skip to content

Commit

Permalink
Merge pull request #1769 from GaloisInc/feature/pwd
Browse files Browse the repository at this point in the history
Add interpreter command to print current working directory
  • Loading branch information
mergify[bot] committed Dec 20, 2022
2 parents 7fe24ae + 1294d32 commit 22b08da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions intTests/test_pwd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Test the REPL's `:pwd` command. This test will pass if the REPL output of this
command includes, in any position, the current working directory as rendered by
`bash`'s `pwd`.
7 changes: 7 additions & 0 deletions intTests/test_pwd/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -e

HERE=`pwd`
RES=`echo ':pwd' | $SAW --interactive --no-color`
[[ "$RES" =~ .*"$HERE".* ]]
7 changes: 6 additions & 1 deletion saw/SAWScript/REPL/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Data.Char (isSpace,isPunctuation,isSymbol)
import Data.Function (on)
import Data.List (intercalate)
import System.FilePath((</>), isPathSeparator)
import System.Directory(getHomeDirectory,setCurrentDirectory,doesDirectoryExist)
import System.Directory(getHomeDirectory,getCurrentDirectory,setCurrentDirectory,doesDirectoryExist)
import qualified Data.Map as Map

-- SAWScript imports
Expand Down Expand Up @@ -124,6 +124,8 @@ commandList =
"exit the REPL"
, CommandDescr ":cd" (FilenameArg cdCmd)
"set the current working directory"
, CommandDescr ":pwd" (NoArg pwdCmd)
"display the current working directory"
]

genHelp :: [CommandDescr] -> [String]
Expand Down Expand Up @@ -194,6 +196,9 @@ cdCmd f | null f = io $ putStrLn $ "[error] :cd requires a path argument"
then io $ setCurrentDirectory f
else raise $ DirectoryNotFound f

pwdCmd :: REPL ()
pwdCmd = io $ getCurrentDirectory >>= putStrLn

-- SAWScript commands ----------------------------------------------------------

{- Evaluation is fairly straightforward; however, there are a few important
Expand Down

0 comments on commit 22b08da

Please sign in to comment.