From fc8b82c1377409538fd885a895a88fbeec1c5e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20=28Dibildos=29=20Gonz=C3=A1lez?= Date: Wed, 4 Oct 2023 11:22:45 +0200 Subject: [PATCH 1/4] Set default module to prerelease to 'dev' --- private/Microsoft.PowerShell.Core.Dependency.ps1 | 5 +++-- public/Add-ModuleV3.ps1 | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/private/Microsoft.PowerShell.Core.Dependency.ps1 b/private/Microsoft.PowerShell.Core.Dependency.ps1 index 59166e7..7a60e9d 100644 --- a/private/Microsoft.PowerShell.Core.Dependency.ps1 +++ b/private/Microsoft.PowerShell.Core.Dependency.ps1 @@ -4,9 +4,10 @@ function script:New-MyModuleManifest { [CmdletBinding()] param( [Parameter(Mandatory)][string]$Path, - [Parameter(Mandatory)][string]$RootModule + [Parameter(Mandatory)][string]$RootModule, + [Parameter(Mandatory)][string]$PreRelease ) - New-ModuleManifest -Path $Path -RootModule $RootModule + New-ModuleManifest -Path $Path -RootModule $RootModule -PreRelease $PreRelease } function script:Update-MyModuleManifest { diff --git a/public/Add-ModuleV3.ps1 b/public/Add-ModuleV3.ps1 index afe4030..28f2e70 100644 --- a/public/Add-ModuleV3.ps1 +++ b/public/Add-ModuleV3.ps1 @@ -40,7 +40,7 @@ function Add-ModuleV3 { try { # Create the PSD1 file - New-MyModuleManifest -Path $psd1Path -RootModule $rootModule + New-MyModuleManifest -Path $psd1Path -RootModule $rootModule -PreRelease "dev" # Update with metadata if ($Metadata.Count -gt 0) { From 1e190c49878b8f654a1477947c465caa6c9ef6eb Mon Sep 17 00:00:00 2001 From: rulasg Date: Wed, 4 Oct 2023 12:25:52 +0200 Subject: [PATCH 2/4] Add test check for dev and others --- .../New-ModuleV3-Add-ModuleV3.Tests.ps1 | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 b/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 index 032e630..24bb284 100644 --- a/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 +++ b/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 @@ -39,6 +39,8 @@ function TestingHelperTest_NewModuleV3_AddModule_DefaultManifest { $defaultsManifest = Get-DefaultsManifest + $defaultsManifest.PrivateData.PSData.Prerelease = 'dev' + Assert-AreEqualPath -Expected $moduleName -Presented $result Assert-AddModuleV3 -Path $moduleName -Expected $defaultsManifest @@ -48,6 +50,7 @@ function TestingHelperTest_NewModuleV3_AddModule_MyManifest { $moduleName = "MyModule" + # Metadata is really the posible parameters for Update-ModuleManifest $param = @{ RootModule = "MyModule.psm1" Author = "Me" @@ -56,11 +59,28 @@ function TestingHelperTest_NewModuleV3_AddModule_MyManifest { Description = "MyDescription of the module" FunctionsToExport = @("MyFunction") CopyRight = "(c) 2020 MyCompany. All rights reserved." + Prerelease = "radompre" } - + $result = Add-TT_ModuleV3 -Name $moduleName -Metadata $param - Assert-AddModuleV3 -Path $result -Expected $param + $ExpectedMetadata = @{ + RootModule = $param.RootModule + Author = $param.Author + CompanyName = $param.CompanyName + ModuleVersion = $param.ModuleVersion + Description = $param.Description + FunctionsToExport = $param.FunctionsToExport + Copyright = $param.CopyRight + } + + $ExpectedMetadata.PrivateData = @{ + PSData = @{ + Prerelease = $param.Prerelease + } + } + + Assert-AddModuleV3 -Path $result -Expected $ExpectedMetadata } From 3434272018fa0ed8117eb1d0c1fad85b16bb7192 Mon Sep 17 00:00:00 2001 From: rulasg Date: Wed, 4 Oct 2023 20:39:37 +0200 Subject: [PATCH 3/4] Add test to check prerelease tag --- public/Add-ModuleV3.ps1 | 1 + public/Add-TestModuleV3.ps1 | 3 +++ 2 files changed, 4 insertions(+) diff --git a/public/Add-ModuleV3.ps1 b/public/Add-ModuleV3.ps1 index 28f2e70..ce64dae 100644 --- a/public/Add-ModuleV3.ps1 +++ b/public/Add-ModuleV3.ps1 @@ -40,6 +40,7 @@ function Add-ModuleV3 { try { # Create the PSD1 file + # Default Prerelease to 'dev' but may be overriten by $metadata New-MyModuleManifest -Path $psd1Path -RootModule $rootModule -PreRelease "dev" # Update with metadata diff --git a/public/Add-TestModuleV3.ps1 b/public/Add-TestModuleV3.ps1 index 6d6361d..1e91920 100644 --- a/public/Add-TestModuleV3.ps1 +++ b/public/Add-TestModuleV3.ps1 @@ -20,6 +20,9 @@ function Add-TestModuleV3 { $manifest.Remove('Name') $manifest.Remove('RootModule') $manifest.Remove('GUID') + + #match the prerelease field with module + $manifest.Prerelease = $manifest.PrivateData.PSData.Prerelease } # TODO: Not sure how to mangage Force on Add-Module functions From d06636d509d45d62c6458a614fbf9a479111eccc Mon Sep 17 00:00:00 2001 From: rulasg Date: Wed, 4 Oct 2023 20:43:57 +0200 Subject: [PATCH 4/4] Fix bug for adding PreRelease to injected function. --- .../New-ModuleV3-Add-ModuleV3.Tests.ps1 | 52 +++++++++++-------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 b/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 index 24bb284..bd87b8b 100644 --- a/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 +++ b/TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1 @@ -2,33 +2,39 @@ function TestingHelperTest_NewModuleV3_AddModule_FailCall_NewModuleManifest { # test when failing calling dependency Microsoft PowerShell.Core/New-ModuleManifest - - $modulename = "MyModule" - # Inject depepdency - $module = Import-Module -Name $TESTED_MANIFEST_PATH -Prefix "LL_" -Force -PassThru - & $module { - . { - function script:New-MyModuleManifest { - [CmdletBinding()] - param( - [Parameter(Mandatory)][string]$Path, - [Parameter(Mandatory)][string]$RootModule - ) - throw "Injected error from New-MymoduleManifest." + try { + + $modulename = "MyModule" + + # Inject depepdency + $module = Import-Module -Name $TESTED_MANIFEST_PATH -Prefix "LL_" -Force -PassThru + & $module { + . { + function script:New-MyModuleManifest { + [CmdletBinding()] + param( + [Parameter(Mandatory)][string]$Path, + [Parameter(Mandatory)][string]$RootModule, + [Parameter(Mandatory)][string]$PreRelease + ) + throw "Injected error from New-MymoduleManifest." + } + } } + + $result = Add-LL_ModuleV3 -Name $modulename @ErrorParameters + + Assert-IsNull -Object $result -Comment "No module is created" + Assert-IsNotNull -Object $errorVar.Exception -Comment "Error is thrown" + Assert-Contains -Expected "Injected error from New-MymoduleManifest." -Presented ($errorVar.Exception.Message) + Assert-ContainsPattern -Expected "Error creating the PSD1 file.*" -Presented ($errorVar.Exception.Message) + } + finally { + # reset module + Import-Module -Name $TESTED_MANIFEST_PATH -Prefix "TT_" -Force } - } - - $result = Add-LL_ModuleV3 -Name $modulename @ErrorParameters - - Assert-IsNull -Object $result -Comment "No module is created" - Assert-IsNotNull -Object $errorVar.Exception -Comment "Error is thrown" - Assert-Contains -Expected "Injected error from New-MymoduleManifest." -Presented ($errorVar.Exception.Message) - Assert-ContainsPattern -Expected "Error creating the PSD1 file.*" -Presented ($errorVar.Exception.Message) - # reset module - Import-Module -Name $TESTED_MANIFEST_PATH -Prefix "TT_" -Force } function TestingHelperTest_NewModuleV3_AddModule_DefaultManifest {