-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property confirming the parse of the command line args
- Loading branch information
1 parent
0ff4ad9
commit 13ab6a0
Showing
6 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# OPTIONS_GHC -Wno-deferred-out-of-scope-variables #-} | ||
|
||
{- | | ||
Module : MemInfo.ChoicesSpec | ||
Copyright : (c) 2023 Tim Emiola | ||
Maintainer : Tim Emiola <[email protected]> | ||
SPDX-License-Identifier: BSD3 | ||
-} | ||
module MemInfo.ChoicesSpec where | ||
|
||
import Data.GenValidity (GenValid (..)) | ||
import qualified Data.List.NonEmpty as NE | ||
import MemInfo.OrphanInstances () | ||
import Options.Applicative (defaultPrefs, execParserPure, getParseResult) | ||
import System.MemInfo.Choices (Choices (..), cmdInfo) | ||
import Test.Hspec | ||
import Test.QuickCheck (Gen, Property, forAll, suchThat) | ||
|
||
|
||
spec :: Spec | ||
spec = describe "module System.MemInfo.Choices" $ do | ||
it "should parse a Choices from the command line ok" prop_roundtripParseChoices | ||
|
||
|
||
prop_roundtripParseChoices :: Property | ||
prop_roundtripParseChoices = | ||
forAll genCmdLine $ | ||
\(choices, args) -> Just choices == getParseResult (execParserPure defaultPrefs cmdInfo args) | ||
|
||
|
||
genCmdLine :: Gen (Choices, [String]) | ||
genCmdLine = do | ||
choices <- genValid `suchThat` ((/= Just 0) . choiceWatchSecs) | ||
pure (choices, cmdlineOf choices) | ||
|
||
|
||
cmdlineOf :: Choices -> [String] | ||
cmdlineOf c = | ||
let | ||
splitArgs = if choiceSplitArgs c then ("-s" :) else id | ||
onlyTotal = if choiceOnlyTotal c then ("-t" :) else id | ||
byPid = if choiceByPid c then ("-d" :) else id | ||
showSwap = if choiceShowSwap c then ("-S" :) else id | ||
watchSecs = maybe id (\x -> (("-w " ++ show x) :)) $ choiceWatchSecs c | ||
onePid x = "-p " ++ show x | ||
manyPids xs = (map onePid (NE.toList xs) ++) | ||
pidsToShow = maybe id manyPids $ choicePidsToShow c | ||
in | ||
pidsToShow $ splitArgs $ onlyTotal $ byPid $ showSwap $ watchSecs mempty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
{- | | ||
Module : MemInfo.ProcSpec | ||
Module : MemInfo.PrintSpec | ||
Copyright : (c) 2023 Tim Emiola | ||
Maintainer : Tim Emiola <[email protected]> | ||
SPDX-License-Identifier: BSD3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters