diff --git a/app/ghcup/GHCup/OptParse/GC.hs b/app/ghcup/GHCup/OptParse/GC.hs index 78ea706..2072287 100644 --- a/app/ghcup/GHCup/OptParse/GC.hs +++ b/app/ghcup/GHCup/OptParse/GC.hs @@ -47,7 +47,7 @@ data GCOptions = GCOptions , gcHLSNoGHC :: Bool , gcCache :: Bool , gcTmp :: Bool - } + } deriving (Eq, Show) diff --git a/app/ghcup/GHCup/OptParse/Run.hs b/app/ghcup/GHCup/OptParse/Run.hs index 0d9ad03..b46e058 100644 --- a/app/ghcup/GHCup/OptParse/Run.hs +++ b/app/ghcup/GHCup/OptParse/Run.hs @@ -68,7 +68,7 @@ data RunOptions = RunOptions , runBinDir :: Maybe FilePath , runQuick :: Bool , runCOMMAND :: [String] - } + } deriving (Eq, Show) diff --git a/ghcup.cabal b/ghcup.cabal index 26bee16..51fce99 100644 --- a/ghcup.cabal +++ b/ghcup.cabal @@ -428,6 +428,8 @@ test-suite ghcup-optparse-test UpgradeTest CompileTest WhereisTest + GCTest + RunTest default-language: Haskell2010 ghc-options: -Wall build-depends: base, ghcup, ghcup-optparse, tasty, tasty-hunit, optparse-applicative, versions, text, uri-bytestring diff --git a/test/optparse-test/GCTest.hs b/test/optparse-test/GCTest.hs new file mode 100644 index 0000000..aea524e --- /dev/null +++ b/test/optparse-test/GCTest.hs @@ -0,0 +1,42 @@ +module GCTest where + +import Test.Tasty +import GHCup.OptParse +import Utils + + +gcTests :: TestTree +gcTests = buildTestTree gcParseWith ("gc", gcCheckList) + +defaultOptions :: GCOptions +defaultOptions = + GCOptions + False + False + False + False + False + False + +gcCheckList :: [(String, GCOptions)] +gcCheckList = + [ ("gc", defaultOptions) + , ("gc -o", defaultOptions{gcOldGHC = True}) + , ("gc --ghc-old", defaultOptions{gcOldGHC = True}) + , ("gc -p", defaultOptions{gcProfilingLibs = True}) + , ("gc --profiling-libs", defaultOptions{gcProfilingLibs = True}) + , ("gc -s", defaultOptions{gcShareDir = True}) + , ("gc --share-dir", defaultOptions{gcShareDir = True}) + , ("gc -h", defaultOptions{gcHLSNoGHC = True}) + , ("gc --hls-no-ghc", defaultOptions{gcHLSNoGHC = True}) + , ("gc -c", defaultOptions{gcCache = True}) + , ("gc --cache", defaultOptions{gcCache = True}) + , ("gc -t", defaultOptions{gcTmp = True}) + , ("gc --tmpdirs", defaultOptions{gcTmp = True}) + , ("gc -o -p -s -h -c -t", GCOptions True True True True True True) + ] + +gcParseWith :: [String] -> IO GCOptions +gcParseWith args = do + GC a <- parseWith args + pure a diff --git a/test/optparse-test/Main.hs b/test/optparse-test/Main.hs index 1091c84..0430e36 100644 --- a/test/optparse-test/Main.hs +++ b/test/optparse-test/Main.hs @@ -12,6 +12,7 @@ import qualified ListTest import qualified UpgradeTest import qualified CompileTest import qualified WhereisTest +import qualified GCTest main :: IO () main = defaultMain $ testGroup "ghcup" @@ -26,4 +27,5 @@ main = defaultMain $ testGroup "ghcup" , UpgradeTest.upgradeTests , CompileTest.compileTests , WhereisTest.whereisTests + , GCTest.gcTests ] diff --git a/test/optparse-test/RunTest.hs b/test/optparse-test/RunTest.hs new file mode 100644 index 0000000..8655e3d --- /dev/null +++ b/test/optparse-test/RunTest.hs @@ -0,0 +1,31 @@ +module RunTest where + +import Test.Tasty +import GHCup.OptParse +import Utils + + +runTests :: TestTree +runTests = buildTestTree runParseWith ("run", runCheckList) + +defaultOptions :: RunOptions +defaultOptions = + RunOptions + False + False + False + Nothing + Nothing + Nothing + Nothing + Nothing + False + [] + +runCheckList :: [(String, RunOptions)] +runCheckList = [] + +runParseWith :: [String] -> IO RunOptions +runParseWith args = do + Run a <- parseWith args + pure a