Skip to content

Commit

Permalink
refactor: use upstream TH constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
fosskers committed Oct 13, 2023
1 parent 28cb015 commit cc7cc8c
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 101 deletions.
5 changes: 3 additions & 2 deletions test/optparse-test/ChangeLogTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Utils
import Test.Tasty.HUnit
import Control.Monad.IO.Class
import GHCup.Types
import Data.Versions (versionQ)

changeLogTests :: TestTree
changeLogTests = testGroup "changelog" $ map (uncurry check) checkList
Expand All @@ -31,15 +32,15 @@ checkList =
(Just $ GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "9.2"))
$(versionQ "9.2"))
)
, ("changelog recommended", ChangeLogOptions False Nothing (Just $ ToolTag Recommended))
, ("changelog -t cabal recommended", ChangeLogOptions False (Just Cabal) (Just $ ToolTag Recommended))
, ("changelog -t cabal 3.10.1.0", ChangeLogOptions False (Just Cabal)
(Just $ GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "3.10.1.0"))
$(versionQ "3.10.1.0"))
)
, ("changelog 2023-07-22", ChangeLogOptions False Nothing (Just (ToolDay (read "2023-07-22"))))
]
Expand Down
26 changes: 13 additions & 13 deletions test/optparse-test/CompileTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ compileGhcCheckList = mapSecond CompileGHC
[ ("compile ghc -v 9.4.5 -b 9.2.8", baseOptions)
, ("compile ghc -g a32db0b -b 9.2.8", mkDefaultGHCCompileOptions
(GHC.GitDist $ GitBranch "a32db0b" Nothing)
(Left $(verQ "9.2.8"))
(Left $(versionQ "9.2.8"))
)
, ("compile ghc -g a32db0b -b 9.2.8 -r https://gitlab.haskell.org/ghc/ghc.git",
mkDefaultGHCCompileOptions
(GHC.GitDist $ GitBranch "a32db0b" (Just "https://gitlab.haskell.org/ghc/ghc.git"))
(Left $(verQ "9.2.8"))
(Left $(versionQ "9.2.8"))
)
, ("compile ghc -g a32db0b -r https://gitlab.haskell.org/ghc/ghc.git -b /usr/bin/ghc-9.2.2",
mkDefaultGHCCompileOptions
Expand All @@ -74,7 +74,7 @@ compileGhcCheckList = mapSecond CompileGHC
)
, ("compile ghc --remote-source-dist https://gitlab.haskell.org/ghc/ghc.git -b 9.2.8", mkDefaultGHCCompileOptions
(GHC.RemoteDist [uri|https://gitlab.haskell.org/ghc/ghc.git|])
(Left $(verQ "9.2.8"))
(Left $(versionQ "9.2.8"))
)
, (baseCmd <> "-j20", baseOptions{GHC.jobs = Just 20})
, (baseCmd <> "--jobs 10", baseOptions{GHC.jobs = Just 10})
Expand All @@ -87,8 +87,8 @@ compileGhcCheckList = mapSecond CompileGHC
, (baseCmd <> "--cross-target armv7-unknown-linux-gnueabihf", baseOptions{GHC.crossTarget = Just "armv7-unknown-linux-gnueabihf"})
, (baseCmd <> "-- --enable-unregisterised", baseOptions{GHC.addConfArgs = ["--enable-unregisterised"]})
, (baseCmd <> "--set", baseOptions{GHC.setCompile = True})
, (baseCmd <> "-o 9.4.5-p1", baseOptions{GHC.ovewrwiteVer = Just $(verQ "9.4.5-p1")})
, (baseCmd <> "--overwrite-version 9.4.5-p1", baseOptions{GHC.ovewrwiteVer = Just $(verQ "9.4.5-p1")})
, (baseCmd <> "-o 9.4.5-p1", baseOptions{GHC.ovewrwiteVer = Just $(versionQ "9.4.5-p1")})
, (baseCmd <> "--overwrite-version 9.4.5-p1", baseOptions{GHC.ovewrwiteVer = Just $(versionQ "9.4.5-p1")})
, (baseCmd <> "-f make", baseOptions{GHC.buildFlavour = Just "make"})
, (baseCmd <> "--flavour make", baseOptions{GHC.buildFlavour = Just "make"})
, (baseCmd <> "--hadrian", baseOptions{GHC.buildSystem = Just Hadrian})
Expand All @@ -108,8 +108,8 @@ compileGhcCheckList = mapSecond CompileGHC
baseOptions :: GHCCompileOptions
baseOptions =
mkDefaultGHCCompileOptions
(GHC.SourceDist $(verQ "9.4.5"))
(Left $(verQ "9.2.8"))
(GHC.SourceDist $(versionQ "9.4.5"))
(Left $(versionQ "9.2.8"))

compileHlsCheckList :: [(String, CompileCommand)]
compileHlsCheckList = mapSecond CompileHLS
Expand Down Expand Up @@ -137,7 +137,7 @@ compileHlsCheckList = mapSecond CompileHLS
)
, ("compile hls --source-dist 2.0.0.0 --ghc 9.2.8",
mkDefaultHLSCompileOptions
(HLS.SourceDist $(verQ "2.0.0.0"))
(HLS.SourceDist $(versionQ "2.0.0.0"))
[ghc928]
)
, ("compile hls --remote-source-dist https://github.com/haskell/haskell-language-server/archive/refs/tags/2.0.0.1.tar.gz --ghc 9.2.8",
Expand All @@ -147,15 +147,15 @@ compileHlsCheckList = mapSecond CompileHLS
)
, ("compile hls -v 2.0.0.0 --ghc latest",
mkDefaultHLSCompileOptions
(HLS.HackageDist $(verQ "2.0.0.0"))
(HLS.HackageDist $(versionQ "2.0.0.0"))
[ToolTag Latest]
)
, (baseCmd <> "-j20", baseOptions{HLS.jobs = Just 20})
, (baseCmd <> "--jobs 10", baseOptions{HLS.jobs = Just 10})
, (baseCmd <> "--no-set", baseOptions{HLS.setCompile = False})
, (baseCmd <> "--cabal-update", baseOptions{HLS.updateCabal = True})
, (baseCmd <> "-o 2.0.0.0-p1", baseOptions{HLS.ovewrwiteVer = Right $(verQ "2.0.0.0-p1")})
, (baseCmd <> "--overwrite-version 2.0.0.0-p1", baseOptions{HLS.ovewrwiteVer = Right $(verQ "2.0.0.0-p1")})
, (baseCmd <> "-o 2.0.0.0-p1", baseOptions{HLS.ovewrwiteVer = Right $(versionQ "2.0.0.0-p1")})
, (baseCmd <> "--overwrite-version 2.0.0.0-p1", baseOptions{HLS.ovewrwiteVer = Right $(versionQ "2.0.0.0-p1")})
, (baseCmd <> "--git-describe-version", baseOptions{HLS.ovewrwiteVer = Left True})
#ifdef IS_WINDOWS
, (baseCmd <> "-i C:\\\\tmp\\out_dir", baseOptions{HLS.isolateDir = Just "C:\\\\tmp\\out_dir"})
Expand All @@ -179,11 +179,11 @@ compileHlsCheckList = mapSecond CompileHLS
baseOptions :: HLSCompileOptions
baseOptions =
mkDefaultHLSCompileOptions
(HLS.HackageDist $(verQ "2.0.0.0"))
(HLS.HackageDist $(versionQ "2.0.0.0"))
[ghc928]

ghc928 :: ToolVersion
ghc928 = GHCVersion $ GHCTargetVersion Nothing $(verQ "9.2.8")
ghc928 = GHCVersion $ GHCTargetVersion Nothing $(versionQ "9.2.8")

compileParseWith :: [String] -> IO CompileCommand
compileParseWith args = do
Expand Down
60 changes: 30 additions & 30 deletions test/optparse-test/InstallTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,56 +55,56 @@ oldStyleCheckList =
: ("install -u https://gitlab.haskell.org/ghc/ghc/-/jobs/artifacts/master/raw/ghc-x86_64-linux-fedora33-release.tar.xz head"
, Right defaultOptions
{ instBindist = Just [uri|https://gitlab.haskell.org/ghc/ghc/-/jobs/artifacts/master/raw/ghc-x86_64-linux-fedora33-release.tar.xz|]
, instVer = Just $ GHCVersion $ GHCTargetVersion Nothing $(verQ "head")
, instVer = Just $ GHCVersion $ GHCTargetVersion Nothing $(versionQ "head")
}
)
: mapSecond
(Right . mkInstallOptions)
[ ("install ghc-9.2", GHCVersion
$ GHCTargetVersion
(Just "ghc")
$(verQ "9.2")
$(versionQ "9.2")
)
-- invalid
, ("install next", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "next")
$(versionQ "next")
)
, ("install latest", ToolTag Latest)
, ("install nightly", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "nightly")
$(versionQ "nightly")
)
, ("install recommended", ToolTag Recommended)
, ("install prerelease", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "prerelease")
$(versionQ "prerelease")
)
, ("install latest-prerelease", ToolTag LatestPrerelease)
, ("install latest-nightly", ToolTag LatestNightly)
, ("install ghc-javascript-unknown-ghcjs-9.6", GHCVersion
$ GHCTargetVersion
(Just "ghc-javascript-unknown-ghcjs")
$(verQ "9.6")
$(versionQ "9.6")
)
, ("install base-4.18", ToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("install cabal-3.10", GHCVersion
$ GHCTargetVersion
(Just "cabal")
$(verQ "3.10")
$(versionQ "3.10")
)
, ("install hls-2.0.0.0", GHCVersion
$ GHCTargetVersion
(Just "hls")
$(verQ "2.0.0.0")
$(versionQ "2.0.0.0")
)
, ("install stack-2.9.3", GHCVersion
$ GHCTargetVersion
(Just "stack")
$(verQ "2.9.3")
$(versionQ "2.9.3")
)
]

Expand All @@ -115,86 +115,86 @@ installGhcCheckList =
[ ("install ghc 9.2", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "9.2")
$(versionQ "9.2")
)
, ("install ghc next", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "next")
$(versionQ "next")
)
, ("install ghc latest", ToolTag Latest)
, ("install ghc nightly", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "nightly")
$(versionQ "nightly")
)
, ("install ghc recommended", ToolTag Recommended)
, ("install ghc prerelease", GHCVersion
$ GHCTargetVersion
Nothing
$(verQ "prerelease")
$(versionQ "prerelease")
)
, ("install ghc latest-prerelease", ToolTag LatestPrerelease)
, ("install ghc latest-nightly", ToolTag LatestNightly)
, ("install ghc javascript-unknown-ghcjs-9.6", GHCVersion
$ GHCTargetVersion
(Just "javascript-unknown-ghcjs")
$(verQ "9.6")
$(versionQ "9.6")
)
, ("install ghc base-4.18", ToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("install ghc ghc-9.2", GHCVersion
$ GHCTargetVersion
(Just "ghc")
$(verQ "9.2")
$(versionQ "9.2")
)
]

installCabalCheckList :: [(String, Either InstallCommand InstallOptions)]
installCabalCheckList =
("install cabal", Left $ InstallCabal defaultOptions{instSet = True})
: mapSecond (Left . InstallCabal . mkInstallOptions')
[ ("install cabal 3.10", ToolVersion $(verQ "3.10"))
, ("install cabal next", ToolVersion $(verQ "next"))
[ ("install cabal 3.10", ToolVersion $(versionQ "3.10"))
, ("install cabal next", ToolVersion $(versionQ "next"))
, ("install cabal latest", ToolTag Latest)
, ("install cabal nightly", ToolVersion $(verQ "nightly"))
, ("install cabal nightly", ToolVersion $(versionQ "nightly"))
, ("install cabal recommended", ToolTag Recommended)
, ("install cabal prerelease", ToolVersion $(verQ "prerelease"))
, ("install cabal prerelease", ToolVersion $(versionQ "prerelease"))
, ("install cabal latest-prerelease", ToolTag LatestPrerelease)
, ("install cabal latest-nightly", ToolTag LatestNightly)
, ("install cabal base-4.18", ToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("install cabal cabal-3.10", ToolVersion $(verQ "cabal-3.10"))
, ("install cabal cabal-3.10", ToolVersion $(versionQ "cabal-3.10"))
]

installHlsCheckList :: [(String, Either InstallCommand InstallOptions)]
installHlsCheckList =
("install hls", Left $ InstallHLS defaultOptions{instSet = True})
: mapSecond (Left . InstallHLS . mkInstallOptions')
[ ("install hls 3.10", ToolVersion $(verQ "3.10"))
, ("install hls next", ToolVersion $(verQ "next"))
[ ("install hls 3.10", ToolVersion $(versionQ "3.10"))
, ("install hls next", ToolVersion $(versionQ "next"))
, ("install hls latest", ToolTag Latest)
, ("install hls nightly", ToolVersion $(verQ "nightly"))
, ("install hls nightly", ToolVersion $(versionQ "nightly"))
, ("install hls recommended", ToolTag Recommended)
, ("install hls prerelease", ToolVersion $(verQ "prerelease"))
, ("install hls prerelease", ToolVersion $(versionQ "prerelease"))
, ("install hls latest-prerelease", ToolTag LatestPrerelease)
, ("install hls latest-nightly", ToolTag LatestNightly)
, ("install hls base-4.18", ToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("install hls hls-2.0", ToolVersion $(verQ "hls-2.0"))
, ("install hls hls-2.0", ToolVersion $(versionQ "hls-2.0"))
]

installStackCheckList :: [(String, Either InstallCommand InstallOptions)]
installStackCheckList =
("install stack", Left $ InstallStack defaultOptions{instSet = True})
: mapSecond (Left . InstallStack . mkInstallOptions')
[ ("install stack 3.10", ToolVersion $(verQ "3.10"))
, ("install stack next", ToolVersion $(verQ "next"))
[ ("install stack 3.10", ToolVersion $(versionQ "3.10"))
, ("install stack next", ToolVersion $(versionQ "next"))
, ("install stack latest", ToolTag Latest)
, ("install stack nightly", ToolVersion $(verQ "nightly"))
, ("install stack nightly", ToolVersion $(versionQ "nightly"))
, ("install stack recommended", ToolTag Recommended)
, ("install stack prerelease", ToolVersion $(verQ "prerelease"))
, ("install stack prerelease", ToolVersion $(versionQ "prerelease"))
, ("install stack latest-prerelease", ToolTag LatestPrerelease)
, ("install stack latest-nightly", ToolTag LatestNightly)
, ("install stack base-4.18", ToolTag (Base (PVP {_pComponents = 4 :| [18]})))
, ("install stack stack-2.9", ToolVersion $(verQ "stack-2.9"))
, ("install stack stack-2.9", ToolVersion $(versionQ "stack-2.9"))
]

installParseWith :: [String] -> IO (Either InstallCommand InstallOptions)
Expand Down
21 changes: 10 additions & 11 deletions test/optparse-test/RmTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Test.Tasty
import GHCup.OptParse
import Utils
import GHCup.Types
import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.Versions


Expand All @@ -25,36 +24,36 @@ rmTests =
oldStyleCheckList :: [(String, Either RmCommand RmOptions)]
oldStyleCheckList = mapSecond (Right . RmOptions)
[ -- failed with ("rm", xxx)
("rm 9.2.8", mkTVer $(verQ "9.2.8"))
, ("rm ghc-9.2.8", GHCTargetVersion (Just "ghc") $(verQ "9.2.8"))
("rm 9.2.8", mkTVer $(versionQ "9.2.8"))
, ("rm ghc-9.2.8", GHCTargetVersion (Just "ghc") $(versionQ "9.2.8"))
]

rmGhcCheckList :: [(String, Either RmCommand RmOptions)]
rmGhcCheckList = mapSecond (Left . RmGHC . RmOptions)
[ -- failed with ("rm ghc", xxx)
("rm ghc 9.2.8", mkTVer $(verQ "9.2.8"))
, ("rm ghc ghc-9.2.8", GHCTargetVersion (Just "ghc") $(verQ "9.2.8"))
("rm ghc 9.2.8", mkTVer $(versionQ "9.2.8"))
, ("rm ghc ghc-9.2.8", GHCTargetVersion (Just "ghc") $(versionQ "9.2.8"))
]

rmCabalCheckList :: [(String, Either RmCommand RmOptions)]
rmCabalCheckList = mapSecond (Left . RmCabal)
[ -- failed with ("rm cabal", xxx)
("rm cabal 3.10", $(verQ "3.10"))
, ("rm cabal cabal-3.10", $(verQ "cabal-3.10"))
("rm cabal 3.10", $(versionQ "3.10"))
, ("rm cabal cabal-3.10", $(versionQ "cabal-3.10"))
]

rmHlsCheckList :: [(String, Either RmCommand RmOptions)]
rmHlsCheckList = mapSecond (Left . RmHLS)
[ -- failed with ("rm hls", xxx)
("rm hls 2.0", $(verQ "2.0"))
, ("rm hls hls-2.0", $(verQ "hls-2.0"))
("rm hls 2.0", $(versionQ "2.0"))
, ("rm hls hls-2.0", $(versionQ "hls-2.0"))
]

rmStackCheckList :: [(String, Either RmCommand RmOptions)]
rmStackCheckList = mapSecond (Left . RmStack)
[ -- failed with ("rm stack", xxx)
("rm stack 2.9.1", $(verQ "2.9.1"))
, ("rm stack stack-2.9.1", $(verQ "stack-2.9.1"))
("rm stack 2.9.1", $(versionQ "2.9.1"))
, ("rm stack stack-2.9.1", $(versionQ "stack-2.9.1"))
]

rmParseWith :: [String] -> IO (Either RmCommand RmOptions)
Expand Down
15 changes: 8 additions & 7 deletions test/optparse-test/RunTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Test.Tasty
import GHCup.OptParse
import Utils
import GHCup.Types
import Data.Versions (versionQ)


runTests :: TestTree
Expand Down Expand Up @@ -36,11 +37,11 @@ runCheckList =
, ("run --install", defaultOptions{runInstTool' = True})
, ("run -m", defaultOptions{runMinGWPath = True})
, ("run --mingw-path", defaultOptions{runMinGWPath = True})
, ("run --ghc 9.2.8", defaultOptions{runGHCVer = Just $ GHCVersion $ mkTVer $(verQ "9.2.8")})
, ("run --ghc 9.2.8", defaultOptions{runGHCVer = Just $ GHCVersion $ mkTVer $(versionQ "9.2.8")})
, ("run --ghc latest", defaultOptions{runGHCVer = Just $ ToolTag Latest})
, ("run --cabal 3.10", defaultOptions{runCabalVer = Just $ ToolVersion $(verQ "3.10")})
, ("run --hls 2.0", defaultOptions{runHLSVer = Just $ ToolVersion $(verQ "2.0")})
, ("run --stack 2.9", defaultOptions{runStackVer = Just $ ToolVersion $(verQ "2.9") })
, ("run --cabal 3.10", defaultOptions{runCabalVer = Just $ ToolVersion $(versionQ "3.10")})
, ("run --hls 2.0", defaultOptions{runHLSVer = Just $ ToolVersion $(versionQ "2.0")})
, ("run --stack 2.9", defaultOptions{runStackVer = Just $ ToolVersion $(versionQ "2.9") })
#ifdef IS_WINDOWS
, ("run -b C:\\\\tmp\\dir", defaultOptions{runBinDir = Just "C:\\\\tmp\\dir"})
, ("run --bindir C:\\\\tmp\\dir", defaultOptions{runBinDir = Just "C:\\\\tmp\\dir"})
Expand All @@ -53,9 +54,9 @@ runCheckList =
, ("run --ghc latest --cabal 3.10 --stack 2.9 --hls 2.0 --install",
defaultOptions
{ runGHCVer = Just $ ToolTag Latest
, runCabalVer = Just $ ToolVersion $(verQ "3.10")
, runHLSVer = Just $ ToolVersion $(verQ "2.0")
, runStackVer = Just $ ToolVersion $(verQ "2.9")
, runCabalVer = Just $ ToolVersion $(versionQ "3.10")
, runHLSVer = Just $ ToolVersion $(versionQ "2.0")
, runStackVer = Just $ ToolVersion $(versionQ "2.9")
, runInstTool' = True
}
)
Expand Down
Loading

0 comments on commit cc7cc8c

Please sign in to comment.