1{-# LANGUAGE ScopedTypeVariables #-}
2{-# LANGUAGE OverloadedStrings, NoImplicitPrelude #-}
3module Stackage.BuildPlanSpec (spec) where
5import qualified Data.Map as Map
6import qualified Data.Map.Strict as M
7import qualified Data.Set as S
9import qualified Data.Yaml as Y
10import Distribution.Version
11import Network.HTTP.Client
12import Network.HTTP.Client.TLS (tlsManagerSettings)
13import Stackage.BuildConstraints
14import Stackage.BuildPlan
15import Stackage.CheckBuildPlan
16import Stackage.PackageDescription
17import Stackage.Prelude
18import Stackage.UpdateBuildPlan
23 it "simple package set" $ check testBuildConstraints $ makePackageSet
24 [("foo", [0, 0, 0], [("bar", thisV [0, 0, 0])])
25 ,("bar", [0, 0, 0], [])]
26 it "bad version range on depdendency fails" $ badBuildPlan $ makePackageSet
27 [("foo", [0, 0, 0], [("bar", thisV [1, 1, 0])])
28 ,("bar", [0, 0, 0], [])]
29 it "nonexistent package fails to check" $ badBuildPlan $ makePackageSet
30 [("foo", [0, 0, 0], [("nonexistent", thisV [0, 0, 0])])
31 ,("bar", [0, 0, 0], [])]
32 it "mutual cycles fail to check" $ badBuildPlan $ makePackageSet
33 [("foo", [0, 0, 0], [("bar", thisV [0, 0, 0])])
34 ,("bar", [0, 0, 0], [("foo", thisV [0, 0, 0])])]
35 it "nested cycles fail to check" $ badBuildPlan $ makePackageSet
36 [("foo", [0, 0, 0], [("bar", thisV [0, 0, 0])])
37 ,("bar", [0, 0, 0], [("mu", thisV [0, 0, 0])])
38 ,("mu", [0, 0, 0], [("foo", thisV [0, 0, 0])])]
39 it "default package set checks ok" $
40 check defaultBuildConstraints getLatestAllowedPlans
42-- | Checking should be considered a bad build plan.
43badBuildPlan :: (BuildConstraints -> IO (Map PackageName PackagePlan))
47 mu <- try (check testBuildConstraints m)
49 Left (_ :: BadBuildPlan) ->
52 error "Expected bad build plan."
54-- | Check build plan with the given package set getter.
55check :: (Manager -> IO BuildConstraints)
56 -> (BuildConstraints -> IO (Map PackageName PackagePlan))
58check readPlanFile getPlans = withManager tlsManagerSettings $ \man -> do
59 bc <- readPlanFile man
61 bp <- newBuildPlan plans bc
63 ebp' = Y.decodeEither bs
65 bp' <- either error return ebp'
67 let allPackages = Map.keysSet (bpPackages bp) ++ Map.keysSet (bpPackages bp')
68 forM_ allPackages $ \name ->
69 (name, lookup name (bpPackages bp')) `shouldBe`
70 (name, lookup name (bpPackages bp))
71 bpGithubUsers bp' `shouldBe` bpGithubUsers bp
73 when (bp' /= bp) $ error "bp' /= bp"
74 bp2 <- updateBuildPlan plans bp
75 when (dropVersionRanges bp2 /= dropVersionRanges bp) $ error "bp2 /= bp"
78 dropVersionRanges bp =
79 bp { bpPackages = map go $ bpPackages bp }
81 go pb = pb { ppConstraints = go' $ ppConstraints pb }
82 go' pc = pc { pcVersionRange = anyVersion }
84-- | Make a package set from a convenient data structure.
86 :: [(String,[Int],[(String,VersionRange)])]
88 -> IO (Map PackageName PackagePlan)
100 , DepInfo {diComponents = S.fromList
106 dummyPackage v deps =
108 {ppVersion = Version v []
109 ,ppGithubPings = mempty
113 {pcVersionRange = anyV
114 ,pcMaintainer = Nothing
115 ,pcTests = Don'tBuild
116 ,pcHaddocks = Don'tBuild
117 ,pcBuildBenchmarks = False
118 ,pcFlagOverrides = mempty
119 ,pcEnableLibProfile = False}
124 ,sdProvidedExes = mempty
125 ,sdModules = mempty}}
127-- | This exact version is required.
128thisV :: [Int] -> VersionRange
129thisV ver = thisVersion (Version ver [])
131-- | Accept any version.
136testBuildConstraints :: void -> IO BuildConstraints
137testBuildConstraints _ =
141 where fp = "test/test-build-constraints.yaml"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list