|
| 1 | +Import-Module (Join-Path $PSScriptRoot '..' 'psutils.psd1') |
| 2 | + |
| 3 | +Describe 'Git 模块函数' { |
| 4 | + Context 'Get-GitIgnorePatterns 解析有效行' { |
| 5 | + BeforeAll { |
| 6 | + $testRoot = Join-Path $env:TEMP ("psutils_git_tests_" + [Guid]::NewGuid().ToString()) |
| 7 | + New-Item -ItemType Directory -Path $testRoot | Out-Null |
| 8 | + $gitIgnore = Join-Path $testRoot '.gitignore' |
| 9 | + @( |
| 10 | + '# comment', |
| 11 | + '\#headline', |
| 12 | + '!important', |
| 13 | + '/build/', |
| 14 | + 'dist/', |
| 15 | + 'logs/', |
| 16 | + '/logs', |
| 17 | + 'node_modules', |
| 18 | + '*.log', |
| 19 | + '*.tmp' |
| 20 | + ) | Set-Content -LiteralPath $gitIgnore -Encoding UTF8 |
| 21 | + } |
| 22 | + |
| 23 | + It '应返回解析后的有效模式集合' { |
| 24 | + $patterns = Get-GitIgnorePatterns -GitIgnorePath $gitIgnore |
| 25 | + ($patterns) | Should -Not -Be $null |
| 26 | + $patterns | Should -Contain 'build' |
| 27 | + $patterns | Should -Contain 'dist' |
| 28 | + $patterns | Should -Contain 'logs' |
| 29 | + $patterns | Should -Contain 'node_modules' |
| 30 | + $patterns | Should -Contain '*.log' |
| 31 | + $patterns | Should -Contain '*.tmp' |
| 32 | + $patterns | Should -Contain '#headline' |
| 33 | + $patterns | Should -Not -Contain '!important' |
| 34 | + ((@($patterns | Where-Object { $_ -eq 'logs' }).Count)) | Should -Be 1 |
| 35 | + } |
| 36 | + |
| 37 | + AfterAll { |
| 38 | + Remove-Item -LiteralPath $testRoot -Recurse -Force |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + Context 'New-7ZipExcludeArgs 生成排除参数' { |
| 43 | + BeforeAll { |
| 44 | + $testRoot = Join-Path $env:TEMP ("psutils_git_tests_" + [Guid]::NewGuid().ToString()) |
| 45 | + New-Item -ItemType Directory -Path $testRoot | Out-Null |
| 46 | + $gitIgnore = Join-Path $testRoot '.gitignore' |
| 47 | + @( |
| 48 | + '/build/', |
| 49 | + 'logs/', |
| 50 | + 'node_modules', |
| 51 | + '*.log' |
| 52 | + ) | Set-Content -LiteralPath $gitIgnore -Encoding UTF8 |
| 53 | + } |
| 54 | + |
| 55 | + It '应合并基础、gitignore 和额外排除并去重' { |
| 56 | + $args = New-7ZipExcludeArgs -GitIgnorePath $gitIgnore -AdditionalExcludes @('dist','build/*.tmp','logs') |
| 57 | + ($args) | Should -Not -Be $null |
| 58 | + foreach ($a in $args) { $a | Should -Match '^-xr!.+' } |
| 59 | + $args | Should -Contain '-xr!node_modules' |
| 60 | + $args | Should -Contain '-xr!build' |
| 61 | + $args | Should -Contain '-xr!dist' |
| 62 | + $args | Should -Contain '-xr!logs' |
| 63 | + $args | Should -Contain '-xr!*.log' |
| 64 | + ((@($args | Where-Object { $_ -eq '-xr!logs' }).Count)) | Should -Be 1 |
| 65 | + } |
| 66 | + |
| 67 | + AfterAll { |
| 68 | + Remove-Item -LiteralPath $testRoot -Recurse -Force |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
0 commit comments