|
1 | 1 | #requires -Module ModuleBuilder |
2 | 2 | Describe "Update-AliasesToExport" { |
3 | 3 | BeforeAll { |
4 | | - $ManifestPath = "$TestDrive\TestModule.psd1" |
| 4 | + $ManifestPath = Join-Path $TestDrive "TestModule.psd1" |
5 | 5 | } |
6 | 6 |
|
7 | 7 | Context "Parsing [Alias()] attributes on functions" { |
@@ -234,25 +234,22 @@ Describe "Update-AliasesToExport" { |
234 | 234 | It "Writes a warning and does not throw" { |
235 | 235 | # Minimal manifest without AliasesToExport |
236 | 236 | New-ModuleManifest -Path $ManifestPath |
237 | | - (Get-Content $ManifestPath).ForEach{ |
238 | | - if ($_ -match 'AliasesToExport') { |
239 | | - '# ' + $_ |
240 | | - } else { |
241 | | - $_ |
| 237 | + (Get-Content $ManifestPath) -replace "^(.*AliasesToExport.*)$", '# $1' | Set-Content $ManifestPath |
| 238 | + |
| 239 | + Mock Write-Warning -ModuleName ModuleBuilder |
| 240 | + Mock Update-Metadata -ModuleName ModuleBuilder |
| 241 | + |
| 242 | + Invoke-ScriptGenerator -Code { |
| 243 | + function Test-Alias { |
| 244 | + [Alias("TA")] param() |
242 | 245 | } |
243 | | - } | Set-Content $ManifestPath |
| 246 | + } -Generator Update-AliasesToExport -Parameters @{ ModuleManifest = $ManifestPath } |
244 | 247 |
|
245 | | - try { |
246 | | - Invoke-ScriptGenerator -Code { |
247 | | - function Test-Alias { |
248 | | - [Alias("TA")] param() |
249 | | - } |
250 | | - } -Generator Update-AliasesToExport -Parameters @{ ModuleManifest = $ManifestPath } -WarningAction Stop |
251 | | - } catch { |
252 | | - $FAILURE = $_ |
253 | | - } |
254 | | - $FAILURE | Should -Match 'the preference variable "WarningPreference" or common parameter is set to Stop' |
255 | | - $FAILURE | Should -Match "Can't update AliasesToExport" |
| 248 | + Assert-MockCalled Write-Warning -ModuleName ModuleBuilder -Exactly 1 -Scope It |
| 249 | + # It does not even try to update the metadata |
| 250 | + Assert-MockCalled Update-Metadata -ModuleName ModuleBuilder -Exactly 0 -Scope It |
| 251 | + # It does not, in fact, update the AliasesToExport |
| 252 | + Get-Metadata -Path $ManifestPath -PropertyName AliasesToExport -ErrorAction Ignore | Should -BeNullOrEmpty |
256 | 253 | } |
257 | 254 | } |
258 | 255 |
|
|
0 commit comments