Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite for ghcup optparse #862

Merged
merged 25 commits into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
debug-info test
  • Loading branch information
July541 committed Jul 22, 2023
commit bcdf2b23f110fbe5ac502d025dc1021d86dbb4b3
2 changes: 2 additions & 0 deletions ghcup.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions test/optparse-test/DebugInfoTest.hs
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion test/optparse-test/Main.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module Main where
import Test.Tasty
import qualified SetTest
import qualified DebugInfoTest

main :: IO ()
main = defaultMain SetTest.setTests
main = defaultMain $ testGroup "ghcup"
[ SetTest.setTests
, DebugInfoTest.debugInfoTests
]
15 changes: 1 addition & 14 deletions test/optparse-test/SetTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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
17 changes: 17 additions & 0 deletions test/optparse-test/Utils.hs
Original file line number Diff line number Diff line change
@@ -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
Loading