diff --git a/app/ghcup/GHCup/OptParse/Upgrade.hs b/app/ghcup/GHCup/OptParse/Upgrade.hs index 8849700..1b71c78 100644 --- a/app/ghcup/GHCup/OptParse/Upgrade.hs +++ b/app/ghcup/GHCup/OptParse/Upgrade.hs @@ -50,7 +50,7 @@ import Data.Versions hiding (str) data UpgradeOpts = UpgradeInplace | UpgradeAt FilePath | UpgradeGHCupDir - deriving Show + deriving (Eq, Show) diff --git a/ghcup.cabal b/ghcup.cabal index c9672a4..c7b9d8b 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -425,6 +425,7 @@ test-suite ghcup-optparse-test UnsetTest RmTest ListTest + UpgradeTest default-language: Haskell2010 ghc-options: -Wall build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text, uri-bytestring diff --git a/test/optparse-test/Main.hs b/test/optparse-test/Main.hs index 8bacfb2..c15743a 100644 --- a/test/optparse-test/Main.hs +++ b/test/optparse-test/Main.hs @@ -9,6 +9,7 @@ import qualified InstallTest import qualified UnsetTest import qualified RmTest import qualified ListTest +import qualified UpgradeTest main :: IO () main = defaultMain $ testGroup "ghcup" @@ -20,4 +21,5 @@ main = defaultMain $ testGroup "ghcup" , UnsetTest.unsetTests , RmTest.rmTests , ListTest.listTests + , UpgradeTest.upgradeTests ] diff --git a/test/optparse-test/UpgradeTest.hs b/test/optparse-test/UpgradeTest.hs new file mode 100644 index 0000000..f54d2be --- /dev/null +++ b/test/optparse-test/UpgradeTest.hs @@ -0,0 +1,38 @@ +{-# LANGUAGE TupleSections #-} + +module UpgradeTest where + +import Test.Tasty +import GHCup.OptParse +import Utils + + +upgradeTests :: TestTree +upgradeTests = buildTestTree upgradeParseWith ("upgrade", upgradeCheckList) + +type FullUpgradeOpts = + ( UpgradeOpts + , Bool -- ^Force update + , Bool -- ^Fails after upgrading if the upgraded ghcup binary is shadowed by something else in PATH (useful for CI) + ) + +mkDefaultOptions :: UpgradeOpts -> FullUpgradeOpts +mkDefaultOptions = (, False, False) + +upgradeCheckList :: [(String, FullUpgradeOpts)] +upgradeCheckList = + [ ("upgrade", mkDefaultOptions UpgradeGHCupDir) + , ("upgrade -f", (UpgradeGHCupDir, True, False)) + , ("upgrade --force", (UpgradeGHCupDir, True, False)) + , ("upgrade --fail-if-shadowed", (UpgradeGHCupDir, False, True)) + , ("upgrade -i", mkDefaultOptions UpgradeInplace) + , ("upgrade --inplace", mkDefaultOptions UpgradeInplace) + , ("upgrade -t ~", mkDefaultOptions $ UpgradeAt "~") + , ("upgrade --target ~", mkDefaultOptions $ UpgradeAt "~") + , ("upgrade -t ~ -f", (UpgradeAt "~", True, False)) + ] + +upgradeParseWith :: [String] -> IO FullUpgradeOpts +upgradeParseWith args = do + Upgrade a b c <- parseWith args + pure (a, b, c)