Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1163 from 23Skidoo/sandbox-constraints-error
Make the UserConstraint parser non-ambiguous.
- Loading branch information
Showing
5 changed files
with
117 additions
and
19 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,15 @@ | ||
module Main | ||
where | ||
|
||
import Test.Framework | ||
|
||
import qualified UnitTests.Distribution.Client.Targets | ||
|
||
tests :: [Test] | ||
tests = [ | ||
testGroup "Distribution.Client.Targets" | ||
UnitTests.Distribution.Client.Targets.tests | ||
] | ||
|
||
main :: IO () | ||
main = defaultMain tests |
59 changes: 59 additions & 0 deletions
59
cabal-install/tests/UnitTests/Distribution/Client/Targets.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,59 @@ | ||
module UnitTests.Distribution.Client.Targets ( | ||
tests | ||
) where | ||
|
||
import Distribution.Client.Targets (UserConstraint (..), readUserConstraint) | ||
import Distribution.Compat.ReadP (ReadP, readP_to_S) | ||
import Distribution.Package (PackageName (..)) | ||
import Distribution.ParseUtils (parseCommaList) | ||
import Distribution.Text (parse) | ||
|
||
import Test.Framework as TF (Test) | ||
import Test.Framework.Providers.HUnit (testCase) | ||
import Test.HUnit (Assertion, assertEqual) | ||
|
||
import Data.Char (isSpace) | ||
|
||
tests :: [TF.Test] | ||
tests = [ testCase "readUserConstraint" readUserConstraintTest | ||
, testCase "parseUserConstraint" parseUserConstraintTest | ||
, testCase "readUserConstraints" readUserConstraintsTest | ||
] | ||
|
||
readUserConstraintTest :: Assertion | ||
readUserConstraintTest = | ||
assertEqual ("Couldn't read constraint: '" ++ constr ++ "'") expected actual | ||
where | ||
pkgName = "template-haskell" | ||
constr = pkgName ++ " installed" | ||
|
||
expected = UserConstraintInstalled (PackageName pkgName) | ||
actual = let (Right r) = readUserConstraint constr in r | ||
|
||
parseUserConstraintTest :: Assertion | ||
parseUserConstraintTest = | ||
assertEqual ("Couldn't parse constraint: '" ++ constr ++ "'") expected actual | ||
where | ||
pkgName = "template-haskell" | ||
constr = pkgName ++ " installed" | ||
|
||
expected = [UserConstraintInstalled (PackageName pkgName)] | ||
actual = [ x | (x, ys) <- readP_to_S parseUserConstraint constr | ||
, all isSpace ys] | ||
|
||
parseUserConstraint :: ReadP r UserConstraint | ||
parseUserConstraint = parse | ||
|
||
readUserConstraintsTest :: Assertion | ||
readUserConstraintsTest = | ||
assertEqual ("Couldn't read constraints: '" ++ constr ++ "'") expected actual | ||
where | ||
pkgName = "template-haskell" | ||
constr = pkgName ++ " installed" | ||
|
||
expected = [[UserConstraintInstalled (PackageName pkgName)]] | ||
actual = [ x | (x, ys) <- readP_to_S parseUserConstraints constr | ||
, all isSpace ys] | ||
|
||
parseUserConstraints :: ReadP r [UserConstraint] | ||
parseUserConstraints = parseCommaList parse |