From dc1a813305b11a085f4bc3b1db585e01be36ea35 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 22 Jul 2023 17:46:23 +0800 Subject: [PATCH] config test --- app/ghcup/GHCup/OptParse/Config.hs | 1 + ghcup.cabal | 3 ++- test/optparse-test/ConfigTest.hs | 34 ++++++++++++++++++++++++++++++ test/optparse-test/Main.hs | 3 +++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/optparse-test/ConfigTest.hs diff --git a/app/ghcup/GHCup/OptParse/Config.hs b/app/ghcup/GHCup/OptParse/Config.hs index 07a3f76..6e71cd4 100644 --- a/app/ghcup/GHCup/OptParse/Config.hs +++ b/app/ghcup/GHCup/OptParse/Config.hs @@ -52,6 +52,7 @@ data ConfigCommand | SetConfig String (Maybe String) | InitConfig | AddReleaseChannel Bool URI + deriving (Eq, Show) diff --git a/ghcup.cabal b/ghcup.cabal index bb8bcc4..cf7b086 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -420,6 +420,7 @@ test-suite ghcup-optparse-test Utils OtherCommandTest ChangeLogTest + ConfigTest default-language: Haskell2010 ghc-options: -Wall - build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text + build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text, uri-bytestring diff --git a/test/optparse-test/ConfigTest.hs b/test/optparse-test/ConfigTest.hs new file mode 100644 index 0000000..6f8f658 --- /dev/null +++ b/test/optparse-test/ConfigTest.hs @@ -0,0 +1,34 @@ +{-# LANGUAGE QuasiQuotes #-} + +module ConfigTest where + +import Test.Tasty +import Test.Tasty.HUnit +import GHCup.OptParse +import Utils +import Control.Monad.IO.Class +import URI.ByteString.QQ + +configTests :: TestTree +configTests = testGroup "config" $ map (uncurry check) checkList + where + check :: String -> ConfigCommand -> TestTree + check args expected = testCase args $ do + res <- configParseWith (words args) + liftIO $ res @?= expected + +checkList :: [(String, ConfigCommand)] +checkList = + [ ("config", ShowConfig) + , ("config init", InitConfig) + , ("config show", ShowConfig) + , ("config add-release-channel https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml" + , AddReleaseChannel False [uri|https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.7.yaml|] + ) + , ("config set cache true", SetConfig "cache" (Just "true")) + ] + +configParseWith :: [String] -> IO ConfigCommand +configParseWith args = do + Config a <- parseWith args + pure a diff --git a/test/optparse-test/Main.hs b/test/optparse-test/Main.hs index a84fa0d..d75eb12 100644 --- a/test/optparse-test/Main.hs +++ b/test/optparse-test/Main.hs @@ -1,12 +1,15 @@ module Main where + import Test.Tasty import qualified SetTest import qualified OtherCommandTest import qualified ChangeLogTest +import qualified ConfigTest main :: IO () main = defaultMain $ testGroup "ghcup" [ SetTest.setTests , OtherCommandTest.otherCommandTests , ChangeLogTest.changeLogTests + , ConfigTest.configTests ]