diff --git a/intTests/test_set_base/Makefile b/intTests/test_set_base/Makefile new file mode 100644 index 0000000000..c9e12c62ae --- /dev/null +++ b/intTests/test_set_base/Makefile @@ -0,0 +1,5 @@ +all: ; +clean: + sh ./test.sh clean + +.PHONY: all clean diff --git a/intTests/test_set_base/test.log.good b/intTests/test_set_base/test.log.good new file mode 100644 index 0000000000..cbaaa88a23 --- /dev/null +++ b/intTests/test_set_base/test.log.good @@ -0,0 +1,33 @@ +Loading file "test.saw" +== Anticipated failure message == +Stack trace: + (builtin) in set_base + test.saw:11:8-11:18 in (callback) + (builtin) in fails + test.saw:11:1-11:18 (at top level) +set_base: unsupported base 0; value must be between 2 and 36 + +== Anticipated failure message == +Stack trace: + (builtin) in set_base + test.saw:12:8-12:18 in (callback) + (builtin) in fails + test.saw:12:1-12:18 (at top level) +set_base: unsupported base 1; value must be between 2 and 36 + +== Anticipated failure message == +Stack trace: + (builtin) in set_base + test.saw:13:8-13:19 in (callback) + (builtin) in fails + test.saw:13:1-13:19 (at top level) +set_base: unsupported base 37; value must be between 2 and 36 + +== Anticipated failure message == +Stack trace: + (builtin) in set_base + test.saw:14:8-14:20 in (callback) + (builtin) in fails + test.saw:14:1-14:20 (at top level) +set_base: unsupported base 100; value must be between 2 and 36 + diff --git a/intTests/test_set_base/test.saw b/intTests/test_set_base/test.saw new file mode 100644 index 0000000000..a9130df890 --- /dev/null +++ b/intTests/test_set_base/test.saw @@ -0,0 +1,14 @@ +// Test that set_base works for valid bases and rejects invalid ones. + +// Valid bases should succeed. +set_base 2; +set_base 8; +set_base 10; +set_base 16; +set_base 36; + +// Invalid bases should fail. +fails (set_base 0); +fails (set_base 1); +fails (set_base 37); +fails (set_base 100); diff --git a/intTests/test_set_base/test.sh b/intTests/test_set_base/test.sh new file mode 100644 index 0000000000..5fcd79d0a6 --- /dev/null +++ b/intTests/test_set_base/test.sh @@ -0,0 +1 @@ +exec ${TEST_SHELL:-bash} ../support/test-and-diff.sh "$@" diff --git a/saw-script/src/SAWScript/REPL/Command.hs b/saw-script/src/SAWScript/REPL/Command.hs index 56f6ab2f47..5f9113c069 100644 --- a/saw-script/src/SAWScript/REPL/Command.hs +++ b/saw-script/src/SAWScript/REPL/Command.hs @@ -453,16 +453,15 @@ searchExactCommandByPrefix prefix = -- | Do tilde-expansion on filenames. expandHome :: Text -> REPL FilePath expandHome path = - case Text.uncons path of - Nothing -> pure "" - Just ('~', more) -> case Text.uncons more of - Just (c, more') | isPathSeparator c -> do - dir <- liftIO getHomeDirectory - return (dir Text.unpack more') - _ -> - pure $ Text.unpack path - Just _ -> - pure $ Text.unpack path + case Text.stripPrefix "~" path of + Nothing -> pure $ Text.unpack path + Just rest -> case Text.uncons rest of + Nothing -> liftIO getHomeDirectory + Just (c, more) + | isPathSeparator c -> do + dir <- liftIO getHomeDirectory + return (dir Text.unpack more) + | otherwise -> pure $ Text.unpack path -- | Execute a REPL :-command. executeReplCommand :: CommandDescr -> [Text] -> REPL ()