git.iko.soy/typeable/stackage2nix
on master help sign in
Add test for StackConfig
0110a4fDmitry Bushev
src/Distribution/Nixpkgs/Haskell/Stack.hs+4−4
@@ -42,22 +42,22 @@ stackLocationToSource
42 -> Maybe FilePath
42 -> Maybe FilePath
43 -> Source
43 -> Source
44stackLocationToSource pl mCabalDir = case pl of
44stackLocationToSource pl mCabalDir = case pl of
45− StackIndex p -> Source
45+ PlIndex p -> Source
46 { sourceUrl = "cabal://" ++ T.unpack (p ^. piNameVersion)
46 { sourceUrl = "cabal://" ++ T.unpack (p ^. piNameVersion)
47 , sourceRevision = mempty
47 , sourceRevision = mempty
48 , sourceHash = UnknownHash
48 , sourceHash = UnknownHash
49 , sourceCabalDir = cabalDir }
49 , sourceCabalDir = cabalDir }
50− StackFilePath p -> Source
50+ PlFilePath p -> Source
51 { sourceUrl = p
51 { sourceUrl = p
52 , sourceRevision = mempty
52 , sourceRevision = mempty
53 , sourceHash = UnknownHash
53 , sourceHash = UnknownHash
54 , sourceCabalDir = cabalDir }
54 , sourceCabalDir = cabalDir }
55− StackUri uri -> Source
55+ PlUri uri -> Source
56 { sourceUrl = URI.uriToString id uri mempty
56 { sourceUrl = URI.uriToString id uri mempty
57 , sourceRevision = mempty
57 , sourceRevision = mempty
58 , sourceHash = UnknownHash
58 , sourceHash = UnknownHash
59 , sourceCabalDir = cabalDir }
59 , sourceCabalDir = cabalDir }
60− StackRepo r -> Source
60+ PlRepo r -> Source
61 { sourceUrl = T.unpack $ r ^. rUri
61 { sourceUrl = T.unpack $ r ^. rUri
62 , sourceRevision = T.unpack $ r ^. rCommit
62 , sourceRevision = T.unpack $ r ^. rCommit
63 , sourceHash = UnknownHash
63 , sourceHash = UnknownHash
src/LtsHaskell.hs+1−1
@@ -52,7 +52,7 @@ getPackageFromRepo allCabalHashesPath mSha1Hash pkgId = do
52getPackageFromDb :: DB.HackageDB -> PackageIdentifier -> IO Package
52getPackageFromDb :: DB.HackageDB -> PackageIdentifier -> IO Package
53getPackageFromDb hackageDb pkgId =
53getPackageFromDb hackageDb pkgId =
54 getStackPackageFromDb hackageDb
54 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
56
56
57loadPackage :: DB.HackageDB -> FilePath -> Maybe SHA1Hash -> PackageIdentifier -> IO Package
57loadPackage :: DB.HackageDB -> FilePath -> Maybe SHA1Hash -> PackageIdentifier -> IO Package
58loadPackage hackageDb allCabalHashesPath mSha1Hash pkgId =
58loadPackage hackageDb allCabalHashesPath mSha1Hash pkgId =
src/Stack/Config.hs+13−13
@@ -52,10 +52,10 @@ data PackageIndex = PackageIndex
52makeLenses ''PackageIndex
52makeLenses ''PackageIndex
53
53
54data PackageLocation
54data PackageLocation
55− = StackIndex PackageIndex
55+ = PlIndex PackageIndex
56− | StackFilePath FilePath
56+ | PlFilePath FilePath
57− | StackUri URI
57+ | PlUri URI
58− | StackRepo Repo
58+ | PlRepo Repo
59 deriving (Eq, Ord, Show)
59 deriving (Eq, Ord, Show)
60
60
61makePrisms ''PackageLocation
61makePrisms ''PackageLocation
@@ -89,7 +89,7 @@ fromYamlConfig c = StackConfig{..}
89 <$> fromMaybe mempty (c ^. cPackages)
89 <$> fromMaybe mempty (c ^. cPackages)
90 yamlExtraDeps = fromYamlPackage extraDepsSimplePath True
90 yamlExtraDeps = fromYamlPackage extraDepsSimplePath True
91 <$> fromMaybe mempty (c ^. cExtraDeps)
91 <$> fromMaybe mempty (c ^. cExtraDeps)
92− defaultPackage = StackPackage (StackFilePath ".") False Nothing
92+ defaultPackage = StackPackage (PlFilePath ".") False Nothing
93
93
94-- | Simple string in a packages section can be an URI or FilePath location
94-- | Simple string in a packages section can be an URI or FilePath location
95packagesSimplePath :: Text -> StackPackage
95packagesSimplePath :: Text -> StackPackage
@@ -97,19 +97,19 @@ packagesSimplePath t = StackPackage (parseSimplePath t) False Nothing
97
97
98-- | Parse location as URI or a FilePath
98-- | Parse location as URI or a FilePath
99parseSimplePath :: Text -> PackageLocation
99parseSimplePath :: Text -> PackageLocation
100−parseSimplePath (T.unpack -> p) = maybe (StackFilePath p) StackUri $ parseURI p
100+parseSimplePath (T.unpack -> p) = maybe (PlFilePath p) PlUri $ parseURI p
101
101
102-- | Simple string in an extra-deps section can be an URI or FilePath or PackageIndex name-version
102-- | Simple string in an extra-deps section can be an URI or FilePath or PackageIndex name-version
103extraDepsSimplePath :: Text -> StackPackage
103extraDepsSimplePath :: Text -> StackPackage
104extraDepsSimplePath t = StackPackage loc True Nothing
104extraDepsSimplePath t = StackPackage loc True Nothing
105 where
105 where
106− loc = maybe (parsePackageIndex t) StackUri $ parseURI (T.unpack t)
106+ loc = maybe (parsePackageIndex t) PlUri $ parseURI (T.unpack t)
107
107
108-- TODO: support new package index format with hash and revision
108-- TODO: support new package index format with hash and revision
109parsePackageIndex :: Text -> PackageLocation
109parsePackageIndex :: Text -> PackageLocation
110parsePackageIndex t = if isFilePath t
110parsePackageIndex t = if isFilePath t
111− then StackFilePath (T.unpack t)
111+ then PlFilePath (T.unpack t)
112− else StackIndex $ PackageIndex t Nothing
112+ else PlIndex $ PackageIndex t Nothing
113
113
114-- Determine wether package is file path
114-- Determine wether package is file path
115isFilePath :: Text -> Bool
115isFilePath :: Text -> Bool
@@ -134,12 +134,12 @@ fromYamlPackage fromSimple isExtraDep = \case
134 Yaml.PArchive a ->
134 Yaml.PArchive a ->
135 unroll (a ^. aSubdirs) $ StackPackage (a ^. aArchive . to parseSimplePath) isExtraDep
135 unroll (a ^. aSubdirs) $ StackPackage (a ^. aArchive . to parseSimplePath) isExtraDep
136 Yaml.PNewGit ng -> unroll (ng ^. ngSubdirs)
136 Yaml.PNewGit ng -> unroll (ng ^. ngSubdirs)
137− $ StackPackage (StackRepo $ fromYamlNewGit ng) isExtraDep
137+ $ StackPackage (PlRepo $ fromYamlNewGit ng) isExtraDep
138 Yaml.PNewHg nh -> unroll (nh ^. nhSubdirs)
138 Yaml.PNewHg nh -> unroll (nh ^. nhSubdirs)
139− $ StackPackage (StackRepo $ fromYamlNewHg nh) isExtraDep
139+ $ StackPackage (PlRepo $ fromYamlNewHg nh) isExtraDep
140 where
140 where
141 mkStackPackageRepo f loc = unroll (loc ^. lSubdirs)
141 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)
143 -- Each package gets a single directory with cabal file in it. If
143 -- Each package gets a single directory with cabal file in it. If
144 -- it's not specified, path is empty.
144 -- it's not specified, path is empty.
145 unroll subs p = case subs of
145 unroll subs p = case subs of
@@ -174,7 +174,7 @@ readStackConfig :: StackYaml -> IO (Either String StackConfig)
174readStackConfig stackYaml = do
174readStackConfig stackYaml = do
175 let
175 let
176 relativeToStackYaml = \case
176 relativeToStackYaml = \case
177− StackFilePath p -> StackFilePath $ stackYaml ^. syDirName </> p
177+ PlFilePath p -> PlFilePath $ stackYaml ^. syDirName </> p
178 packageLocation -> packageLocation
178 packageLocation -> packageLocation
179 mkStackConfig = over (scPackages . traversed . spLocation) relativeToStackYaml
179 mkStackConfig = over (scPackages . traversed . spLocation) relativeToStackYaml
180 . fromYamlConfig
180 . fromYamlConfig
src/Stack/Config/Yaml.hs+2−2
@@ -93,8 +93,8 @@ instance ToJSON Package where
93 PNewGit t -> toJSON t
93 PNewGit t -> toJSON t
94 PNewHg t -> toJSON t
94 PNewHg t -> toJSON t
95
95
96−-- To support support both old and new syntax, we allow all varieties of package
96+-- To support both old and new syntax, we allow all variants of package
97−-- definitions in both "packages" and "extra-deps" sections
97+-- definitions in "packages" and "extra-deps" sections
98data Config = Config
98data Config = Config
99 { _cResolver :: Text
99 { _cResolver :: Text
100 , _cPackages :: Maybe [Package]
100 , _cPackages :: Maybe [Package]
stackage2nix.cabal+2
@@ -77,6 +77,7 @@ test-suite spec
77 , Cabal
77 , Cabal
78 , bytestring
78 , bytestring
79 , hspec
79 , hspec
80+ , network-uri
80 , pretty
81 , pretty
81 , shakespeare
82 , shakespeare
82 , stackage2nix
83 , stackage2nix
@@ -86,6 +87,7 @@ test-suite spec
86 other-modules: Language.Nix.FilePathSpec
87 other-modules: Language.Nix.FilePathSpec
87 , PrettyPrintingSpec
88 , PrettyPrintingSpec
88 , Stack.Config.YamlSpec
89 , Stack.Config.YamlSpec
90+ , Stack.ConfigSpec
89 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
91 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
90 default-language: Haskell2010
92 default-language: Haskell2010
91
93
test/Stack/Config/YamlSpec.hs+4−4
@@ -148,10 +148,10 @@ configNew = Config
148 }
148 }
149
149
150spec :: Spec
150spec :: Spec
151−spec = describe "Parse" $ do
151+spec = describe "Config" $ do
152− specify "config-minimal" $
152+ specify "minimal" $
153 (Y.decode configYamlMinimal :: Maybe Config) `shouldBe` Just configMinimal
153 (Y.decode configYamlMinimal :: Maybe Config) `shouldBe` Just configMinimal
154− specify "config-full" $
154+ specify "full" $
155 (Y.decode configYaml :: Maybe Config) `shouldBe` Just config
155 (Y.decode configYaml :: Maybe Config) `shouldBe` Just config
156− specify "config-new" $
156+ specify "new" $
157 (Y.decode configNewYaml :: Maybe Config) `shouldBe` Just configNew
157 (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+ }