@@ -73,14 +73,14 @@ runTest testExePath testname cmd inp norm = testCase testname $ do
7373 else return $ TestError ec
7474 assertBool (show result) (result == TestPassed )
7575
76- tests :: TestTree
76+ tests :: FilePath -> TestTree
7777{-# NOINLINE tests #-}
78- tests = unsafePerformIO $ do
78+ tests root = unsafePerformIO $ do
7979 files <- filter (" .md" `isSuffixOf` ) <$>
80- getDirectoryContents " command "
80+ getDirectoryContents root
8181 testExePath <- getExecutablePath
82- let cmds = map (extractCommandTest testExePath) files
83- return $ testGroup " Command: " cmds
82+ let cmds = map (extractCommandTest root testExePath) files
83+ return $ testGroup ( " Command folder: " <> root) cmds
8484
8585isCodeBlock :: Block -> Bool
8686isCodeBlock (CodeBlock _ _) = True
@@ -94,9 +94,9 @@ dropPercent :: String -> String
9494dropPercent (' %' : xs) = dropWhile (== ' ' ) xs
9595dropPercent xs = xs
9696
97- runCommandTest :: FilePath -> FilePath -> Int -> String -> TestTree
98- runCommandTest testExePath fp num code =
99- goldenTest testname getExpected getActual compareValues' updateGolden
97+ runCommandTest :: FilePath -> FilePath -> FilePath -> Int -> String -> TestTree
98+ runCommandTest root testExePath fp num code =
99+ goldenTest testname getExpected getActual compareValues updateGolden
100100 where
101101 testname = " #" <> show num
102102 codelines = lines code
@@ -109,27 +109,27 @@ runCommandTest testExePath fp num code =
109109 norm = unlines normlines
110110 getExpected = return norm
111111 getActual = snd <$> execTest testExePath cmd input
112- compareValues' expected actual
112+ compareValues expected actual
113113 | actual == expected = return Nothing
114- | otherwise = return $ Just $ " --- test/command/ " ++ fp ++ " \n +++ " ++
114+ | otherwise = return $ Just $ " --- test" </> root </> fp ++ " \n +++ " ++
115115 cmd ++ " \n " ++ showDiff (1 ,1 )
116116 (getDiff (lines actual) (lines expected))
117117 updateGolden newnorm = do
118- let fp' = " command" </> fp
118+ let fp' = " command/figures " </> fp
119119 raw <- UTF8. readFile fp'
120120 let cmdline = " % " <> cmd
121121 let x = cmdline <> " \n " <> input <> " ^D\n " <> norm
122122 let y = cmdline <> " \n " <> input <> " ^D\n " <> newnorm
123123 let updated = T. replace (T. pack x) (T. pack y) raw
124124 UTF8. writeFile fp' updated
125125
126- extractCommandTest :: FilePath -> FilePath -> TestTree
127- extractCommandTest testExePath fp = unsafePerformIO $ do
128- contents <- UTF8. toText <$> BS. readFile (" command " </> fp)
126+ extractCommandTest :: FilePath -> FilePath -> FilePath -> TestTree
127+ extractCommandTest root testExePath fp = unsafePerformIO $ do
128+ contents <- UTF8. toText <$> BS. readFile (root </> fp)
129129 Pandoc _ blocks <- runIOorExplode (readMarkdown
130130 def{ readerExtensions = pandocExtensions } contents)
131131 let codeblocks = map extractCode $ filter isCodeBlock blocks
132- let cases = zipWith (runCommandTest testExePath fp) [1 .. ] codeblocks
132+ let cases = zipWith (runCommandTest root testExePath fp) [1 .. ] codeblocks
133133 return $ testGroup fp
134134 $ if null cases
135135 then [testCase " !!" $ assertFailure " No command tests defined" ]
0 commit comments