@@ -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+ }