Skip to content

Commit

Permalink
Implement WantedCompiler parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Aug 9, 2018
1 parent 71c79e4 commit 050e06b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions subs/pantry/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,4 @@ tests:
- pantry
- hspec
- exceptions
- hedgehog
7 changes: 6 additions & 1 deletion subs/pantry/src/Pantry/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,12 @@ parseWantedCompiler t0 = maybe (Left $ InvalidWantedCompiler t0) Right $
Just t1 -> parseGhcjs t1
Nothing -> T.stripPrefix "ghc-" t0 >>= parseGhc
where
parseGhcjs = undefined
parseGhcjs t1 = do
let (ghcjsVT, t2) = T.break (== '_') t1
ghcjsV <- parseVersion $ T.unpack ghcjsVT
ghcVT <- T.stripPrefix "_ghc-" t2
ghcV <- parseVersion $ T.unpack ghcVT
pure $ WCGhcjs ghcjsV ghcV
parseGhc = fmap WCGhc . parseVersion . T.unpack

data UnresolvedSnapshotLocation
Expand Down
30 changes: 30 additions & 0 deletions subs/pantry/test/Pantry/TypesSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Pantry.TypesSpec (spec) where

import Test.Hspec
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import Pantry
import RIO
import Distribution.Types.Version (mkVersion)

hh :: HasCallStack => String -> Property -> Spec
hh name p = it name $ do
result <- check p
unless result $ throwString "Hedgehog property failed" :: IO ()

spec :: Spec
spec = do
describe "WantedCompiler" $ do
hh "parse/render works" $ property $ do
wc <- forAll $
let ghc = WCGhc <$> genVersion
ghcjs = WCGhcjs <$> genVersion <*> genVersion
genVersion = mkVersion <$> Gen.list (Range.linear 1 5) (Gen.int (Range.linear 0 100))
in Gen.choice [ghc, ghcjs]
let text = utf8BuilderToText $ display wc
case parseWantedCompiler text of
Left e -> throwIO e
Right actual -> liftIO $ actual `shouldBe` wc

0 comments on commit 050e06b

Please sign in to comment.