{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}module Utils whereimport GHCup.OptParse as GHCupimport Options.Applicativeimport Data.Bifunctorimport Test.Tastyimport Test.Tasty.HUnitimport Control.Monad.IO.ClassparseWith :: [String] -> IO CommandparseWith args = optCommand <$> handleParseResult (execParserPure defaultPrefs (info GHCup.opts fullDesc) args)padLeft :: Int -> String -> StringpadLeft desiredLength s = padding ++ s where padding = replicate (desiredLength - length s) ' 'mapSecond :: (b -> c) -> [(a,b)] -> [(a,c)]mapSecond = map . secondbuildTestTree :: (Eq a, Show a) => ([String] -> IO a) -- ^ The parse function -> (String, [(String, a)]) -- ^ The check list @(test group, [(cli command, expected value)])@ -> TestTreebuildTestTree parse (title, checkList) = testGroup title $ zipWith (uncurry . check) [1 :: Int ..] checkList where check idx args expected = testCase (padLeft 2 (show idx) ++ "." ++ args) $ do res <- parse (words args) liftIO $ res @?= expected