Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove "-any" from AnyVersion pretty-print output. #6741

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cabal/Cabal-quickcheck/src/Test/QuickCheck/Instances/Cabal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ instance Arbitrary Version where
, not (null ns) ]

instance Arbitrary VersionRange where
arbitrary = sized verRangeExp
arbitrary = oneof [sized verRangeExp, return anyVersion]
where
verRangeExp :: Int -> Gen VersionRange
verRangeExp n = frequency $
[ (2, return anyVersion)
, (1, fmap thisVersion arbitrary)
[ (1, fmap thisVersion arbitrary)
, (1, fmap laterVersion arbitrary)
, (1, fmap orLaterVersion arbitrary)
, (1, fmap orLaterVersion' arbitrary)
Expand Down
2 changes: 1 addition & 1 deletion Cabal/Distribution/Types/VersionRange.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Prelude ()
--
-- For a semantic view use 'asVersionIntervals'.
--
foldVersionRange :: a -- ^ @\"-any\"@ version
foldVersionRange :: a -- ^ "any" version
-> (Version -> a) -- ^ @\"== v\"@
-> (Version -> a) -- ^ @\"> v\"@
-> (Version -> a) -- ^ @\"< v\"@
Expand Down
19 changes: 12 additions & 7 deletions Cabal/Distribution/Types/VersionRange/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import qualified Distribution.Compat.DList as DList
import qualified Text.PrettyPrint as Disp

data VersionRange
= AnyVersion
| ThisVersion Version -- = version
= AnyVersion -- "" (no version range)
| ThisVersion Version -- == version
| LaterVersion Version -- > version (NB. not >=)
| OrLaterVersion Version -- >= version
| EarlierVersion Version -- < version
Expand Down Expand Up @@ -235,7 +235,7 @@ hyloVersionRange f g = h where h = f . fmap h . g
instance Pretty VersionRange where
pretty = fst . cataVersionRange alg
where
alg AnyVersionF = (Disp.text "-any", 0 :: Int)
alg AnyVersionF = (Disp.empty, 0 :: Int)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The Dependency output have to be modified.

See what's done in #6742. That PR is not complete, I run out of time on Friday, so didn't put it up. Sorry for that. I changed the Dependency output as I was updating parser-tests outputs anyway.

alg (ThisVersionF v) = (Disp.text "==" <<>> pretty v, 0)
alg (LaterVersionF v) = (Disp.char '>' <<>> pretty v, 0)
alg (OrLaterVersionF v) = (Disp.text ">=" <<>> pretty v, 0)
Expand Down Expand Up @@ -293,7 +293,7 @@ instance Parsec VersionRange where

instance Described VersionRange where
describe _ = RERec "version-range" $ REUnion
[ "-any", "-none"
[ "-none"

, "==" <> RESpaces <> ver
, ">" <> RESpaces <> ver
Expand All @@ -302,8 +302,8 @@ instance Described VersionRange where
, ">=" <> RESpaces <> ver
, "^>=" <> RESpaces <> ver

, reVar0 <> RESpaces <> "||" <> RESpaces <> reVar0
, reVar0 <> RESpaces <> "&&" <> RESpaces <> reVar0
, reVar0 <> RESpaces <> "||" <> RESpaces <> reVar0
, reVar0 <> RESpaces <> "&&" <> RESpaces <> reVar0
, "(" <> RESpaces <> reVar0 <> RESpaces <> ")"

-- ==0.1.*
Expand All @@ -313,6 +313,7 @@ instance Described VersionRange where
-- silly haddock: ^>= { 0.1.2, 3.4.5 }
, "==" <> RESpaces <> verSet
, "^>=" <> RESpaces <> verSet
, ""
]
where
ver' = describe (Proxy :: Proxy Version)
Expand All @@ -328,8 +329,12 @@ instance Described VersionRange where
--
-- @since 3.0
versionRangeParser :: forall m. CabalParsing m => m Int -> CabalSpecVersion -> m VersionRange
versionRangeParser digitParser csv = expr
versionRangeParser digitParser csv = noVersionParser <|> expr
where
-- If the input is empty, parse as 'AnyVersion'.
noVersionParser = do P.spaces
return anyVersion <* P.eof

expr = do P.spaces
t <- term
P.spaces
Expand Down
4 changes: 2 additions & 2 deletions Cabal/tests/UnitTests/Distribution/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Distribution.Utils.Generic

import Data.Typeable (typeOf)
import Math.NumberTheory.Logarithms (intLog2)
import Text.PrettyPrint as Disp (text, render, hcat
import Text.PrettyPrint as Disp (empty, text, render, hcat
,punctuate, int, char, (<+>))
import Test.Tasty
import Test.Tasty.QuickCheck
Expand Down Expand Up @@ -643,7 +643,7 @@ displayRaw =

-- precedence:
-- All the same as the usual pretty printer, except for the parens
alg AnyVersionF = Disp.text "-any"
alg AnyVersionF = Disp.empty
alg (ThisVersionF v) = Disp.text "==" <<>> pretty v
alg (LaterVersionF v) = Disp.char '>' <<>> pretty v
alg (EarlierVersionF v) = Disp.char '<' <<>> pretty v
Expand Down