forked from commercialhaskell/stack
-
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.
Change parsers to use
flag'
instead of switch
This fixes commercialhaskell#3959. The problem is that the [switch](https://hackage.haskell.org/package/optparse-applicative/docs/Options-Applicative-Builder.html#v:switch) function returns a `Just False` which gets wrapped into `First`. This means that the value is *always* set to either `True` or `False` and the `First` monoid means that during options parsing the order of the flags suddenly matters as described in commercialhaskell#3959, because `First (Just False)` is chosen when `mappend`ing with `First (Just True)`. The fix is to use the [flag](https://hackage.haskell.org/package/optparse-applicative-0.14.2.0/docs/Options-Applicative-Builder.html#v:flag-39-) function that does not set a default value, so we get a `First Nothing` instead.
- Loading branch information
1 parent
8ba673f
commit bf4711e
Showing
7 changed files
with
39 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
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,21 @@ | ||
import StackTest | ||
|
||
import Control.Monad (unless) | ||
import Data.List (isInfixOf) | ||
|
||
-- Integration test for https://github.com/commercialhaskell/stack/issues/3959 | ||
main :: IO () | ||
main = do | ||
checkFlagsBeforeCommand | ||
checkFlagsAfterCommand | ||
|
||
checkFlagsBeforeCommand :: IO () | ||
checkFlagsBeforeCommand = stackCheckStderr ["--test", "--no-run-tests", "build"] checker | ||
|
||
checkFlagsAfterCommand :: IO () | ||
checkFlagsAfterCommand = stackCheckStderr ["build", "--test", "--no-run-tests"] checker | ||
|
||
checker :: String -> IO () | ||
checker output = do | ||
let testsAreDisabled = any (\ln -> "Test running disabled by" `isInfixOf` ln) (lines output) | ||
unless testsAreDisabled $ fail "Tests should not be run" |
10 changes: 10 additions & 0 deletions
10
test/integration/tests/3959-order-of-flags/files/package.yaml
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,10 @@ | ||
name: issue3959 | ||
version: 0.1.0.0 | ||
|
||
dependencies: | ||
- base | ||
|
||
tests: | ||
test: | ||
main: Spec.hs | ||
source-dirs: test |
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 @@ | ||
resolver: lts-11.6 |
2 changes: 2 additions & 0 deletions
2
test/integration/tests/3959-order-of-flags/files/test/Spec.hs
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,2 @@ | ||
main :: IO () | ||
main = fail "this always fails for the test" |