From 4c6a4202d86699a3849fca15f5e2f9b4f2836747 Mon Sep 17 00:00:00 2001 From: Sam Cowger Date: Thu, 17 Nov 2022 14:33:29 -0800 Subject: [PATCH 1/3] Add :pwd command to REPL --- saw/SAWScript/REPL/Command.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/saw/SAWScript/REPL/Command.hs b/saw/SAWScript/REPL/Command.hs index df278eb073..2c6c6413c4 100644 --- a/saw/SAWScript/REPL/Command.hs +++ b/saw/SAWScript/REPL/Command.hs @@ -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 @@ -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] @@ -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 From d8c68bf7541c3544288636019b5bfb433c4ea8e2 Mon Sep 17 00:00:00 2001 From: Sam Cowger Date: Fri, 18 Nov 2022 10:19:25 -0800 Subject: [PATCH 2/3] Add test --- intTests/test_pwd/README.md | 3 +++ intTests/test_pwd/test.sh | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 intTests/test_pwd/README.md create mode 100644 intTests/test_pwd/test.sh diff --git a/intTests/test_pwd/README.md b/intTests/test_pwd/README.md new file mode 100644 index 0000000000..ed1a57fc58 --- /dev/null +++ b/intTests/test_pwd/README.md @@ -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`. \ No newline at end of file diff --git a/intTests/test_pwd/test.sh b/intTests/test_pwd/test.sh new file mode 100644 index 0000000000..2e75ed870b --- /dev/null +++ b/intTests/test_pwd/test.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -e + +HERE=`pwd` +RES=`echo ':pwd' | $SAW` +[[ "$RES" =~ .*"$HERE".* ]] \ No newline at end of file From 29b6478eaef579d94c1b2c510e3a7fb0b34d3ecc Mon Sep 17 00:00:00 2001 From: Sam Cowger Date: Tue, 20 Dec 2022 11:19:32 -0600 Subject: [PATCH 3/3] test_pwd: specify interactive REPL and disable colorization --- intTests/test_pwd/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intTests/test_pwd/test.sh b/intTests/test_pwd/test.sh index 2e75ed870b..a336b468ff 100644 --- a/intTests/test_pwd/test.sh +++ b/intTests/test_pwd/test.sh @@ -3,5 +3,5 @@ set -e HERE=`pwd` -RES=`echo ':pwd' | $SAW` +RES=`echo ':pwd' | $SAW --interactive --no-color` [[ "$RES" =~ .*"$HERE".* ]] \ No newline at end of file