From cf1e8659b076942b9cb12b76367fa54fbfde05b7 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sun, 23 Jul 2023 15:41:27 +0800 Subject: [PATCH] unset test --- app/ghcup/GHCup/OptParse/UnSet.hs | 5 ++-- ghcup.cabal | 1 + test/optparse-test/Main.hs | 2 ++ test/optparse-test/UnsetTest.hs | 50 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 test/optparse-test/UnsetTest.hs diff --git a/app/ghcup/GHCup/OptParse/UnSet.hs b/app/ghcup/GHCup/OptParse/UnSet.hs index a3b33b7..313fcc9 100644 --- a/app/ghcup/GHCup/OptParse/UnSet.hs +++ b/app/ghcup/GHCup/OptParse/UnSet.hs @@ -48,6 +48,7 @@ data UnsetCommand = UnsetGHC UnsetOptions | UnsetCabal UnsetOptions | UnsetHLS UnsetOptions | UnsetStack UnsetOptions + deriving (Eq, Show) @@ -59,7 +60,7 @@ data UnsetCommand = UnsetGHC UnsetOptions data UnsetOptions = UnsetOptions { sToolVer :: Maybe T.Text -- target platform triple - } + } deriving (Eq, Show) @@ -68,7 +69,7 @@ data UnsetOptions = UnsetOptions --[ Parsers ]-- --------------- - + unsetParser :: Parser UnsetCommand unsetParser = subparser diff --git a/ghcup.cabal b/ghcup.cabal index 5bc4b80..04a4d9b 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -422,6 +422,7 @@ test-suite ghcup-optparse-test ChangeLogTest ConfigTest InstallTest + UnsetTest 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 ca877b6..51eb318 100644 --- a/test/optparse-test/Main.hs +++ b/test/optparse-test/Main.hs @@ -6,6 +6,7 @@ import qualified OtherCommandTest import qualified ChangeLogTest import qualified ConfigTest import qualified InstallTest +import qualified UnsetTest main :: IO () main = defaultMain $ testGroup "ghcup" @@ -14,4 +15,5 @@ main = defaultMain $ testGroup "ghcup" , ChangeLogTest.changeLogTests , ConfigTest.configTests , InstallTest.installTests + , UnsetTest.unsetTests ] diff --git a/test/optparse-test/UnsetTest.hs b/test/optparse-test/UnsetTest.hs new file mode 100644 index 0000000..be49fba --- /dev/null +++ b/test/optparse-test/UnsetTest.hs @@ -0,0 +1,50 @@ +{-# LANGUAGE OverloadedStrings #-} + +module UnsetTest where + +import Test.Tasty +import GHCup.OptParse +import Utils + + +unsetTests :: TestTree +unsetTests = + testGroup "unset" + $ map (buildTestTree unsetParseWith) + [ ("ghc", unsetGhcCheckList) + , ("cabal", unsetCabalCheckList) + , ("hls", unsetHlsCheckList) + , ("stack", unsetStackCheckList) + ] + +unsetGhcCheckList :: [(String, UnsetCommand)] +unsetGhcCheckList = mapSecond (UnsetGHC . UnsetOptions) + [ ("unset ghc", Nothing) + , ("unset ghc armv7-unknown-linux-gnueabihf", Just "armv7-unknown-linux-gnueabihf") + ] + +unsetCabalCheckList :: [(String, UnsetCommand)] +unsetCabalCheckList = mapSecond (UnsetCabal . UnsetOptions) + [ ("unset cabal", Nothing) + -- This never used + , ("unset cabal armv7-unknown-linux-gnueabihf", Just "armv7-unknown-linux-gnueabihf") + ] + +unsetHlsCheckList :: [(String, UnsetCommand)] +unsetHlsCheckList = mapSecond (UnsetHLS . UnsetOptions) + [ ("unset hls", Nothing) + -- This never used + , ("unset hls armv7-unknown-linux-gnueabihf", Just "armv7-unknown-linux-gnueabihf") + ] + +unsetStackCheckList :: [(String, UnsetCommand)] +unsetStackCheckList = mapSecond (UnsetStack . UnsetOptions) + [ ("unset stack", Nothing) + -- This never used + , ("unset stack armv7-unknown-linux-gnueabihf", Just "armv7-unknown-linux-gnueabihf") + ] + +unsetParseWith :: [String] -> IO UnsetCommand +unsetParseWith args = do + UnSet a <- parseWith args + pure a