git.iko.soy/typeable/stackage2nix
on master help sign in
Add test for StackConfig
commit0110a4f6719995827d1b034c10ecfbcacc7822ac authorDmitry Bushev <bushevdv@gmail.com> dateSun 18 Mar 2018, 22:54 (9 years ago) parenta9569b8
7 files changed+213−24
src/Distribution/Nixpkgs/Haskell/Stack.hs+4−4 src/LtsHaskell.hs+1−1 src/Stack/Config.hs+13−13 src/Stack/Config/Yaml.hs+2−2 stackage2nix.cabal+2 test/Stack/Config/YamlSpec.hs+4−4 test/Stack/ConfigSpec.hs+187
src/Distribution/Nixpkgs/Haskell/Stack.hs+4−4
@@ -42,22 +42,22 @@ stackLocationToSource
4242 -> Maybe FilePath
4343 -> Source
4444stackLocationToSource pl mCabalDir = case pl of
45− StackIndex p -> Source
45+ PlIndex p -> Source
4646 { sourceUrl = "cabal://" ++ T.unpack (p ^. piNameVersion)
4747 , sourceRevision = mempty
4848 , sourceHash = UnknownHash
4949 , sourceCabalDir = cabalDir }
50− StackFilePath p -> Source
50+ PlFilePath p -> Source
5151 { sourceUrl = p
5252 , sourceRevision = mempty
5353 , sourceHash = UnknownHash
5454 , sourceCabalDir = cabalDir }
55− StackUri uri -> Source
55+ PlUri uri -> Source
5656 { sourceUrl = URI.uriToString id uri mempty
5757 , sourceRevision = mempty
5858 , sourceHash = UnknownHash
5959 , sourceCabalDir = cabalDir }
60− StackRepo r -> Source
60+ PlRepo r -> Source
6161 { sourceUrl = T.unpack $ r ^. rUri
6262 , sourceRevision = T.unpack $ r ^. rCommit
6363 , sourceHash = UnknownHash
src/LtsHaskell.hs+1−1
@@ -52,7 +52,7 @@ getPackageFromRepo allCabalHashesPath mSha1Hash pkgId = do
5252getPackageFromDb :: DB.HackageDB -> PackageIdentifier -> IO Package
5353getPackageFromDb hackageDb pkgId =
5454 getStackPackageFromDb hackageDb
55− $ StackPackage (StackIndex $ PackageIndex (T.pack $ Text.display pkgId) Nothing) True Nothing
55+ $ StackPackage (PlIndex $ PackageIndex (T.pack $ Text.display pkgId) Nothing) True Nothing
5656
5757loadPackage :: DB.HackageDB -> FilePath -> Maybe SHA1Hash -> PackageIdentifier -> IO Package
5858loadPackage hackageDb allCabalHashesPath mSha1Hash pkgId =
src/Stack/Config.hs+13−13
@@ -52,10 +52,10 @@ data PackageIndex = PackageIndex
5252makeLenses ''PackageIndex
5353
5454data PackageLocation
55− = StackIndex PackageIndex
56− | StackFilePath FilePath
57− | StackUri URI
58− | StackRepo Repo
55+ = PlIndex PackageIndex
56+ | PlFilePath FilePath
57+ | PlUri URI
58+ | PlRepo Repo
5959 deriving (Eq, Ord, Show)
6060
6161makePrisms ''PackageLocation
@@ -89,7 +89,7 @@ fromYamlConfig c = StackConfig{..}
8989 <$> fromMaybe mempty (c ^. cPackages)
9090 yamlExtraDeps = fromYamlPackage extraDepsSimplePath True
9191 <$> fromMaybe mempty (c ^. cExtraDeps)
92− defaultPackage = StackPackage (StackFilePath ".") False Nothing
92+ defaultPackage = StackPackage (PlFilePath ".") False Nothing
9393
9494-- | Simple string in a packages section can be an URI or FilePath location
9595packagesSimplePath :: Text -> StackPackage
@@ -97,19 +97,19 @@ packagesSimplePath t = StackPackage (parseSimplePath t) False Nothing
9797
9898-- | Parse location as URI or a FilePath
9999parseSimplePath :: Text -> PackageLocation
100−parseSimplePath (T.unpack -> p) = maybe (StackFilePath p) StackUri $ parseURI p
100+parseSimplePath (T.unpack -> p) = maybe (PlFilePath p) PlUri $ parseURI p
101101
102102-- | Simple string in an extra-deps section can be an URI or FilePath or PackageIndex name-version
103103extraDepsSimplePath :: Text -> StackPackage
104104extraDepsSimplePath t = StackPackage loc True Nothing
105105 where
106− loc = maybe (parsePackageIndex t) StackUri $ parseURI (T.unpack t)
106+ loc = maybe (parsePackageIndex t) PlUri $ parseURI (T.unpack t)
107107
108108-- TODO: support new package index format with hash and revision
109109parsePackageIndex :: Text -> PackageLocation
110110parsePackageIndex t = if isFilePath t
111− then StackFilePath (T.unpack t)
112− else StackIndex $ PackageIndex t Nothing
111+ then PlFilePath (T.unpack t)
112+ else PlIndex $ PackageIndex t Nothing
113113
114114-- Determine wether package is file path
115115isFilePath :: Text -> Bool
@@ -134,12 +134,12 @@ fromYamlPackage fromSimple isExtraDep = \case
134134 Yaml.PArchive a ->
135135 unroll (a ^. aSubdirs) $ StackPackage (a ^. aArchive . to parseSimplePath) isExtraDep
136136 Yaml.PNewGit ng -> unroll (ng ^. ngSubdirs)
137− $ StackPackage (StackRepo $ fromYamlNewGit ng) isExtraDep
137+ $ StackPackage (PlRepo $ fromYamlNewGit ng) isExtraDep
138138 Yaml.PNewHg nh -> unroll (nh ^. nhSubdirs)
139− $ StackPackage (StackRepo $ fromYamlNewHg nh) isExtraDep
139+ $ StackPackage (PlRepo $ fromYamlNewHg nh) isExtraDep
140140 where
141141 mkStackPackageRepo f loc = unroll (loc ^. lSubdirs)
142− $ StackPackage (StackRepo (loc ^. lLocation . to f)) (fromMaybe isExtraDep $ loc ^. lExtraDep)
142+ $ StackPackage (PlRepo (loc ^. lLocation . to f)) (fromMaybe isExtraDep $ loc ^. lExtraDep)
143143 -- Each package gets a single directory with cabal file in it. If
144144 -- it's not specified, path is empty.
145145 unroll subs p = case subs of
@@ -174,7 +174,7 @@ readStackConfig :: StackYaml -> IO (Either String StackConfig)
174174readStackConfig stackYaml = do
175175 let
176176 relativeToStackYaml = \case
177− StackFilePath p -> StackFilePath $ stackYaml ^. syDirName </> p
177+ PlFilePath p -> PlFilePath $ stackYaml ^. syDirName </> p
178178 packageLocation -> packageLocation
179179 mkStackConfig = over (scPackages . traversed . spLocation) relativeToStackYaml
180180 . fromYamlConfig
src/Stack/Config/Yaml.hs+2−2
@@ -93,8 +93,8 @@ instance ToJSON Package where
9393 PNewGit t -> toJSON t
9494 PNewHg t -> toJSON t
9595
96−-- To support support both old and new syntax, we allow all varieties of package
97−-- definitions in both "packages" and "extra-deps" sections
96+-- To support both old and new syntax, we allow all variants of package
97+-- definitions in "packages" and "extra-deps" sections
9898data Config = Config
9999 { _cResolver :: Text
100100 , _cPackages :: Maybe [Package]
stackage2nix.cabal+2
@@ -77,6 +77,7 @@ test-suite spec
7777 , Cabal
7878 , bytestring
7979 , hspec
80+ , network-uri
8081 , pretty
8182 , shakespeare
8283 , stackage2nix
@@ -86,6 +87,7 @@ test-suite spec
8687 other-modules: Language.Nix.FilePathSpec
8788 , PrettyPrintingSpec
8889 , Stack.Config.YamlSpec
90+ , Stack.ConfigSpec
8991 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
9092 default-language: Haskell2010
9193
test/Stack/Config/YamlSpec.hs+4−4
@@ -148,10 +148,10 @@ configNew = Config
148148 }
149149
150150spec :: Spec
151−spec = describe "Parse" $ do
152− specify "config-minimal" $
151+spec = describe "Config" $ do
152+ specify "minimal" $
153153 (Y.decode configYamlMinimal :: Maybe Config) `shouldBe` Just configMinimal
154− specify "config-full" $
154+ specify "full" $
155155 (Y.decode configYaml :: Maybe Config) `shouldBe` Just config
156− specify "config-new" $
156+ specify "new" $
157157 (Y.decode configNewYaml :: Maybe Config) `shouldBe` Just configNew
test/Stack/ConfigSpec.hsnew file+187
@@ -0,0 +1,187 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE QuasiQuotes #-}
3+
4+module Stack.ConfigSpec (spec) where
5+
6+import Data.ByteString
7+import Data.List.NonEmpty as NE
8+import Data.Text.Encoding as T
9+import Data.Yaml as Y
10+import Network.URI as URI
11+import Stack.Config
12+import Test.Hspec
13+import Text.Shakespeare.Text
14+
15+
16+spec :: Spec
17+spec = describe "StackConfig" $ do
18+ specify "minimal"
19+ $ checkYamlConfig minimalBs minimalConf
20+ specify "packageDefault"
21+ $ checkYamlConfig packageDefaultBs packageDefaultConf
22+ specify "packageSimpleList"
23+ $ checkYamlConfig packageSimpleListBs packageSimpleListConf
24+ specify "packageLocations"
25+ $ checkYamlConfig packageLocationsBs packageLocationsConf
26+ specify "packageExtraDeps"
27+ $ checkYamlConfig packageExtraDepsBs packageExtraDepsConf
28+ specify "packageMixed"
29+ $ checkYamlConfig packageMixedBs packageMixedConf
30+ specify "packageExtraDepsNew"
31+ $ checkYamlConfig packageExtraDepsNewBs packageExtraDepsNewConf
32+
33+parseYamlConfig :: ByteString -> Maybe StackConfig
34+parseYamlConfig = fmap fromYamlConfig . Y.decode
35+
36+checkYamlConfig :: ByteString -> StackConfig -> Expectation
37+checkYamlConfig bs sc = parseYamlConfig bs `shouldBe` Just sc
38+
39+stUri :: String -> URI
40+stUri s =
41+ let Just uri = parseURI s
42+ in uri
43+
44+minimalBs :: ByteString
45+minimalBs = T.encodeUtf8 [st|
46+resolver: lts-10.0
47+|]
48+
49+minimalConf :: StackConfig
50+minimalConf = StackConfig
51+ { _scResolver = StackResolver "lts-10.0"
52+ , _scPackages = NE.fromList
53+ [ StackPackage (PlFilePath ".") False Nothing]
54+ }
55+
56+packageDefaultBs :: ByteString
57+packageDefaultBs = T.encodeUtf8 [st|
58+resolver: lts-10.0
59+packages:
60+ - .
61+|]
62+
63+packageDefaultConf :: StackConfig
64+packageDefaultConf = minimalConf
65+
66+packageSimpleListBs :: ByteString
67+packageSimpleListBs = T.encodeUtf8 [st|
68+resolver: lts-10.0
69+packages:
70+ - client
71+ - server
72+|]
73+
74+packageSimpleListConf :: StackConfig
75+packageSimpleListConf = StackConfig
76+ { _scResolver = StackResolver "lts-10.0"
77+ , _scPackages = NE.fromList
78+ [ StackPackage (PlFilePath "client") False Nothing
79+ , StackPackage (PlFilePath "server") False Nothing ]
80+ }
81+
82+packageLocationsBs :: ByteString
83+packageLocationsBs = T.encodeUtf8 [st|
84+resolver: lts-10.0
85+packages:
86+ - location: humble/package
87+ subdirs:
88+ - client
89+ - server
90+ - location: https://example.com/foo/bar/baz-0.0.2.tar.gz
91+ extra-dep: true
92+ subdirs:
93+ - extra
94+ - location:
95+ git: git@github.com:example/mega-repo
96+ commit: 6a86ee32e5b869a877151f74064572225e1a0000
97+ subdirs:
98+ - subdir1
99+ - subdir2
100+ extra-dep: true
101+|]
102+
103+packageLocationsConf :: StackConfig
104+packageLocationsConf = StackConfig
105+ { _scResolver = StackResolver "lts-10.0"
106+ , _scPackages = NE.fromList
107+ [ StackPackage (PlFilePath "humble/package") False (Just "client")
108+ , StackPackage (PlFilePath "humble/package") False (Just "server")
109+ , StackPackage (PlUri $ stUri "https://example.com/foo/bar/baz-0.0.2.tar.gz") True (Just "extra")
110+ , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:example/mega-repo" "6a86ee32e5b869a877151f74064572225e1a0000") True (Just "subdir1")
111+ , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:example/mega-repo" "6a86ee32e5b869a877151f74064572225e1a0000") True (Just "subdir2")
112+ ]
113+ }
114+
115+packageExtraDepsBs :: ByteString
116+packageExtraDepsBs = T.encodeUtf8 [st|
117+resolver: lts-10.0
118+extra-deps:
119+ - acme-missiles-0.3
120+ - humble-package-1
121+|]
122+
123+packageExtraDepsConf :: StackConfig
124+packageExtraDepsConf = StackConfig
125+ { _scResolver = StackResolver "lts-10.0"
126+ , _scPackages = NE.fromList
127+ [ StackPackage (PlFilePath ".") False Nothing
128+ , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
129+ , StackPackage (PlIndex $ PackageIndex "humble-package-1" Nothing) True Nothing ]
130+ }
131+
132+packageMixedBs :: ByteString
133+packageMixedBs = T.encodeUtf8 [st|
134+resolver: lts-10.0
135+packages:
136+ - client
137+ - server
138+extra-deps:
139+ - acme-missiles-0.3
140+ - humble-package-1
141+|]
142+
143+packageMixedConf :: StackConfig
144+packageMixedConf = StackConfig
145+ { _scResolver = StackResolver "lts-10.0"
146+ , _scPackages = NE.fromList
147+ [ StackPackage (PlFilePath "client") False Nothing
148+ , StackPackage (PlFilePath "server") False Nothing
149+ , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
150+ , StackPackage (PlIndex $ PackageIndex "humble-package-1" Nothing) True Nothing ]
151+ }
152+
153+packageExtraDepsNewBs :: ByteString
154+packageExtraDepsNewBs = T.encodeUtf8 [st|
155+resolver: lts-10.0
156+extra-deps:
157+ - vendor/lib
158+ - acme-missiles-0.3
159+ - git: git@github.com:yesodweb/wai
160+ commit: 2f8a8e1b771829f4a8a77c0111352ce45a14c30f
161+ subdirs:
162+ - auto-update
163+ - wai
164+ - https://example.com/foo/bar/baz-0.0.2.tar.gz
165+ - archive: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip
166+ subdirs:
167+ - wai
168+ - warp
169+ - archive: ../acme-missiles-0.3.tar.gz
170+ sha256: e563d8b524017a06b32768c4db8eff1f822f3fb22a90320b7e414402647b735b
171+|]
172+
173+packageExtraDepsNewConf :: StackConfig
174+packageExtraDepsNewConf = StackConfig
175+ { _scResolver = StackResolver "lts-10.0"
176+ , _scPackages = NE.fromList
177+ [ StackPackage (PlFilePath ".") False Nothing
178+ , StackPackage (PlFilePath "vendor/lib") True Nothing
179+ , StackPackage (PlIndex $ PackageIndex "acme-missiles-0.3" Nothing) True Nothing
180+ , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:yesodweb/wai" "2f8a8e1b771829f4a8a77c0111352ce45a14c30f") True (Just "auto-update")
181+ , StackPackage (PlRepo $ Repo (Vcs "git") "git@github.com:yesodweb/wai" "2f8a8e1b771829f4a8a77c0111352ce45a14c30f") True (Just "wai")
182+ , StackPackage (PlUri $ stUri "https://example.com/foo/bar/baz-0.0.2.tar.gz") True Nothing
183+ , StackPackage (PlUri $ stUri "http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip") True (Just "wai")
184+ , StackPackage (PlUri $ stUri "http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip") True (Just "warp")
185+ , StackPackage (PlFilePath "../acme-missiles-0.3.tar.gz") True Nothing
186+ ]
187+ }