@@ -0,0 +1,187 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+{-# LANGUAGE QuasiQuotes #-}
4+module Stack.ConfigSpec (spec) where
7+import Data.List.NonEmpty as NE
8+import Data.Text.Encoding as T
10+import Network.URI as URI
13+import Text.Shakespeare.Text
17+spec = describe "StackConfig" $ do
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
33+parseYamlConfig :: ByteString -> Maybe StackConfig
34+parseYamlConfig = fmap fromYamlConfig . Y.decode
36+checkYamlConfig :: ByteString -> StackConfig -> Expectation
37+checkYamlConfig bs sc = parseYamlConfig bs `shouldBe` Just sc
39+stUri :: String -> URI
41+ let Just uri = parseURI s
44+minimalBs :: ByteString
45+minimalBs = T.encodeUtf8 [st|
49+minimalConf :: StackConfig
50+minimalConf = StackConfig
51+ { _scResolver = StackResolver "lts-10.0"
52+ , _scPackages = NE.fromList
53+ [ StackPackage (PlFilePath ".") False Nothing]
56+packageDefaultBs :: ByteString
57+packageDefaultBs = T.encodeUtf8 [st|
63+packageDefaultConf :: StackConfig
64+packageDefaultConf = minimalConf
66+packageSimpleListBs :: ByteString
67+packageSimpleListBs = T.encodeUtf8 [st|
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 ]
82+packageLocationsBs :: ByteString
83+packageLocationsBs = T.encodeUtf8 [st|
86+ - location: humble/package
90+ - location: https://example.com/foo/bar/baz-0.0.2.tar.gz
95+ git: git@github.com:example/mega-repo
96+ commit: 6a86ee32e5b869a877151f74064572225e1a0000
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")
115+packageExtraDepsBs :: ByteString
116+packageExtraDepsBs = T.encodeUtf8 [st|
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 ]
132+packageMixedBs :: ByteString
133+packageMixedBs = T.encodeUtf8 [st|
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 ]
153+packageExtraDepsNewBs :: ByteString
154+packageExtraDepsNewBs = T.encodeUtf8 [st|
159+ - git: git@github.com:yesodweb/wai
160+ commit: 2f8a8e1b771829f4a8a77c0111352ce45a14c30f
164+ - https://example.com/foo/bar/baz-0.0.2.tar.gz
165+ - archive: http://github.com/yesodweb/wai/archive/2f8a8e1b771829f4a8a77c0111352ce45a14c30f.zip
169+ - archive: ../acme-missiles-0.3.tar.gz
170+ sha256: e563d8b524017a06b32768c4db8eff1f822f3fb22a90320b7e414402647b735b
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