debug-info test

This commit is contained in:
Lei Zhu 2023-07-22 16:07:49 +08:00
parent 83b82c328b
commit bcdf2b23f1
5 changed files with 43 additions and 15 deletions

View File

@ -417,6 +417,8 @@ test-suite ghcup-optparse-test
main-is: Main.hs main-is: Main.hs
other-modules: other-modules:
SetTest SetTest
Utils
DebugInfoTest
default-language: Haskell2010 default-language: Haskell2010
ghc-options: -Wall 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

View File

@ -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

View File

@ -1,6 +1,10 @@
module Main where module Main where
import Test.Tasty import Test.Tasty
import qualified SetTest import qualified SetTest
import qualified DebugInfoTest
main :: IO () main :: IO ()
main = defaultMain SetTest.setTests main = defaultMain $ testGroup "ghcup"
[ SetTest.setTests
, DebugInfoTest.debugInfoTests
]

View File

@ -5,12 +5,11 @@ module SetTest where
import GHCup.OptParse as GHCup import GHCup.OptParse as GHCup
import Test.Tasty import Test.Tasty
import Test.Tasty.HUnit import Test.Tasty.HUnit
import Options.Applicative
import Control.Monad.IO.Class (liftIO) import Control.Monad.IO.Class (liftIO)
import GHCup.Types import GHCup.Types
import Data.Versions import Data.Versions
import Data.List.NonEmpty (NonEmpty ((:|))) import Data.List.NonEmpty (NonEmpty ((:|)))
import Data.Bifunctor (second) import Utils
setTests :: TestTree setTests :: TestTree
setTests = setTests =
@ -190,15 +189,3 @@ setParseWith :: [String] -> IO (Either SetCommand SetOptions)
setParseWith args = do setParseWith args = do
Set a <- parseWith args Set a <- parseWith args
pure a 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

View File

@ -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