list test

This commit is contained in:
Lei Zhu 2023-07-23 23:51:03 +08:00
parent c92875882a
commit f400f43b8c
5 changed files with 41 additions and 2 deletions

View File

@ -58,7 +58,7 @@ data ListOptions = ListOptions
, lHideOld :: Bool , lHideOld :: Bool
, lShowNightly :: Bool , lShowNightly :: Bool
, lRawFormat :: Bool , lRawFormat :: Bool
} } deriving (Eq, Show)

View File

@ -424,6 +424,7 @@ test-suite ghcup-optparse-test
InstallTest InstallTest
UnsetTest UnsetTest
RmTest RmTest
ListTest
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, uri-bytestring build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text, uri-bytestring

View File

@ -65,7 +65,7 @@ import qualified Data.Text as T
data ListCriteria = ListInstalled Bool data ListCriteria = ListInstalled Bool
| ListSet Bool | ListSet Bool
| ListAvailable Bool | ListAvailable Bool
deriving Show deriving (Eq, Show)
-- | A list result describes a single tool version -- | A list result describes a single tool version
-- and various of its properties. -- and various of its properties.

View File

@ -0,0 +1,36 @@
module ListTest where
import Test.Tasty
import GHCup.OptParse
import Utils
import GHCup.List
import GHCup.Types
listTests :: TestTree
listTests = buildTestTree listParseWith ("list", listCheckList)
defaultOptions :: ListOptions
defaultOptions = ListOptions Nothing Nothing Nothing Nothing False False False
listCheckList :: [(String, ListOptions)]
listCheckList =
[ ("list", defaultOptions)
, ("list -t ghc", defaultOptions{loTool = Just GHC})
, ("list -t cabal", defaultOptions{loTool = Just Cabal})
, ("list -t hls", defaultOptions{loTool = Just HLS})
, ("list -t stack", defaultOptions{loTool = Just Stack})
, ("list -c installed", defaultOptions{lCriteria = Just $ ListInstalled True})
, ("list -c +installed", defaultOptions{lCriteria = Just $ ListInstalled True})
, ("list -c -installed", defaultOptions{lCriteria = Just $ ListInstalled False})
, ("list -c set", defaultOptions{lCriteria = Just $ ListSet True})
, ("list -c +set", defaultOptions{lCriteria = Just $ ListSet True})
, ("list -c -set", defaultOptions{lCriteria = Just $ ListSet False})
, ("list -c available", defaultOptions{lCriteria = Just $ ListAvailable True})
, ("list -c +available", defaultOptions{lCriteria = Just $ ListAvailable True})
, ("list -c -available", defaultOptions{lCriteria = Just $ ListAvailable False})
]
listParseWith :: [String] -> IO ListOptions
listParseWith args = do
List a <- parseWith args
pure a

View File

@ -8,6 +8,7 @@ import qualified ConfigTest
import qualified InstallTest import qualified InstallTest
import qualified UnsetTest import qualified UnsetTest
import qualified RmTest import qualified RmTest
import qualified ListTest
main :: IO () main :: IO ()
main = defaultMain $ testGroup "ghcup" main = defaultMain $ testGroup "ghcup"
@ -18,4 +19,5 @@ main = defaultMain $ testGroup "ghcup"
, InstallTest.installTests , InstallTest.installTests
, UnsetTest.unsetTests , UnsetTest.unsetTests
, RmTest.rmTests , RmTest.rmTests
, ListTest.listTests
] ]