diff --git a/app/ghcup/GHCup/OptParse/List.hs b/app/ghcup/GHCup/OptParse/List.hs index 56a6c0f..3989adc 100644 --- a/app/ghcup/GHCup/OptParse/List.hs +++ b/app/ghcup/GHCup/OptParse/List.hs @@ -58,7 +58,7 @@ data ListOptions = ListOptions , lHideOld :: Bool , lShowNightly :: Bool , lRawFormat :: Bool - } + } deriving (Eq, Show) diff --git a/ghcup.cabal b/ghcup.cabal index 03d0b47..c9672a4 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -424,6 +424,7 @@ test-suite ghcup-optparse-test InstallTest UnsetTest RmTest + ListTest default-language: Haskell2010 ghc-options: -Wall build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text, uri-bytestring diff --git a/lib/GHCup/List.hs b/lib/GHCup/List.hs index 3d38880..afe1d6d 100644 --- a/lib/GHCup/List.hs +++ b/lib/GHCup/List.hs @@ -65,7 +65,7 @@ import qualified Data.Text as T data ListCriteria = ListInstalled Bool | ListSet Bool | ListAvailable Bool - deriving Show + deriving (Eq, Show) -- | A list result describes a single tool version -- and various of its properties. diff --git a/test/optparse-test/ListTest.hs b/test/optparse-test/ListTest.hs new file mode 100644 index 0000000..670426d --- /dev/null +++ b/test/optparse-test/ListTest.hs @@ -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 diff --git a/test/optparse-test/Main.hs b/test/optparse-test/Main.hs index 9e26b0d..8bacfb2 100644 --- a/test/optparse-test/Main.hs +++ b/test/optparse-test/Main.hs @@ -8,6 +8,7 @@ import qualified ConfigTest import qualified InstallTest import qualified UnsetTest import qualified RmTest +import qualified ListTest main :: IO () main = defaultMain $ testGroup "ghcup" @@ -18,4 +19,5 @@ main = defaultMain $ testGroup "ghcup" , InstallTest.installTests , UnsetTest.unsetTests , RmTest.rmTests + , ListTest.listTests ]