From bcdf2b23f110fbe5ac502d025dc1021d86dbb4b3 Mon Sep 17 00:00:00 2001 From: Lei Zhu Date: Sat, 22 Jul 2023 16:07:49 +0800 Subject: [PATCH] debug-info test --- ghcup.cabal | 2 ++ test/optparse-test/DebugInfoTest.hs | 18 ++++++++++++++++++ test/optparse-test/Main.hs | 6 +++++- test/optparse-test/SetTest.hs | 15 +-------------- test/optparse-test/Utils.hs | 17 +++++++++++++++++ 5 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 test/optparse-test/DebugInfoTest.hs create mode 100644 test/optparse-test/Utils.hs diff --git a/ghcup.cabal b/ghcup.cabal index 49b79c2..1ecfcfb 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -417,6 +417,8 @@ test-suite ghcup-optparse-test main-is: Main.hs other-modules: SetTest + Utils + DebugInfoTest default-language: Haskell2010 ghc-options: -Wall build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text \ No newline at end of file diff --git a/test/optparse-test/DebugInfoTest.hs b/test/optparse-test/DebugInfoTest.hs new file mode 100644 index 0000000..719483e --- /dev/null +++ b/test/optparse-test/DebugInfoTest.hs @@ -0,0 +1,18 @@ +module DebugInfoTest where + +import Test.Tasty +import Test.Tasty.HUnit +import GHCup.OptParse +import Utils +import Control.Monad.IO.Class + +debugInfoTests :: TestTree +debugInfoTests = + testGroup "debug-info" $ pure + $ testCase "1. debug-info" $ do + res <- parseWith ["debug-info"] + liftIO $ assertBool "debug-info parse failed" (isDInfo res) + where + isDInfo :: Command -> Bool + isDInfo DInfo = True + isDInfo _ = False diff --git a/test/optparse-test/Main.hs b/test/optparse-test/Main.hs index e6059fc..4bc34e1 100644 --- a/test/optparse-test/Main.hs +++ b/test/optparse-test/Main.hs @@ -1,6 +1,10 @@ module Main where import Test.Tasty import qualified SetTest +import qualified DebugInfoTest main :: IO () -main = defaultMain SetTest.setTests \ No newline at end of file +main = defaultMain $ testGroup "ghcup" + [ SetTest.setTests + , DebugInfoTest.debugInfoTests + ] \ No newline at end of file diff --git a/test/optparse-test/SetTest.hs b/test/optparse-test/SetTest.hs index 18d0ec3..f39902b 100644 --- a/test/optparse-test/SetTest.hs +++ b/test/optparse-test/SetTest.hs @@ -5,12 +5,11 @@ module SetTest where import GHCup.OptParse as GHCup import Test.Tasty import Test.Tasty.HUnit -import Options.Applicative import Control.Monad.IO.Class (liftIO) import GHCup.Types import Data.Versions import Data.List.NonEmpty (NonEmpty ((:|))) -import Data.Bifunctor (second) +import Utils setTests :: TestTree setTests = @@ -190,15 +189,3 @@ setParseWith :: [String] -> IO (Either SetCommand SetOptions) setParseWith args = do Set a <- parseWith args pure a - -parseWith :: [String] -> IO Command -parseWith args = - optCommand <$> handleParseResult - (execParserPure defaultPrefs (info GHCup.opts fullDesc) args) - -padLeft :: Int -> String -> String -padLeft desiredLength s = padding ++ s - where padding = replicate (desiredLength - length s) ' ' - -mapSecond :: (b -> c) -> [(a,b)] -> [(a,c)] -mapSecond = map . second diff --git a/test/optparse-test/Utils.hs b/test/optparse-test/Utils.hs new file mode 100644 index 0000000..7874f2c --- /dev/null +++ b/test/optparse-test/Utils.hs @@ -0,0 +1,17 @@ +module Utils where + +import GHCup.OptParse as GHCup +import Options.Applicative +import Data.Bifunctor + +parseWith :: [String] -> IO Command +parseWith args = + optCommand <$> handleParseResult + (execParserPure defaultPrefs (info GHCup.opts fullDesc) args) + +padLeft :: Int -> String -> String +padLeft desiredLength s = padding ++ s + where padding = replicate (desiredLength - length s) ' ' + +mapSecond :: (b -> c) -> [(a,b)] -> [(a,c)] +mapSecond = map . second