Merge pull request #10493 from Sdywolf/doc-refine/repl
[cabal.git] / cabal-testsuite / PackageTests / ConditionalAndImport / cabal.test.hs
blobc1aea47ce85d7f81231385581a7e9adc2d9324d0
1 import Test.Cabal.Prelude
3 normalizeWindowsOutput :: String -> String
4 normalizeWindowsOutput = if isWindows then map (\x -> case x of '/' -> '\\'; _ -> x) else id
6 main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
7 let log = recordHeader . pure
9 cabal "v2-run" [ "some-exe" ]
11 -- +-- cyclical-0-self.project (imports cyclical-0-self.project)
12 -- +-- cyclical-0-self.project (already processed)
13 -- +-- etc
14 log "checking cyclical loopback of a project importing itself"
15 cyclical0 <- fails $ cabal' "v2-build" [ "--project-file=cyclical-0-self.project" ]
16 assertOutputContains "cyclical import of cyclical-0-self.project" cyclical0
18 -- +-- cyclical-1-out-back.project
19 -- +-- cyclical-1-out-back.config (imports cyclical-1-out-back.project)
20 -- +-- cyclical-1-out-back.project (already processed)
21 -- +-- etc
22 log "checking cyclical with hops; out and back"
23 cyclical1a <- fails $ cabal' "v2-build" [ "--project-file=cyclical-1-out-back.project" ]
24 assertOutputContains "cyclical import of cyclical-1-out-back.project" cyclical1a
26 -- +-- cyclical-1-out-self.project
27 -- +-- cyclical-1-out-self.config (imports cyclical-1-out-self.config)
28 -- +-- cyclical-1-out-self.config (already processed)
29 -- +-- etc
30 log "checking cyclical with hops; out to a config that imports itself"
31 cyclical1b <- fails $ cabal' "v2-build" [ "--project-file=cyclical-1-out-self.project" ]
32 assertOutputContains "cyclical import of cyclical-1-out-self.config" cyclical1b
34 -- +-- cyclical-2-out-out-backback.project
35 -- +-- cyclical-2-out-out-backback-a.config
36 -- +-- cyclical-2-out-out-backback-b.config (imports cyclical-2-out-out-backback.project)
37 -- +-- cyclical-2-out-out-backback.project (already processed)
38 -- +-- etc
39 log "checking cyclical with hops; out, out, twice back"
40 cyclical2a <- fails $ cabal' "v2-build" [ "--project-file=cyclical-2-out-out-backback.project" ]
41 assertOutputContains "cyclical import of cyclical-2-out-out-backback.project" cyclical2a
43 -- +-- cyclical-2-out-out-back.project
44 -- +-- cyclical-2-out-out-back-a.config
45 -- +-- cyclical-2-out-out-back-b.config (imports cyclical-2-out-out-back-a.config)
46 -- +-- cyclical-2-out-out-back-a.config (already processed)
47 -- +-- etc
48 log "checking cyclical with hops; out, out, once back"
49 cyclical2b <- fails $ cabal' "v2-build" [ "--project-file=cyclical-2-out-out-back.project" ]
50 assertOutputContains "cyclical import of cyclical-2-out-out-back-a.config" cyclical2b
52 -- +-- cyclical-2-out-out-self.project
53 -- +-- cyclical-2-out-out-self-a.config
54 -- +-- cyclical-2-out-out-self-b.config (imports cyclical-2-out-out-self-b.config)
55 -- +-- cyclical-2-out-out-self-b.config (already processed)
56 -- +-- etc
57 log "checking cyclical with hops; out, out to a config that imports itself"
58 cyclical2c <- fails $ cabal' "v2-build" [ "--project-file=cyclical-2-out-out-self.project" ]
59 assertOutputContains "cyclical import of cyclical-2-out-out-self-b.config" cyclical2c
61 -- +-- noncyclical-same-filename-a.project
62 -- +-- noncyclical-same-filename-a.config
63 -- +-- same-filename/noncyclical-same-filename-a.config (no further imports so not cyclical)
64 log "checking that cyclical check doesn't false-positive on same file names in different folders; hoping within a folder and then into a subfolder"
65 cyclical3b <- cabal' "v2-build" [ "--project-file=noncyclical-same-filename-a.project" ]
66 assertOutputDoesNotContain "cyclical import of" cyclical3b
68 -- +-- noncyclical-same-filename-b.project
69 -- +-- same-filename/noncyclical-same-filename-b.config
70 -- +-- noncyclical-same-filename-b.config (no further imports so not cyclical)
71 log "checking that cyclical check doesn't false-positive on same file names in different folders; hoping into a subfolder and then back out again"
72 cyclical3c <- cabal' "v2-build" [ "--project-file=noncyclical-same-filename-b.project" ]
73 assertOutputDoesNotContain "cyclical import of" cyclical3c
75 -- +-- cyclical-same-filename-out-out-self.project
76 -- +-- cyclical-same-filename-out-out-self.config
77 -- +-- same-filename/cyclical-same-filename-out-out-self.config
78 -- +-- same-filename/cyclical-same-filename-out-out-self.config (already processed)
79 -- +-- etc
80 log "checking that cyclical check catches a same file name that imports itself"
81 cyclical4a <- fails $ cabal' "v2-build" [ "--project-file=cyclical-same-filename-out-out-self.project" ]
82 assertOutputContains (normalizeWindowsOutput "cyclical import of same-filename/cyclical-same-filename-out-out-self.config") cyclical4a
84 -- +-- cyclical-same-filename-out-out-backback.project
85 -- +-- cyclical-same-filename-out-out-backback.config
86 -- +-- same-filename/cyclical-same-filename-out-out-backback.config
87 -- +-- cyclical-same-filename-out-out-backback.project (already processed)
88 -- +-- etc
89 log "checking that cyclical check catches importing its importer (with the same file name)"
90 cyclical4b <- fails $ cabal' "v2-build" [ "--project-file=cyclical-same-filename-out-out-backback.project" ]
91 assertOutputContains "cyclical import of cyclical-same-filename-out-out-backback.project" cyclical4b
93 -- +-- cyclical-same-filename-out-out-back.project
94 -- +-- cyclical-same-filename-out-out-back.config
95 -- +-- same-filename/cyclical-same-filename-out-out-back.config
96 -- +-- cyclical-same-filename-out-out-back.config (already processed)
97 -- +-- etc
98 log "checking that cyclical check catches importing its importer's importer (hopping over same file names)"
99 cyclical4c <- fails $ cabal' "v2-build" [ "--project-file=cyclical-same-filename-out-out-back.project" ]
100 assertOutputContains "cyclical import of cyclical-same-filename-out-out-back.config" cyclical4c
102 -- +-- hops-0.project
103 -- +-- hops/hops-1.config
104 -- +-- hops-2.config
105 -- +-- hops/hops-3.config
106 -- +-- hops-4.config
107 -- +-- hops/hops-5.config
108 -- +-- hops-6.config
109 -- +-- hops/hops-7.config
110 -- +-- hops-8.config
111 -- +-- hops/hops-9.config (no further imports so not cyclical)
112 log "checking that imports work skipping into a subfolder and then back out again and again"
113 hopping <- cabal' "v2-build" [ "--project-file=hops-0.project" ]
114 assertOutputContains "this build was affected by the following (project) config files:" hopping
115 assertOutputContains "- hops-0.project" hopping
117 assertOutputContains
118 (normalizeWindowsOutput "- hops-2.config \
119 \ imported by: hops/hops-1.config \
120 \ imported by: hops-0.project")
121 hopping
123 assertOutputContains
124 (normalizeWindowsOutput "- hops-4.config \
125 \ imported by: hops/hops-3.config \
126 \ imported by: hops-2.config \
127 \ imported by: hops/hops-1.config \
128 \ imported by: hops-0.project")
129 hopping
131 assertOutputContains
132 (normalizeWindowsOutput "- hops-6.config \
133 \ imported by: hops/hops-5.config \
134 \ imported by: hops-4.config \
135 \ imported by: hops/hops-3.config \
136 \ imported by: hops-2.config \
137 \ imported by: hops/hops-1.config \
138 \ imported by: hops-0.project")
139 hopping
141 assertOutputContains
142 (normalizeWindowsOutput "- hops-8.config \
143 \ imported by: hops/hops-7.config \
144 \ imported by: hops-6.config \
145 \ imported by: hops/hops-5.config \
146 \ imported by: hops-4.config \
147 \ imported by: hops/hops-3.config \
148 \ imported by: hops-2.config \
149 \ imported by: hops/hops-1.config \
150 \ imported by: hops-0.project")
151 hopping
153 assertOutputContains
154 (normalizeWindowsOutput "- hops/hops-1.config \
155 \ imported by: hops-0.project")
156 hopping
158 assertOutputContains
159 (normalizeWindowsOutput "- hops/hops-3.config \
160 \ imported by: hops-2.config \
161 \ imported by: hops/hops-1.config \
162 \ imported by: hops-0.project")
163 hopping
165 assertOutputContains
166 (normalizeWindowsOutput "- hops/hops-5.config \
167 \ imported by: hops-4.config \
168 \ imported by: hops/hops-3.config \
169 \ imported by: hops-2.config \
170 \ imported by: hops/hops-1.config \
171 \ imported by: hops-0.project")
172 hopping
174 assertOutputContains
175 (normalizeWindowsOutput "- hops/hops-7.config \
176 \ imported by: hops-6.config \
177 \ imported by: hops/hops-5.config \
178 \ imported by: hops-4.config \
179 \ imported by: hops/hops-3.config \
180 \ imported by: hops-2.config \
181 \ imported by: hops/hops-1.config \
182 \ imported by: hops-0.project")
183 hopping
185 assertOutputContains
186 (normalizeWindowsOutput "- hops/hops-9.config \
187 \ imported by: hops-8.config \
188 \ imported by: hops/hops-7.config \
189 \ imported by: hops-6.config \
190 \ imported by: hops/hops-5.config \
191 \ imported by: hops-4.config \
192 \ imported by: hops/hops-3.config \
193 \ imported by: hops-2.config \
194 \ imported by: hops/hops-1.config \
195 \ imported by: hops-0.project")
196 hopping
198 -- The project is named oops as it is like hops but has conflicting constraints.
199 -- +-- oops-0.project
200 -- +-- oops/oops-1.config
201 -- +-- oops-2.config
202 -- +-- oops/oops-3.config
203 -- +-- oops-4.config
204 -- +-- oops/oops-5.config
205 -- +-- oops-6.config
206 -- +-- oops/oops-7.config
207 -- +-- oops-8.config
208 -- +-- oops/oops-9.config (has conflicting constraints)
209 log "checking conflicting constraints skipping into a subfolder and then back out again and again"
210 oopsing <- fails $ cabal' "v2-build" [ "all", "--project-file=oops-0.project" ]
211 assertOutputContains "rejecting: hashable-1.4.2.0" oopsing
212 assertOutputContains "rejecting: hashable-1.4.3.0" oopsing
213 assertOutputContains "(constraint from oops-0.project requires ==1.4.3.0)" oopsing
215 assertOutputContains
216 (normalizeWindowsOutput " (constraint from oops/oops-9.config requires ==1.4.2.0) \
217 \ imported by: oops-8.config \
218 \ imported by: oops/oops-7.config \
219 \ imported by: oops-6.config \
220 \ imported by: oops/oops-5.config \
221 \ imported by: oops-4.config \
222 \ imported by: oops/oops-3.config \
223 \ imported by: oops-2.config \
224 \ imported by: oops/oops-1.config \
225 \ imported by: oops-0.project")
226 oopsing
228 log "checking bad conditional"
229 badIf <- fails $ cabal' "v2-build" [ "--project-file=bad-conditional.project" ]
230 assertOutputContains "Cannot set compiler in a conditional clause of a cabal project file" badIf
232 log "checking that missing package message lists configuration provenance"
233 missing <- fails $ cabal' "v2-build" [ "--project-file=cabal-missing-package.project" ]
234 assertOutputContains
235 (normalizeWindowsOutput "When using configuration from: \
236 \ - cabal-missing-package.project \
237 \ - missing/pkgs.config \
238 \ - missing/pkgs/default.config \
239 \The following errors occurred: \
240 \ - The package location 'pkg-doesnt-exist' does not exist.")
241 missing
243 return ()