@@ -247,4 +247,104 @@ switch ($action)
247247 }
248248 }
249249 }
250+
251+ Context ' cmake-file' {
252+ It ' works with FetchContent_Declare' {
253+ $testFile = " $testDir /test.cmake"
254+ @ (
255+ ' FetchContent_Declare(' ,
256+ ' sentry-native' ,
257+ " GIT_REPOSITORY $repoUrl " ,
258+ ' GIT_TAG none # 0.9.1' ,
259+ ' GIT_SHALLOW FALSE' ,
260+ ' GIT_SUBMODULES "external/breakpad"' ,
261+ ' )'
262+ ) | Out-File $testFile
263+ UpdateDependency $testFile
264+ $content = Get-Content $testFile
265+ $content [3 ] | Should -Match " GIT_TAG $currentVersion "
266+ $content [3 ] | Should -Match ' # 0.9.1' # Comment should be preserved
267+ }
268+
269+ It ' works with CMakeLists.txt' {
270+ $testFile = " $testDir /CMakeLists.txt"
271+ @ (
272+ ' cmake_minimum_required(VERSION 3.10)' ,
273+ ' FetchContent_Declare(' ,
274+ ' some-dependency' ,
275+ " GIT_REPOSITORY $repoUrl " ,
276+ ' GIT_TAG v0.0.1' ,
277+ ' )'
278+ ) | Out-File $testFile
279+ UpdateDependency $testFile
280+ $content = Get-Content $testFile
281+ $content [4 ] | Should -Match " GIT_TAG $currentVersion "
282+ }
283+
284+ It ' handles indented GIT_TAG' {
285+ $testFile = " $testDir /test.cmake"
286+ @ (
287+ ' FetchContent_Declare(dependency' ,
288+ " GIT_REPOSITORY $repoUrl " ,
289+ ' GIT_TAG old_version' ,
290+ ' )'
291+ ) | Out-File $testFile
292+ UpdateDependency $testFile
293+ $content = Get-Content $testFile
294+ $content [2 ] | Should -Match " ^\s+GIT_TAG $currentVersion "
295+ }
296+
297+ It ' version pattern match' {
298+ $testFile = " $testDir /test.cmake"
299+ $repo = ' https://github.com/getsentry/sentry-cli'
300+ @ (
301+ ' FetchContent_Declare(' ,
302+ ' sentry-cli' ,
303+ " GIT_REPOSITORY $repo " ,
304+ ' GIT_TAG 0.1.0' ,
305+ ' )'
306+ ) | Out-File $testFile
307+ UpdateDependency $testFile ' ^0\.'
308+ $content = Get-Content $testFile
309+ $content [3 ] | Should -Match ' GIT_TAG 0.28.0'
310+ }
311+
312+ It ' fails when GIT_TAG is missing' {
313+ $testFile = " $testDir /test.cmake"
314+ @ (
315+ ' FetchContent_Declare(' ,
316+ ' dependency' ,
317+ " GIT_REPOSITORY $repoUrl " ,
318+ ' )'
319+ ) | Out-File $testFile
320+ { UpdateDependency $testFile } | Should - Throw ' *Could not find GIT_TAG*'
321+ }
322+
323+ It ' fails when GIT_REPOSITORY is missing' {
324+ $testFile = " $testDir /test.cmake"
325+ @ (
326+ ' FetchContent_Declare(' ,
327+ ' dependency' ,
328+ ' GIT_TAG v1.0.0' ,
329+ ' )'
330+ ) | Out-File $testFile
331+ { UpdateDependency $testFile } | Should - Throw ' *Could not find GIT_REPOSITORY*'
332+ }
333+
334+ It ' detects FetchContent_Declare in any file' {
335+ $testFile = " $testDir /dependency.txt"
336+ @ (
337+ ' Some text before' ,
338+ ' FetchContent_Declare(' ,
339+ ' dependency' ,
340+ " GIT_REPOSITORY $repoUrl " ,
341+ ' GIT_TAG v0.0.1' ,
342+ ' )' ,
343+ ' Some text after'
344+ ) | Out-File $testFile
345+ UpdateDependency $testFile
346+ $content = Get-Content $testFile
347+ $content [4 ] | Should -Match " GIT_TAG $currentVersion "
348+ }
349+ }
250350}
0 commit comments