Skip to content

Commit c4e388d

Browse files
committed
added unit tests for issue #2254
1 parent 630ba49 commit c4e388d

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

kore/test/Test/Kore/OptionsParser.hs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module Test.Kore.OptionsParser
22
( test_flags
3+
, test_options
34
) where
45

56
import Prelude.Kore
@@ -20,41 +21,66 @@ test_flags =
2021
[ testGroup "print-definition"
2122
[ testCase "default is False" $ do
2223
let flag_value = willPrintDefinition $ runParser commandLineParser
23-
["mock/path/to/file"]
24+
["mock/path/to/def"]
2425
assertEqual "Expected print-definition to be False by default"
2526
False flag_value
2627
, testCase "given explicitly is True" $ do
2728
let flag_value = willPrintDefinition $ runParser commandLineParser
28-
["mock/path/to/file", "--print-definition"]
29+
["mock/path/to/def", "--print-definition"]
2930
assertEqual "Expected --print-definition to give True"
3031
True flag_value
3132
, testCase "with `no` prefix is False" $ do
3233
let flag_value = willPrintDefinition $ runParser commandLineParser
33-
["mock/path/to/file", "--no-print-definition"]
34+
["mock/path/to/def", "--no-print-definition"]
3435
assertEqual "Expected --no-print-definition to give False"
3536
False flag_value
3637
]
3738
, testGroup "print-pattern"
3839
[ testCase "default is False" $ do
3940
let flag_value = willPrintPattern $ runParser commandLineParser
40-
["mock/path/to/file"]
41+
["mock/path/to/def"]
4142
assertEqual "Expected print-pattern to be False by default"
4243
False flag_value
4344
, testCase "given explicitly is True" $ do
4445
let flag_value = willPrintPattern $ runParser commandLineParser
45-
["mock/path/to/file", "--print-pattern"]
46+
["mock/path/to/def", "--print-pattern"]
4647
assertEqual "Expected --print-pattern to give True"
4748
True flag_value
4849
, testCase "with `no` prefix is False" $ do
4950
let flag_value = willPrintPattern $ runParser commandLineParser
50-
["mock/path/to/file", "--no-print-pattern"]
51+
["mock/path/to/def", "--no-print-pattern"]
5152
assertEqual "Expected --no-print-pattern to give False"
5253
False flag_value
5354
]
5455
]
5556

56-
runParser :: Parser a -> [String] -> a
57-
runParser parser input = fromJust $ getParseResult parserResult
57+
test_options :: [TestTree]
58+
test_options =
59+
[ testGroup "pattern and module must go together"
60+
[ testCase "pattern only" $ do
61+
let result = runParser' commandLineParser
62+
["mock/path/to/def", "--pattern", "mock/path/to/pat"]
63+
assertBool "Expected passing only the pattern option to fail"
64+
$ isNothing result
65+
, testCase "module only" $ do
66+
let result = runParser' commandLineParser
67+
["mock/path/to/def", "--module", "mock_module"]
68+
assertBool "Expected passing only the module option to fail"
69+
$ isNothing result
70+
, testCase "pattern and module" $ do
71+
let result = runParser' commandLineParser
72+
["mock/path/to/def", "--pattern", "mock/path/to/pat"
73+
, "--module", "mock_module"]
74+
assertBool "Expected passing both pattern and module options to not fail"
75+
$ isJust result
76+
]
77+
]
78+
79+
runParser' :: Parser a -> [String] -> Maybe a
80+
runParser' parser input = getParseResult parserResult
5881
where
5982
parserInfo = info parser mempty
6083
parserResult = execParserPure defaultPrefs parserInfo input
84+
85+
runParser :: Parser a -> [String] -> a
86+
runParser parser input = fromJust $ runParser' parser input

0 commit comments

Comments
 (0)