ghcup-hs/test/optparse-test/SetTest.hs

157 lines
5.3 KiB
Haskell
Raw Normal View History

2023-07-22 07:31:37 +00:00
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
2023-07-22 07:31:37 +00:00
module SetTest where
2023-07-22 15:10:27 +00:00
import GHCup.OptParse
2023-07-22 07:31:37 +00:00
import Test.Tasty
import GHCup.Types
import Data.Versions
import Data.List.NonEmpty (NonEmpty ((:|)))
2023-07-22 08:07:49 +00:00
import Utils
2023-07-22 07:31:37 +00:00
setTests :: TestTree
setTests =
testGroup "set"
$ map
2023-07-22 15:10:27 +00:00
(buildTestTree setParseWith)
2023-07-22 07:31:37 +00:00
[ ("old-style", oldStyleCheckList)
, ("ghc", setGhcCheckList)
, ("cabal", setCabalCheckList)
, ("hls", setHlsCheckList)
, ("stack", setStackCheckList)
]
oldStyleCheckList :: [(String, Either SetCommand SetOptions)]
oldStyleCheckList = mapSecond (Right . SetOptions)
[ ("set", SetRecommended)
, ("set ghc-9.2", SetGHCVersion
$ GHCTargetVersion
(Just "ghc")
2023-10-13 08:35:39 +00:00
$(versionQ "9.2")
2023-07-22 07:31:37 +00:00
)
, ("set next", SetNext)
, ("set latest", SetToolTag Latest)
, ("set nightly", SetGHCVersion
$ GHCTargetVersion
Nothing
2023-10-13 08:35:39 +00:00
$(versionQ "nightly")
2023-07-22 07:31:37 +00:00
)
-- different from `set`
, ("set recommended", SetToolTag Recommended)
, ("set prerelease", SetGHCVersion
$ GHCTargetVersion
Nothing
2023-10-13 08:35:39 +00:00
$(versionQ "prerelease")
2023-07-22 07:31:37 +00:00
)
, ("set latest-prerelease", SetToolTag LatestPrerelease)
, ("set latest-nightly", SetToolTag LatestNightly)
, ("set ghc-javascript-unknown-ghcjs-9.6", SetGHCVersion
$ GHCTargetVersion
(Just "ghc-javascript-unknown-ghcjs")
2023-10-13 08:35:39 +00:00
$(versionQ "9.6")
2023-07-22 07:31:37 +00:00
)
, ("set base-4.18", SetToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("set cabal-3.10", SetGHCVersion
$ GHCTargetVersion
(Just "cabal")
2023-10-13 08:35:39 +00:00
$(versionQ "3.10")
2023-07-22 07:31:37 +00:00
)
, ("set hls-2.0.0.0", SetGHCVersion
$ GHCTargetVersion
(Just "hls")
2023-10-13 08:35:39 +00:00
$(versionQ "2.0.0.0")
2023-07-22 07:31:37 +00:00
)
, ("set stack-2.9.3", SetGHCVersion
$ GHCTargetVersion
(Just "stack")
2023-10-13 08:35:39 +00:00
$(versionQ "2.9.3")
2023-07-22 07:31:37 +00:00
)
]
setGhcCheckList :: [(String, Either SetCommand SetOptions)]
setGhcCheckList = mapSecond (Left . SetGHC . SetOptions)
[ ("set ghc", SetRecommended)
, ("set ghc 9.2", SetGHCVersion
$ GHCTargetVersion
Nothing
2023-10-13 08:35:39 +00:00
$(versionQ "9.2")
2023-07-22 07:31:37 +00:00
)
, ("set ghc next", SetNext)
, ("set ghc latest", SetToolTag Latest)
, ("set ghc nightly", SetGHCVersion
$ GHCTargetVersion
Nothing
2023-10-13 08:35:39 +00:00
$(versionQ "nightly")
2023-07-22 07:31:37 +00:00
)
, ("set ghc recommended", SetToolTag Recommended)
, ("set ghc prerelease", SetGHCVersion
$ GHCTargetVersion
Nothing
2023-10-13 08:35:39 +00:00
$(versionQ "prerelease")
2023-07-22 07:31:37 +00:00
)
, ("set ghc latest-prerelease", SetToolTag LatestPrerelease)
, ("set ghc latest-nightly", SetToolTag LatestNightly)
, ("set ghc javascript-unknown-ghcjs-9.6", SetGHCVersion
$ GHCTargetVersion
(Just "javascript-unknown-ghcjs")
2023-10-13 08:35:39 +00:00
$(versionQ "9.6")
2023-07-22 07:31:37 +00:00
)
, ("set ghc base-4.18", SetToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("set ghc ghc-9.2", SetGHCVersion
$ GHCTargetVersion
(Just "ghc")
2023-10-13 08:35:39 +00:00
$(versionQ "9.2")
2023-07-22 07:31:37 +00:00
)
]
setCabalCheckList :: [(String, Either SetCommand SetOptions)]
setCabalCheckList = mapSecond (Left . SetCabal . SetOptions)
[ ("set cabal", SetRecommended)
2023-10-13 08:35:39 +00:00
, ("set cabal 3.10", SetToolVersion $(versionQ "3.10"))
2023-07-22 07:31:37 +00:00
, ("set cabal next", SetNext)
, ("set cabal latest", SetToolTag Latest)
2023-10-13 08:35:39 +00:00
, ("set cabal nightly", SetToolVersion $(versionQ "nightly"))
2023-07-22 07:31:37 +00:00
, ("set cabal recommended", SetToolTag Recommended)
2023-10-13 08:35:39 +00:00
, ("set cabal prerelease", SetToolVersion $(versionQ "prerelease"))
2023-07-22 07:31:37 +00:00
, ("set cabal latest-prerelease", SetToolTag LatestPrerelease)
, ("set cabal latest-nightly", SetToolTag LatestNightly)
, ("set cabal base-4.18", SetToolTag (Base (PVP {_pComponents = 4 :| [18]})))
2023-10-13 08:35:39 +00:00
, ("set cabal cabal-3.10", SetToolVersion $(versionQ "cabal-3.10"))
2023-07-22 07:31:37 +00:00
]
setHlsCheckList :: [(String, Either SetCommand SetOptions)]
setHlsCheckList = mapSecond (Left . SetHLS . SetOptions)
[ ("set hls", SetRecommended)
2023-10-13 08:35:39 +00:00
, ("set hls 2.0", SetToolVersion $(versionQ "2.0"))
2023-07-22 07:31:37 +00:00
, ("set hls next", SetNext)
, ("set hls latest", SetToolTag Latest)
2023-10-13 08:35:39 +00:00
, ("set hls nightly", SetToolVersion $(versionQ "nightly"))
2023-07-22 07:31:37 +00:00
, ("set hls recommended", SetToolTag Recommended)
2023-10-13 08:35:39 +00:00
, ("set hls prerelease", SetToolVersion $(versionQ "prerelease"))
2023-07-22 07:31:37 +00:00
, ("set hls latest-prerelease", SetToolTag LatestPrerelease)
, ("set hls latest-nightly", SetToolTag LatestNightly)
, ("set hls base-4.18", SetToolTag (Base (PVP {_pComponents = 4 :| [18]})))
2023-10-13 08:35:39 +00:00
, ("set hls hls-2.0", SetToolVersion $(versionQ "hls-2.0"))
2023-07-22 07:31:37 +00:00
]
setStackCheckList :: [(String, Either SetCommand SetOptions)]
setStackCheckList = mapSecond (Left . SetStack . SetOptions)
[ ("set stack", SetRecommended)
2023-10-13 08:35:39 +00:00
, ("set stack 2.9", SetToolVersion $(versionQ "2.9"))
2023-07-22 07:31:37 +00:00
, ("set stack next", SetNext)
, ("set stack latest", SetToolTag Latest)
2023-10-13 08:35:39 +00:00
, ("set stack nightly", SetToolVersion $(versionQ "nightly"))
2023-07-22 07:31:37 +00:00
, ("set stack recommended", SetToolTag Recommended)
2023-10-13 08:35:39 +00:00
, ("set stack prerelease", SetToolVersion $(versionQ "prerelease"))
2023-07-22 07:31:37 +00:00
, ("set stack latest-prerelease", SetToolTag LatestPrerelease)
, ("set stack latest-nightly", SetToolTag LatestNightly)
, ("set stack base-4.18", SetToolTag (Base (PVP {_pComponents = 4 :| [18]})))
2023-10-13 08:35:39 +00:00
, ("set stack stack-2.9", SetToolVersion $(versionQ "stack-2.9"))
2023-07-22 07:31:37 +00:00
]
setParseWith :: [String] -> IO (Either SetCommand SetOptions)
setParseWith args = do
Set a <- parseWith args
pure a