Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit e77e4aa

Browse files
committed
Throw error when Test-ModuleManifest fails in Update-ModuleManifest
1 parent 16a13fa commit e77e4aa

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

Tests/PSGetUpdateModuleManifest.Tests.ps1

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,19 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
686686
-expectedFullyQualifiedErrorId "InvalidPackageManagementProviders,Update-ModuleManifest"
687687
}
688688

689+
# Purpose: Validate Update-ModuleManifest will throw errors when an invalid RootModule is provided
690+
#
691+
# Action:
692+
# Update-ModuleManifest -RootModule [InvalidRootModule]
693+
#
694+
# Expected Result: Update-ModuleManifest should throw errors about the invalid RootModule
695+
#
696+
It UpdateModuleManifestWithInvalidRootModule {
697+
New-ModuleManifest -path $script:testManifestPath
698+
$RootModule = "\/"
699+
AssertFullyQualifiedErrorIdEquals -scriptblock {Update-ModuleManifest -Path $script:testManifestPath -RootModule $InvalidRootModule} `
700+
-expectedFullyQualifiedErrorId "ParameterArgumentValidationError,Update-ModuleManifest"
701+
}
689702

690703
# Purpose: Validate Update-ModuleManifest will throw errors if the original manifest fail the Test-ModuleManifest
691704
#
@@ -969,4 +982,23 @@ Describe PowerShell.PSGet.UpdateModuleManifest -Tags 'BVT','InnerLoop' {
969982
Assert ($newModuleInfo.CompatiblePSEditions -contains $CompatiblePSEditions[1]) "CompatiblePSEditions should include $($CompatiblePSEditions[1])"
970983
} `
971984
-Skip:$($PSVersionTable.PSVersion -lt '5.1.0')
972-
}
985+
986+
# Purpose : Validate Update-ModuleManifest cmdlet does not update a module manifest file with an invalid root module
987+
# on PowerShell version greater than 5.1
988+
#
989+
# Action:
990+
# Update-ModuleManifest -Path [Path] -RootModule "\/"
991+
#
992+
# Expected Result: Update-ModuleManifest shoyuld not update the field "RootModule" in module manifest file
993+
#
994+
It "UpdateModuleManifestWithInvalidRootModule" {
995+
New-ModuleManifest -path $script:testManifestPath
996+
997+
$InvalidRootModule = "\/"
998+
try { Update-ModuleManifest -Path $script:testManifestPath -RootModule $InvalidRootModule } catch {}
999+
$newModuleInfo = Test-ModuleManifest -Path $script:testManifestPath
1000+
1001+
Assert ($newModuleInfo.RootModule -contains $InvalidRootModule -eq $False) 'Module Manifest should not contain an invalid root module'
1002+
}`
1003+
-Skip:$($PSVersionTable.PSVersion -lt '5.1.0')
1004+
}

src/PowerShellGet/public/psgetfunctions/Update-ModuleManifest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ function Update-ModuleManifest
922922

923923
#Verify the new module manifest is valid
924924
$testModuleInfo = Microsoft.PowerShell.Core\Test-ModuleManifest -Path $tempPath `
925-
-Verbose:$VerbosePreference `
925+
-Verbose:$VerbosePreference ` -ErrorAction Stop
926926
}
927927
#Catch the exceptions from Test-ModuleManifest
928928
catch

0 commit comments

Comments
 (0)