Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Cabal
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Glasgow Haskell Compiler
Packages
Cabal
Commits
8b9143f0
Commit
8b9143f0
authored
9 years ago
by
Oleg Grenrus
Browse files
Options
Downloads
Patches
Plain Diff
Fix #2804: Text Platform roundtrip (with tests)
parent
b2d75687
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cabal/Distribution/System.hs
+14
-4
14 additions, 4 deletions
Cabal/Distribution/System.hs
Cabal/tests/UnitTests.hs
+3
-0
3 additions, 0 deletions
Cabal/tests/UnitTests.hs
Cabal/tests/UnitTests/Distribution/System.hs
+29
-0
29 additions, 0 deletions
Cabal/tests/UnitTests/Distribution/System.hs
with
46 additions
and
4 deletions
Cabal/Distribution/System.hs
+
14
−
4
View file @
8b9143f0
...
...
@@ -28,12 +28,17 @@ module Distribution.System (
-- * Platform is a pair of arch and OS
Platform
(
..
),
buildPlatform
,
platformFromTriple
platformFromTriple
,
-- * Internal
knownOSs
,
knownArches
)
where
import
qualified
System.Info
(
os
,
arch
)
import
qualified
Data.Char
as
Char
(
toLower
,
isAlphaNum
)
import
qualified
Data.Char
as
Char
(
toLower
,
isAlphaNum
,
isAlpha
)
import
Control.Monad
(
liftM2
)
import
Distribution.Compat.Binary
(
Binary
)
import
Data.Data
(
Data
)
import
Data.Typeable
(
Typeable
)
...
...
@@ -193,8 +198,13 @@ buildPlatform = Platform buildArch buildOS
-- Utils:
ident
::
Parse
.
ReadP
r
String
ident
=
Parse
.
munch1
(
\
c
->
Char
.
isAlphaNum
c
||
c
==
'_'
||
c
==
'-'
)
--TODO: probably should disallow starting with a number
ident
=
liftM2
(
:
)
first
rest
Parse
.+++
liftM2
(
:
)
first
rest'
where
first
=
Parse
.
satisfy
Char
.
isAlpha
-- We try first to parse identifier without dashes
-- This is required to parse 'Platform' properly
-- https://github.com/haskell/cabal/issues/2804
rest
=
Parse
.
munch
(
\
c
->
Char
.
isAlphaNum
c
||
c
==
'_'
)
rest'
=
Parse
.
munch
(
\
c
->
Char
.
isAlphaNum
c
||
c
==
'_'
||
c
==
'-'
)
lowercase
::
String
->
String
lowercase
=
map
Char
.
toLower
...
...
This diff is collapsed.
Click to expand it.
Cabal/tests/UnitTests.hs
+
3
−
0
View file @
8b9143f0
...
...
@@ -8,6 +8,7 @@ import qualified UnitTests.Distribution.Compat.CreatePipe
import
qualified
UnitTests.Distribution.Compat.ReadP
import
qualified
UnitTests.Distribution.Simple.Program.Internal
import
qualified
UnitTests.Distribution.Utils.NubList
import
qualified
UnitTests.Distribution.System
import
qualified
Test.Distribution.Version
(
versionTests
,
parseTests
)
tests
::
TestTree
...
...
@@ -20,6 +21,8 @@ tests = testGroup "Unit Tests" $
UnitTests
.
Distribution
.
Simple
.
Program
.
Internal
.
tests
,
testGroup
"Distribution.Utils.NubList"
UnitTests
.
Distribution
.
Utils
.
NubList
.
tests
,
testGroup
"Distribution.System"
UnitTests
.
Distribution
.
System
.
tests
,
Test
.
Distribution
.
Version
.
versionTests
,
Test
.
Distribution
.
Version
.
parseTests
]
...
...
This diff is collapsed.
Click to expand it.
Cabal/tests/UnitTests/Distribution/System.hs
0 → 100644
+
29
−
0
View file @
8b9143f0
{-# OPTIONS_GHC -fno-warn-orphans #-}
module
UnitTests.Distribution.System
(
tests
)
where
import
Control.Monad
(
liftM2
)
import
Distribution.Text
(
Text
(
..
),
display
,
simpleParse
)
import
Distribution.System
import
Test.Tasty
import
Test.Tasty.QuickCheck
textRoundtrip
::
(
Arbitrary
a
,
Show
a
,
Eq
a
,
Text
a
)
=>
a
->
Property
textRoundtrip
x
=
simpleParse
(
display
x
)
===
Just
x
tests
::
[
TestTree
]
tests
=
[
testProperty
"Text OS round trip"
(
textRoundtrip
::
OS
->
Property
)
,
testProperty
"Text Arch round trip"
(
textRoundtrip
::
Arch
->
Property
)
,
testProperty
"Text Platform round trip"
(
textRoundtrip
::
Platform
->
Property
)
]
instance
Arbitrary
OS
where
arbitrary
=
elements
knownOSs
instance
Arbitrary
Arch
where
arbitrary
=
elements
knownArches
instance
Arbitrary
Platform
where
arbitrary
=
liftM2
Platform
arbitrary
arbitrary
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment