diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-09-21 10:10:25 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-09-21 10:42:14 -0700 |
commit | a1ca51c979849b5a29f54cd4eea49ca3d49cb4c9 (patch) | |
tree | 1db3c61241ef0e62b9083212ac6ec059de4b6186 /test/Tests | |
parent | 1cbaea673debae8bbfebbb7835a6145166fae67b (diff) | |
download | pandoc-a1ca51c979849b5a29f54cd4eea49ca3d49cb4c9.tar.gz |
Command tests: raise error if command doesn't begin with `%`.
Diffstat (limited to 'test/Tests')
-rw-r--r-- | test/Tests/Command.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/test/Tests/Command.hs b/test/Tests/Command.hs index c197fd11f..f437e026b 100644 --- a/test/Tests/Command.hs +++ b/test/Tests/Command.hs @@ -12,6 +12,7 @@ Run commands, and test results, defined in markdown files. module Tests.Command (runTest, tests) where +import Data.Maybe (fromMaybe) import Data.Algorithm.Diff import System.Environment (getExecutablePath) import qualified Data.ByteString as BS @@ -90,18 +91,19 @@ extractCode :: Block -> String extractCode (CodeBlock _ code) = T.unpack code extractCode _ = "" -dropPercent :: String -> String -dropPercent ('%':xs) = dropWhile (== ' ') xs -dropPercent xs = xs +dropPercent :: String -> Maybe String +dropPercent ('%':xs) = Just $ dropWhile (== ' ') xs +dropPercent _ = Nothing runCommandTest :: FilePath -> FilePath -> Int -> String -> TestTree -runCommandTest testExePath fp num code = +runCommandTest testExePath fp num code = do goldenTest testname getExpected getActual compareValues' updateGolden where testname = "#" <> show num codelines = lines code (continuations, r1) = span ("\\" `isSuffixOf`) codelines - cmd = dropPercent (unwords (map init continuations ++ take 1 r1)) + cmd = fromMaybe (error "Command test line does not begin with %") + (dropPercent (unwords (map init continuations ++ take 1 r1))) r2 = drop 1 r1 (inplines, r3) = break (=="^D") r2 normlines = takeWhile (/=".") (drop 1 r3) |