Skip to content

Commit

Permalink
cabal-doctest: Add support for --with-compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
sol committed Jul 16, 2024
1 parent 332fcf8 commit 30bff0a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ externalCommand args = do
run :: String -> [String] -> IO ()
run cabal args = do

Paths{..} <- paths cabal
Paths{..} <- paths cabal args

let
doctest = cache </> "doctest" <> "-" <> Info.version
Expand Down Expand Up @@ -53,9 +53,10 @@ run cabal args = do
: "--build-depends=QuickCheck"
: "--build-depends=template-haskell"
: ("--repl-options=-ghci-script=" <> script)
: "--with-compiler" : doctest
: "--with-hc-pkg" : ghcPkg
: args) >>= waitForProcess >>= exitWith
: args ++ [
"--with-compiler", doctest
, "--with-hc-pkg", ghcPkg
]) >>= waitForProcess >>= exitWith

writeFileAtomically :: FilePath -> String -> IO ()
writeFileAtomically name contents = do
Expand Down
6 changes: 3 additions & 3 deletions src/Cabal/Paths.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ data Paths = Paths {
, cache :: FilePath
} deriving (Eq, Show)

paths :: FilePath -> IO Paths
paths cabal = do
paths :: FilePath -> [String] -> IO Paths
paths cabal args = do
cabalVersion <- strip <$> readProcess cabal ["--numeric-version"] ""

let
Expand All @@ -35,7 +35,7 @@ paths cabal = do
when (parseVersion cabalVersion < Just required) $ do
die $ "'cabal-install' version " <> showVersion required <> " or later is required, but 'cabal --numeric-version' returned " <> cabalVersion <> "."

values <- parseFields <$> readProcess cabal ["path", "-v0"] ""
values <- parseFields <$> readProcess cabal ("path" : args ++ ["-v0"]) ""

let
getPath :: String -> String -> IO FilePath
Expand Down
7 changes: 4 additions & 3 deletions test/Cabal/PathsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import Test.Hspec

import System.Directory

import Cabal ()
import Cabal.Paths

spec :: Spec
spec = do
describe "paths" $ do
it "returns the path to 'ghc'" $ do
(paths "cabal" >>= doesFileExist . ghc) `shouldReturn` True
(paths "cabal" [] >>= doesFileExist . ghc) `shouldReturn` True

it "returns the path to 'ghc-pkg'" $ do
(paths "cabal" >>= doesFileExist . ghcPkg) `shouldReturn` True
(paths "cabal" [] >>= doesFileExist . ghcPkg) `shouldReturn` True

it "returns the path to Cabal's cache directory" $ do
(paths "cabal" >>= doesDirectoryExist . cache) `shouldReturn` True
(paths "cabal" [] >>= doesDirectoryExist . cache) `shouldReturn` True

0 comments on commit 30bff0a

Please sign in to comment.