@@ -3,13 +3,12 @@ BeforeAll {
33 . " $PSScriptRoot /../scripts/cmake-functions.ps1"
44}
55
6- Describe ' CMake Helper Functions ' {
7- Context ' Parse-CMakeFetchContent ' {
6+ Describe ' Parse-CMakeFetchContent ' {
7+ Context ' Basic single dependency file ' {
88 BeforeAll {
99 $script :tempDir = " $TestDrive /cmake-tests"
1010 New-Item $tempDir - ItemType Directory - Force | Out-Null
1111
12- # Create test files with inline data
1312 $script :basicFile = " $tempDir /basic.cmake"
1413 @'
1514include(FetchContent)
@@ -23,6 +22,33 @@ FetchContent_Declare(
2322
2423FetchContent_MakeAvailable(sentry-native)
2524'@ | Out-File $basicFile
25+ }
26+
27+ It ' parses with explicit dependency name' {
28+ $result = Parse- CMakeFetchContent $basicFile ' sentry-native'
29+
30+ $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
31+ $result.GitTag | Should - Be ' v0.9.1'
32+ $result.DepName | Should - Be ' sentry-native'
33+ }
34+
35+ It ' auto-detects single dependency' {
36+ $result = Parse- CMakeFetchContent $basicFile $null
37+
38+ $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
39+ $result.GitTag | Should - Be ' v0.9.1'
40+ $result.DepName | Should - Be ' sentry-native'
41+ }
42+
43+ It ' throws on missing dependency' {
44+ { Parse- CMakeFetchContent $basicFile ' nonexistent' } | Should - Throw " *FetchContent_Declare for 'nonexistent' not found*"
45+ }
46+ }
47+
48+ Context ' Hash-based dependency file' {
49+ BeforeAll {
50+ $script :tempDir = " $TestDrive /cmake-tests"
51+ New-Item $tempDir - ItemType Directory - Force | Out-Null
2652
2753 $script :hashFile = " $tempDir /hash.cmake"
2854 @'
@@ -38,6 +64,21 @@ FetchContent_Declare(
3864
3965FetchContent_MakeAvailable(sentry-native)
4066'@ | Out-File $hashFile
67+ }
68+
69+ It ' handles hash values correctly' {
70+ $result = Parse- CMakeFetchContent $hashFile ' sentry-native'
71+
72+ $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
73+ $result.GitTag | Should - Be ' a64d5bd8ee130f2cda196b6fa7d9b65bfa6d32e2'
74+ $result.DepName | Should - Be ' sentry-native'
75+ }
76+ }
77+
78+ Context ' Complex formatting file' {
79+ BeforeAll {
80+ $script :tempDir = " $TestDrive /cmake-tests"
81+ New-Item $tempDir - ItemType Directory - Force | Out-Null
4182
4283 $script :complexFile = " $tempDir /complex.cmake"
4384 @'
@@ -57,6 +98,21 @@ FetchContent_Declare(
5798
5899FetchContent_MakeAvailable(sentry-native)
59100'@ | Out-File $complexFile
101+ }
102+
103+ It ' handles complex multi-line formatting' {
104+ $result = Parse- CMakeFetchContent $complexFile ' sentry-native'
105+
106+ $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
107+ $result.GitTag | Should - Be ' v0.9.1'
108+ $result.DepName | Should - Be ' sentry-native'
109+ }
110+ }
111+
112+ Context ' Multiple dependencies file' {
113+ BeforeAll {
114+ $script :tempDir = " $TestDrive /cmake-tests"
115+ New-Item $tempDir - ItemType Directory - Force | Out-Null
60116
61117 $script :multipleFile = " $tempDir /multiple.cmake"
62118 @'
@@ -76,6 +132,25 @@ FetchContent_Declare(
76132
77133FetchContent_MakeAvailable(sentry-native googletest)
78134'@ | Out-File $multipleFile
135+ }
136+
137+ It ' throws on multiple dependencies without explicit name' {
138+ { Parse- CMakeFetchContent $multipleFile $null } | Should - Throw ' *Multiple FetchContent declarations found*'
139+ }
140+
141+ It ' handles specific dependency from multiple dependencies' {
142+ $result = Parse- CMakeFetchContent $multipleFile ' googletest'
143+
144+ $result.GitRepository | Should - Be ' https://github.com/google/googletest'
145+ $result.GitTag | Should - Be ' v1.14.0'
146+ $result.DepName | Should - Be ' googletest'
147+ }
148+ }
149+
150+ Context ' Malformed files' {
151+ BeforeAll {
152+ $script :tempDir = " $TestDrive /cmake-tests"
153+ New-Item $tempDir - ItemType Directory - Force | Out-Null
79154
80155 $script :missingRepoFile = " $tempDir /missing-repo.cmake"
81156 @'
@@ -98,54 +173,6 @@ FetchContent_Declare(
98173'@ | Out-File $missingTagFile
99174 }
100175
101- It ' parses basic FetchContent_Declare with explicit dependency name' {
102- $result = Parse- CMakeFetchContent $basicFile ' sentry-native'
103-
104- $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
105- $result.GitTag | Should - Be ' v0.9.1'
106- $result.DepName | Should - Be ' sentry-native'
107- }
108-
109- It ' auto-detects single FetchContent_Declare' {
110- $result = Parse- CMakeFetchContent $basicFile $null
111-
112- $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
113- $result.GitTag | Should - Be ' v0.9.1'
114- $result.DepName | Should - Be ' sentry-native'
115- }
116-
117- It ' handles hash values correctly' {
118- $result = Parse- CMakeFetchContent $hashFile ' sentry-native'
119-
120- $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
121- $result.GitTag | Should - Be ' a64d5bd8ee130f2cda196b6fa7d9b65bfa6d32e2'
122- $result.DepName | Should - Be ' sentry-native'
123- }
124-
125- It ' handles complex multi-line formatting' {
126- $result = Parse- CMakeFetchContent $complexFile ' sentry-native'
127-
128- $result.GitRepository | Should - Be ' https://github.com/getsentry/sentry-native'
129- $result.GitTag | Should - Be ' v0.9.1'
130- $result.DepName | Should - Be ' sentry-native'
131- }
132-
133- It ' throws on multiple dependencies without explicit name' {
134- { Parse- CMakeFetchContent $multipleFile $null } | Should - Throw ' *Multiple FetchContent declarations found*'
135- }
136-
137- It ' handles specific dependency from multiple dependencies' {
138- $result = Parse- CMakeFetchContent $multipleFile ' googletest'
139-
140- $result.GitRepository | Should - Be ' https://github.com/google/googletest'
141- $result.GitTag | Should - Be ' v1.14.0'
142- $result.DepName | Should - Be ' googletest'
143- }
144-
145- It ' throws on missing dependency' {
146- { Parse- CMakeFetchContent $basicFile ' nonexistent' } | Should - Throw " *FetchContent_Declare for 'nonexistent' not found*"
147- }
148-
149176 It ' throws on missing GIT_REPOSITORY' {
150177 { Parse- CMakeFetchContent $missingRepoFile ' sentry-native' } | Should - Throw ' *Could not parse GIT_REPOSITORY or GIT_TAG*'
151178 }
@@ -154,8 +181,10 @@ FetchContent_Declare(
154181 { Parse- CMakeFetchContent $missingTagFile ' sentry-native' } | Should - Throw ' *Could not parse GIT_REPOSITORY or GIT_TAG*'
155182 }
156183 }
184+ }
157185
158- Context ' Find-TagForHash' {
186+ Describe ' Find-TagForHash' {
187+ Context ' Hash resolution scenarios' {
159188 It ' returns null for hash without matching tag' {
160189 # Use a fake hash that won't match any real tag
161190 $fakeHash = ' abcdef1234567890abcdef1234567890abcdef12'
@@ -179,13 +208,14 @@ FetchContent_Declare(
179208 # Note: Testing actual hash resolution requires network access
180209 # and is better suited for integration tests
181210 }
211+ }
182212
183- Context ' Update-CMakeFile' {
213+ Describe ' Update-CMakeFile' {
214+ Context ' Basic tag updates' {
184215 BeforeAll {
185216 $script :tempDir = " $TestDrive /cmake-update-tests"
186217 New-Item $tempDir - ItemType Directory - Force | Out-Null
187218
188- # Template for basic CMake file
189219 $script :basicTemplate = @'
190220include(FetchContent)
191221
@@ -198,8 +228,47 @@ FetchContent_Declare(
198228
199229FetchContent_MakeAvailable(sentry-native)
200230'@
231+ }
232+
233+ BeforeEach {
234+ $script :basicTestFile = " $tempDir /basic-test.cmake"
235+ }
236+
237+ It ' updates tag to tag preserving format' {
238+ $basicTemplate | Out-File $basicTestFile
239+
240+ Update-CMakeFile $basicTestFile ' sentry-native' ' v0.9.2'
241+
242+ $content = Get-Content $basicTestFile - Raw
243+ $content | Should -Match ' GIT_TAG v0.9.2'
244+ $content | Should -Not -Match ' v0.9.1'
245+ }
246+
247+ It ' preserves file structure and other content' {
248+ $basicTemplate | Out-File $basicTestFile
249+
250+ Update-CMakeFile $basicTestFile ' sentry-native' ' v0.9.2'
251+
252+ $content = Get-Content $basicTestFile - Raw
253+ $content | Should -Match ' include\(FetchContent\)'
254+ $content | Should -Match ' FetchContent_MakeAvailable'
255+ $content | Should -Match ' GIT_REPOSITORY https://github.com/getsentry/sentry-native'
256+ $content | Should -Match ' GIT_SHALLOW FALSE'
257+ }
258+
259+ It ' throws on failed regex match' {
260+ $basicTemplate | Out-File $basicTestFile
261+
262+ # Try to update a dependency that doesn't exist
263+ { Update-CMakeFile $basicTestFile ' nonexistent-dep' ' v1.0.0' } | Should - Throw " *FetchContent_Declare for 'nonexistent-dep' not found*"
264+ }
265+ }
266+
267+ Context ' Hash updates' {
268+ BeforeAll {
269+ $script :tempDir = " $TestDrive /cmake-update-tests"
270+ New-Item $tempDir - ItemType Directory - Force | Out-Null
201271
202- # Template for hash-based CMake file
203272 $script :hashTemplate = @'
204273include(FetchContent)
205274
@@ -211,44 +280,12 @@ FetchContent_Declare(
211280 GIT_SUBMODULES "external/breakpad"
212281)
213282
214- FetchContent_MakeAvailable(sentry-native)
215- '@
216-
217- # Template for complex formatting
218- $script :complexTemplate = @'
219- include(FetchContent)
220-
221- FetchContent_Declare(
222- sentry-native
223- GIT_REPOSITORY
224- https://github.com/getsentry/sentry-native
225- GIT_TAG
226- v0.9.1
227- GIT_SHALLOW
228- FALSE
229- GIT_SUBMODULES
230- "external/breakpad"
231- )
232-
233283FetchContent_MakeAvailable(sentry-native)
234284'@
235285 }
236286
237287 BeforeEach {
238- # Create fresh test files for each test
239- $script :basicTestFile = " $tempDir /basic-test.cmake"
240288 $script :hashTestFile = " $tempDir /hash-test.cmake"
241- $script :complexTestFile = " $tempDir /complex-test.cmake"
242- }
243-
244- It ' updates tag to tag preserving format' {
245- $basicTemplate | Out-File $basicTestFile
246-
247- Update-CMakeFile $basicTestFile ' sentry-native' ' v0.9.2'
248-
249- $content = Get-Content $basicTestFile - Raw
250- $content | Should -Match ' GIT_TAG v0.9.2'
251- $content | Should -Not -Match ' v0.9.1'
252289 }
253290
254291 It ' updates hash to newer hash preserving format' {
@@ -264,17 +301,34 @@ FetchContent_MakeAvailable(sentry-native)
264301 $content | Should -Not -Match ' a64d5bd8ee130f2cda196b6fa7d9b65bfa6d32e2'
265302 $content | Should -Not -Match ' # 0.9.1'
266303 }
304+ }
267305
268- It ' preserves file structure and other content' {
269- $basicTemplate | Out-File $basicTestFile
306+ Context ' Complex formatting' {
307+ BeforeAll {
308+ $script :tempDir = " $TestDrive /cmake-update-tests"
309+ New-Item $tempDir - ItemType Directory - Force | Out-Null
270310
271- Update-CMakeFile $basicTestFile ' sentry-native' ' v0.9.2'
311+ $script :complexTemplate = @'
312+ include(FetchContent)
272313
273- $content = Get-Content $basicTestFile - Raw
274- $content | Should -Match ' include\(FetchContent\)'
275- $content | Should -Match ' FetchContent_MakeAvailable'
276- $content | Should -Match ' GIT_REPOSITORY https://github.com/getsentry/sentry-native'
277- $content | Should -Match ' GIT_SHALLOW FALSE'
314+ FetchContent_Declare(
315+ sentry-native
316+ GIT_REPOSITORY
317+ https://github.com/getsentry/sentry-native
318+ GIT_TAG
319+ v0.9.1
320+ GIT_SHALLOW
321+ FALSE
322+ GIT_SUBMODULES
323+ "external/breakpad"
324+ )
325+
326+ FetchContent_MakeAvailable(sentry-native)
327+ '@
328+ }
329+
330+ BeforeEach {
331+ $script :complexTestFile = " $tempDir /complex-test.cmake"
278332 }
279333
280334 It ' handles complex formatting correctly' {
@@ -286,15 +340,8 @@ FetchContent_MakeAvailable(sentry-native)
286340 $content | Should -Match ' GIT_TAG\s+v0.9.2'
287341 $content | Should -Not -Match ' v0.9.1'
288342 }
289-
290- It ' throws on failed regex match' {
291- $basicTemplate | Out-File $basicTestFile
292-
293- # Try to update a dependency that doesn't exist
294- { Update-CMakeFile $basicTestFile ' nonexistent-dep' ' v1.0.0' } | Should - Throw " *FetchContent_Declare for 'nonexistent-dep' not found*"
295- }
296-
297- # Note: Hash update tests require network access for git ls-remote
298- # and are better suited for integration tests
299343 }
344+
345+ # Note: Hash update tests require network access for git ls-remote
346+ # and are better suited for integration tests
300347}
0 commit comments