@@ -1,46 +1,17 @@
1module Tests.Old (tests) where
1module Tests.Old (tests) where
3+import Tests.Helpers hiding (test)
3import Test.Framework (testGroup, Test )
4import Test.Framework (testGroup, Test )
4import Test.Framework.Providers.HUnit
5import Test.Framework.Providers.HUnit
5import Test.HUnit ( assertBool )
6import Test.HUnit ( assertBool )
6−import System.Environment.Executable (getExecutablePath)
7import System.IO ( openTempFile, stderr )
7import System.IO ( openTempFile, stderr )
8import System.Process ( runProcess, waitForProcess )
8import System.Process ( runProcess, waitForProcess )
9−import System.FilePath ( (</>), (<.>), takeDirectory, splitDirectories,
9+import System.FilePath ( (</>), (<.>), splitDirectories, joinPath )
11import System.Directory
10import System.Directory
12import System.Exit
11import System.Exit
13import Data.Algorithm.Diff
12import Data.Algorithm.Diff
14import Prelude hiding ( readFile )
13import Prelude hiding ( readFile )
15−import qualified Data.ByteString.Lazy as B
14+import qualified Text.Pandoc.UTF8 as UTF8
16−import Text.Pandoc.UTF8 (toStringLazy)
19−readFileUTF8 :: FilePath -> IO String
20−readFileUTF8 f = B.readFile f >>= return . toStringLazy
22−data TestResult = TestPassed
24− | TestFailed String FilePath [Diff String]
27−instance Show TestResult where
28− show TestPassed = "PASSED"
29− show (TestError ec) = "ERROR " ++ show ec
30− show (TestFailed cmd file d) = '\n' : dash ++
32− "\n+++ " ++ cmd ++ "\n" ++ showDiff (1,1) d ++
34− where dash = replicate 72 '-'
36−showDiff :: (Int,Int) -> [Diff String] -> String
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
45tests :: [Test]
16tests :: [Test]
46tests = [ testGroup "markdown"
17tests = [ testGroup "markdown"
@@ -175,7 +146,7 @@ tests = [ testGroup "markdown"
176-- makes sure file is fully closed after reading
147-- makes sure file is fully closed after reading
177readFile' :: FilePath -> IO String
148readFile' :: FilePath -> IO String
178−readFile' f = do s <- readFileUTF8 f
149+readFile' f = do s <- UTF8.readFile f
179 return $! (length s `seq` s)
150 return $! (length s `seq` s)
181lhsWriterTests :: String -> [Test]
152lhsWriterTests :: String -> [Test]
@@ -242,15 +213,7 @@ testWithNormalize normalizer testname opts inp norm = testCase testname $ do
242 -- find pandoc executable relative to test-pandoc
213 -- find pandoc executable relative to test-pandoc
243 -- First, try in same directory (e.g. if both in ~/.cabal/bin)
214 -- First, try in same directory (e.g. if both in ~/.cabal/bin)
244 -- Second, try ../pandoc (e.g. if in dist/XXX/build/test-pandoc)
215 -- Second, try ../pandoc (e.g. if in dist/XXX/build/test-pandoc)
245− pandocPath <- do
216+ pandocPath <- findPandoc
246− testExePath <- getExecutablePath
247− let testExeDir = takeDirectory testExePath
248− found <- doesFileExist (testExeDir </> "pandoc")
250− then testExeDir </> "pandoc"
251− else case splitDirectories testExeDir of
252− [] -> error "test-pandoc: empty testExeDir"
253− xs -> joinPath (init xs) </> "pandoc" </> "pandoc"
254 (outputPath, hOut) <- openTempFile "" "pandoc-test"
217 (outputPath, hOut) <- openTempFile "" "pandoc-test"
255 let inpPath = inp
218 let inpPath = inp
256 let normPath = norm
219 let normPath = norm