Skip to content

Commit

Permalink
Add cabal-doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jul 11, 2024
1 parent da742f2 commit edaef11
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/doctest.cabal linguist-generated=true
/ghci-wrapper/ghci-wrapper.cabal linguist-generated=true
doctest.cabal linguist-generated=true
30 changes: 30 additions & 0 deletions doctest.cabal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions driver/cabal-doctest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{-# LANGUAGE LambdaCase #-}
module Main (main) where

import Prelude

import Data.Version
import System.Environment
import System.Exit
import System.FilePath
import System.IO.Temp (withSystemTempDirectory)
import System.Process

import Paths_doctest (version)

main :: IO ()
main = do
args <- getArgs
lookupEnv "CABAL" >>= \ case
Nothing -> run "cabal" args
Just cabal -> run cabal (drop 1 args)

run :: String -> [String] -> IO ()
run cabal args = withSystemTempDirectory "doctest" $ \ dir -> do
let
doctest = dir </> "doctest"
script = dir </> "init-ghci"
callProcess cabal ["install", "--ignore-project", "--installdir=" <> dir, "--install-method=symlink", "doctest-" <> showVersion version]
callProcess (dir </> "doctest") ["--version"]
callProcess cabal ("build" : "--only-dependencies" : args)
writeFile script ":seti -w -Wdefault"
spawnProcess cabal ("repl"
: "--build-depends=QuickCheck"
: "--build-depends=template-haskell"
: "--repl-options=-ghci-script=" <> script
: "--with-ghc" : doctest
: args) >>= waitForProcess >>= exitWith
18 changes: 13 additions & 5 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,19 @@ library:
- Test.DocTest.Internal.Parse
- Test.DocTest.Internal.Run

executable:
main: Main.hs
ghc-options: -threaded
source-dirs: driver
dependencies: doctest
executables:
doctest:
main: Main.hs
ghc-options: -threaded
source-dirs: driver
dependencies: doctest

cabal-doctest:
main: cabal-doctest.hs
ghc-options: -threaded
source-dirs: driver
dependencies:
- temporary

tests:
spec:
Expand Down

0 comments on commit edaef11

Please sign in to comment.