Skip to content

Commit

Permalink
Split out DoctestOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Feb 10, 2019
1 parent e9adab1 commit eb12f2b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
36 changes: 22 additions & 14 deletions src/HaskellCI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ versionNumbers (Version vn _) = vn

#endif

-------------------------------------------------------------------------------
-- Microlens
-------------------------------------------------------------------------------

view :: Getting a s a -> s -> a
view l x = x ^. l

-------------------------------------------------------------------------------
-- Hardcoded values
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -811,10 +818,11 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa
]

-- Install doctest
let doctestConfig = cfgDoctest config
let doctestVersionConstraint
| isAnyVersion (cfgDoctestVersion config) = ""
| otherwise = " --constraint='doctest " ++ display (cfgDoctestVersion config) ++ "'"
when (cfgDoctest config) $ tellStrLns
| isAnyVersion (cfgDoctestVersion doctestConfig) = ""
| otherwise = " --constraint='doctest " ++ display (cfgDoctestVersion doctestConfig) ++ "'"
when (cfgDoctestEnabled doctestConfig) $ tellStrLns
[ sh $ "if [ $HCNUMVER -ge 80000 ]; then cabal new-install -w ${HC} -j2 --symlink-bindir=$HOME/.local/bin doctest" ++ doctestVersionConstraint ++ "; fi"
]

Expand Down Expand Up @@ -928,8 +936,8 @@ genTravisFromConfigs (argv,opts) xpkgs isCabalProject config prj@Project { prjPa

tellStrLns [""]

when (cfgDoctest config) $ do
let doctestOptions = unwords $ cfgDoctestOptions config
when (cfgDoctestEnabled doctestConfig) $ do
let doctestOptions = unwords $ cfgDoctestOptions doctestConfig
tellStrLns [ comment "doctest" ]
foldedTellStrLns FoldDoctest "Doctest..." folds $ do
forM_ pkgs $ \Pkg{pkgName,pkgGpd} -> do
Expand Down Expand Up @@ -1339,13 +1347,13 @@ options =
(reqArgReadP parseOptsQ (\xs cfg -> cfg { cfgLocalGhcOptions = xs }) "OPTIONS")
"--ghc-options for local packages"
, Option ['d'] ["doctest"]
(NoArg $ successCM $ \cfg -> cfg { cfgDoctest = True })
(NoArg $ successCM $ set (#cfgDoctest . #cfgDoctestEnabled) True)
"Run doctest using .ghc.environment files."
, Option [] ["doctest-options"]
(reqArgReadP parseOptsQ (\xs cfg -> cfg { cfgDoctestOptions = xs }) "OPTIONS")
(reqArgReadP parseOptsQ (set $ #cfgDoctest . #cfgDoctestOptions) "OPTIONS")
"Additional doctest options."
, Option [] ["doctest-version"]
(reqArgReadP parse (\arg cfg -> cfg { cfgDoctestVersion = arg }) "VERSION")
(reqArgReadP parse (set $ #cfgDoctest . #cfgDoctestVersion) "VERSION")
"Doctest version range"
, Option ['l'] ["hlint"]
(NoArg $ successCM $ \cfg -> cfg { cfgHLint = True })
Expand Down Expand Up @@ -1484,18 +1492,18 @@ configFieldDescrs =
(\x cfg -> cfg { cfgHLintVersion = x })
-- TODO: hlint-options
, PU.boolField "doctest"
cfgDoctest
(\b cfg -> cfg { cfgDoctest = b })
(view $ #cfgDoctest . #cfgDoctestEnabled)
(set $ #cfgDoctest . #cfgDoctestEnabled)
, PU.simpleField "doctest-options"
(error "we don't pretty print")
parseOptsQ
cfgDoctestOptions
(\x cfg -> cfg { cfgDoctestOptions = cfgDoctestOptions cfg ++ x })
(view $ #cfgDoctest . #cfgDoctestOptions)
(set $ #cfgDoctest . #cfgDoctestOptions)
, PU.simpleField "doctest-version"
(error "we don't pretty print")
parse
cfgDoctestVersion
(\x cfg -> cfg { cfgDoctestVersion = x })
(view $ #cfgDoctest . #cfgDoctestVersion)
(set $ #cfgDoctest . #cfgDoctestVersion)
, PU.simpleField "cabal-install-version"
(error "we don't pretty print")
(fmap Just parse)
Expand Down
20 changes: 14 additions & 6 deletions src/HaskellCI/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ data ConstraintSet = ConstraintSet
emptyConstraintSet :: String -> ConstraintSet
emptyConstraintSet n = ConstraintSet n anyVersion []

data DoctestConfig = DoctestConfig
{ cfgDoctestEnabled :: !Bool
, cfgDoctestOptions :: [String]
, cfgDoctestVersion :: !VersionRange
}
deriving (Show, Generic)

-- TODO: split other blocks like DoctestConfig
data Config = Config
{ cfgCabalInstallVersion :: Maybe Version
, cfgHLint :: !Bool
, cfgHLintYaml :: !(Maybe FilePath)
, cfgHLintVersion :: !VersionRange
, cfgHLintOptions :: [String]
, cfgJobs :: (Maybe Int, Maybe Int)
, cfgDoctest :: !Bool
, cfgDoctestOptions :: [String]
, cfgDoctestVersion :: !VersionRange
, cfgDoctest :: !DoctestConfig
, cfgLocalGhcOptions :: [String]
, cfgConstraintSets :: [ConstraintSet]
, cfgCache :: !Bool
Expand Down Expand Up @@ -69,9 +75,11 @@ emptyConfig = Config
, cfgHLintVersion = defaultHLintVersion
, cfgHLintOptions = []
, cfgJobs = (Nothing, Nothing)
, cfgDoctest = False
, cfgDoctestOptions = []
, cfgDoctestVersion = defaultDoctestVersion
, cfgDoctest = DoctestConfig
{ cfgDoctestEnabled = False
, cfgDoctestOptions = []
, cfgDoctestVersion = defaultDoctestVersion
}
, cfgLocalGhcOptions = []
, cfgConstraintSets = []
, cfgCache = True
Expand Down

0 comments on commit eb12f2b

Please sign in to comment.