@@ -1,46 +1,17 @@
11module Tests.Old (tests) where
22
3+import Tests.Helpers hiding (test)
34import Test.Framework (testGroup, Test )
45import Test.Framework.Providers.HUnit
56import Test.HUnit ( assertBool )
6−import System.Environment.Executable (getExecutablePath)
77import System.IO ( openTempFile, stderr )
88import System.Process ( runProcess, waitForProcess )
9−import System.FilePath ( (</>), (<.>), takeDirectory, splitDirectories,
10− joinPath )
9+import System.FilePath ( (</>), (<.>), splitDirectories, joinPath )
1110import System.Directory
1211import System.Exit
1312import Data.Algorithm.Diff
1413import Prelude hiding ( readFile )
15−import qualified Data.ByteString.Lazy as B
16−import Text.Pandoc.UTF8 (toStringLazy)
17−import Text.Printf
18−
19−readFileUTF8 :: FilePath -> IO String
20−readFileUTF8 f = B.readFile f >>= return . toStringLazy
21−
22−data TestResult = TestPassed
23− | TestError ExitCode
24− | TestFailed String FilePath [Diff String]
25− deriving (Eq)
26−
27−instance Show TestResult where
28− show TestPassed = "PASSED"
29− show (TestError ec) = "ERROR " ++ show ec
30− show (TestFailed cmd file d) = '\n' : dash ++
31− "\n--- " ++ file ++
32− "\n+++ " ++ cmd ++ "\n" ++ showDiff (1,1) d ++
33− dash
34− where dash = replicate 72 '-'
35−
36−showDiff :: (Int,Int) -> [Diff String] -> String
37−showDiff _ [] = ""
38−showDiff (l,r) (First ln : ds) =
39− printf "+%4d " l ++ ln ++ "\n" ++ showDiff (l+1,r) ds
40−showDiff (l,r) (Second ln : ds) =
41− printf "-%4d " r ++ ln ++ "\n" ++ showDiff (l,r+1) ds
42−showDiff (l,r) (Both _ _ : ds) =
43− showDiff (l+1,r+1) ds
14+import qualified Text.Pandoc.UTF8 as UTF8
4415
4516tests :: [Test]
4617tests = [ testGroup "markdown"
@@ -175,7 +146,7 @@ tests = [ testGroup "markdown"
175146
176147-- makes sure file is fully closed after reading
177148readFile' :: FilePath -> IO String
178−readFile' f = do s <- readFileUTF8 f
149+readFile' f = do s <- UTF8.readFile f
179150 return $! (length s `seq` s)
180151
181152lhsWriterTests :: String -> [Test]
@@ -242,15 +213,7 @@ testWithNormalize normalizer testname opts inp norm = testCase testname $ do
242213 -- find pandoc executable relative to test-pandoc
243214 -- First, try in same directory (e.g. if both in ~/.cabal/bin)
244215 -- Second, try ../pandoc (e.g. if in dist/XXX/build/test-pandoc)
245− pandocPath <- do
246− testExePath <- getExecutablePath
247− let testExeDir = takeDirectory testExePath
248− found <- doesFileExist (testExeDir </> "pandoc")
249− return $ if found
250− then testExeDir </> "pandoc"
251− else case splitDirectories testExeDir of
252− [] -> error "test-pandoc: empty testExeDir"
253− xs -> joinPath (init xs) </> "pandoc" </> "pandoc"
216+ pandocPath <- findPandoc
254217 (outputPath, hOut) <- openTempFile "" "pandoc-test"
255218 let inpPath = inp
256219 let normPath = norm