aboutsummaryrefslogtreecommitdiff
path: root/test/test-pandoc.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2021-02-02 17:09:16 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2021-02-02 20:36:51 -0800
commit2415b2680a522e89b63abb370c02bfff54b824a2 (patch)
treed9a808794626c82c968334af97e51505d701ff22 /test/test-pandoc.hs
parentec8509295a8de19462ecd352a22b2784158e9ec6 (diff)
downloadpandoc-2415b2680a522e89b63abb370c02bfff54b824a2.tar.gz
Test suite: a more robust way of testing the executable.
Mmny of our tests require running the pandoc executable. This is problematic for a few different reasons. First, cabal-install will sometimes run the test suite after building the library but before building the executable, which means the executable isn't in place for the tests. One can work around that by first building, then building and running the tests, but that's fragile. Second, we have to find the executable. So far, we've done that using a function findPandoc that attempts to locate it relative to the test executable (which can be located using findExecutablePath). But the logic here is delicate and work with every combination of options. To solve both problems, we add an `--emulate` option to the `test-pandoc` executable. When `--emulate` occurs as the first argument passed to `test-pandoc`, the program simply emulates the regular pandoc executable, using the rest of the arguments (after `--emulate`). Thus, test-pandoc --emulate -f markdown -t latex is just like pandoc -f markdown -t latex Since all the work is done by library functions, implementing this emulation just takes a couple lines of code and should be entirely reliable. With this change, we can test the pandoc executable by running the test program itself (locatable using findExecutablePath) with the `--emulate` option. This removes the need for the fragile `findPandoc` step, and it means we can run our integration tests even when we're just building the library, not the executable. Part of this change involved simplifying some complex handling to set environment variables for dynamic library paths. I have tested a build with `--enable-dynamic-executable`, and it works, but further testing may be needed.
Diffstat (limited to 'test/test-pandoc.hs')
-rw-r--r--test/test-pandoc.hs25
1 files changed, 19 insertions, 6 deletions
diff --git a/test/test-pandoc.hs b/test/test-pandoc.hs
index bb4db90b9..9973dffc8 100644
--- a/test/test-pandoc.hs
+++ b/test/test-pandoc.hs
@@ -4,6 +4,12 @@
module Main where
import Prelude
+import System.Environment (getArgs)
+import qualified Control.Exception as E
+import Text.Pandoc.App (convertWithOpts, defaultOpts, options,
+ parseOptionsFromArgs)
+import Text.Pandoc.Error (handleError)
+import System.Environment.Executable (getExecutablePath)
import GHC.IO.Encoding
import Test.Tasty
import qualified Tests.Command
@@ -46,12 +52,11 @@ import qualified Tests.Writers.Powerpoint
import qualified Tests.Writers.RST
import qualified Tests.Writers.AnnotatedTable
import qualified Tests.Writers.TEI
-import Tests.Helpers (findPandoc)
import Text.Pandoc.Shared (inDirectory)
tests :: FilePath -> TestTree
tests pandocPath = testGroup "pandoc tests"
- [ Tests.Command.tests pandocPath
+ [ Tests.Command.tests
, testGroup "Old" (Tests.Old.tests pandocPath)
, testGroup "Shared" Tests.Shared.tests
, testGroup "Writers"
@@ -102,7 +107,15 @@ tests pandocPath = testGroup "pandoc tests"
main :: IO ()
main = do
setLocaleEncoding utf8
- inDirectory "test" $ do
- fp <- findPandoc
- putStrLn $ "Using pandoc executable at " ++ fp
- defaultMain $ tests fp
+ args <- getArgs
+ case args of
+ "--emulate":args' -> -- emulate pandoc executable
+ E.catch
+ (parseOptionsFromArgs options defaultOpts "pandoc" args' >>=
+ convertWithOpts)
+ (handleError . Left)
+ _ -> inDirectory "test" $ do
+ fp <- getExecutablePath
+ -- putStrLn $ "Using pandoc executable at " ++ fp
+ defaultMain $ tests fp
+