From da44fb6a9224e5c015d6dec6f1d0ee7613aa9a69 Mon Sep 17 00:00:00 2001 From: rulasg Date: Thu, 6 Jul 2023 20:46:21 +0200 Subject: [PATCH 1/8] Bug: Not addin SampleSource on AddAll ; Check that Name and Path cannot be both null --- public/New-ModuleV3.ps1 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/public/New-ModuleV3.ps1 b/public/New-ModuleV3.ps1 index abb109b..454c80b 100644 --- a/public/New-ModuleV3.ps1 +++ b/public/New-ModuleV3.ps1 @@ -64,6 +64,11 @@ function New-ModuleV3 { # Add deploy workflow [Parameter()][switch]$AddDeployWorkflow ) + # check that Name and Path are not both empty + if(!$Name -and !$Path){ + Write-Error "Name and Path cannot be both empty" + return $null + } $retModulePath = $null @@ -76,7 +81,7 @@ function New-ModuleV3 { } # If asked for testing add sample code on both modules - $AddSampleCode = $AddSampleCode -or $AddTesting + $AddSampleCode = $AddSampleCode -or $AddTesting -or $AddAll # Create the module if ($moduleName) { From 85111ca77396ec61c8bafce7b2084fff92eeb74d Mon Sep 17 00:00:00 2001 From: rulasg Date: Fri, 28 Jul 2023 13:23:17 +0200 Subject: [PATCH 2/8] wop --- .../public/New-ModuleV3.Tests.ps1 | 24 +++++++++++++++++-- private/Add-ToModule.Helper.ps1 | 3 +++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/TestingHelperTest/public/New-ModuleV3.Tests.ps1 b/TestingHelperTest/public/New-ModuleV3.Tests.ps1 index b7d97fe..9c5ed3b 100644 --- a/TestingHelperTest/public/New-ModuleV3.Tests.ps1 +++ b/TestingHelperTest/public/New-ModuleV3.Tests.ps1 @@ -30,7 +30,7 @@ function TestingHelperTest_NewModuleV3_WithName_RemotePath { Assert-AddModuleV3 -Path $expectedPath } -function TestingHelperTest_NewModuleV3_WithOutName { +function TestingHelperTest_NewModuleV3_WithOutName_LocalPath { # Error as the name is mandatory @@ -40,9 +40,29 @@ function TestingHelperTest_NewModuleV3_WithOutName { $result = New-TT_ModuleV3 @ErrorParameters Assert-IsNull -Object $result - Assert-Contains -Expected "Path and Name cannot be null or empty at the same time." -Presented $errorVar.Exception.Message + Assert-Contains -Expected "Name and Path cannot be both empty" -Presented $errorVar.Exception.Message } +function TestingHelperTest_NewModuleV3_WithOutName_withPath { + + $folder = New-TestingFolder -Name "ModulefolderName" -PassThru + + $result = New-TT_ModuleV3 -Path $folder @ErrorParameters + + Assert-AreEqualPath -Expected $folder -Presented $result + Assert-AddModuleV3 -Path $folder +} + +function TestingHelperTest_NewModuleV3_WithOutName_WithPath_AddAll { + + $folder = New-TestingFolder -Name "ModulefolderName" -PassThru + + $result = New-TT_ModuleV3 -Path $folder -AddAll @ErrorParameters + + Assert-AreEqualPath -Expected $folder -Presented $result + Assert-AddAll -Path $folder + +} function TestingHelperTest_NewModuleV3_AddTesting{ $moduleName = "MyModule" diff --git a/private/Add-ToModule.Helper.ps1 b/private/Add-ToModule.Helper.ps1 index 355ebf5..6da6ead 100644 --- a/private/Add-ToModule.Helper.ps1 +++ b/private/Add-ToModule.Helper.ps1 @@ -13,6 +13,9 @@ function ReturnValue($Path,$Force, $Passthru){ } # Normalize $Path and returns $null if not valid +# If $Path is a file, returns the parent folder +# If $Path is $null or empty, returns the current folder +# Path needs to be a valid path function NormalizePath($Path){ # Path returned should be the folder where the module is located. From 1040d38f04e1dbc6973c0592249ba27cdc30b1bf Mon Sep 17 00:00:00 2001 From: rulasg Date: Tue, 8 Aug 2023 14:37:37 +0200 Subject: [PATCH 3/8] bug: typo --- .github/workflows/deploy_module_on_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy_module_on_release.yml b/.github/workflows/deploy_module_on_release.yml index 00a25b1..9a09235 100644 --- a/.github/workflows/deploy_module_on_release.yml +++ b/.github/workflows/deploy_module_on_release.yml @@ -34,7 +34,7 @@ jobs: $tag = $env:RELEASE_TAG write-host -message "Release [$env:RELEASE_NAME] on tag [$tag]" } else { - # Read Tag o Branch name + # Read Tag or Branch name $tag = $env:EVENT_REF.Split('/')[2] write-host "workflow_dispatch triggered on ref leaf [$tag]" } From ab44cccfd86049e22de6193b7c6bfedc66083563 Mon Sep 17 00:00:00 2001 From: rulasg Date: Tue, 8 Aug 2023 14:38:21 +0200 Subject: [PATCH 4/8] Diagnostics.CodeAnalysis.SuppressMessage --- private/Git.Dependency.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/private/Git.Dependency.ps1 b/private/Git.Dependency.ps1 index 18846cb..9957277 100644 --- a/private/Git.Dependency.ps1 +++ b/private/Git.Dependency.ps1 @@ -23,6 +23,7 @@ function Reset-GitRepoConfiguration { if ($PSCmdlet.ShouldProcess("git config user.email", "Init to [you@example.com] ")) { $result1 = git -C $Path config user.email $userEmail if($LASTEXITCODE -ne 0){ + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')] $GITLASTERROR = "Git config user.email failed - $result1" return $null } @@ -58,6 +59,7 @@ function script:Invoke-GitRepositoryInit{ # check if git is installed $gitPath = Get-Command -Name git -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source if(!$gitPath){ + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')] $GITLASTERROR = "Git is not installed" return $null } From 321c8d2c023b21b823cb43af8359ebd46c73497e Mon Sep 17 00:00:00 2001 From: rulasg Date: Sun, 29 Oct 2023 10:34:42 +0100 Subject: [PATCH 5/8] suppress PSUseDeclaredVarsMoreThanAssignments --- private/Git.Dependency.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private/Git.Dependency.ps1 b/private/Git.Dependency.ps1 index 9957277..de52cca 100644 --- a/private/Git.Dependency.ps1 +++ b/private/Git.Dependency.ps1 @@ -7,6 +7,7 @@ $GITLASTERROR = $null # Reset git configuration function Reset-GitRepoConfiguration { [CmdletBinding(SupportsShouldProcess)] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function')] param( [Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)] [Alias("PSPath")][ValidateNotNullOrEmpty()] @@ -23,7 +24,6 @@ function Reset-GitRepoConfiguration { if ($PSCmdlet.ShouldProcess("git config user.email", "Init to [you@example.com] ")) { $result1 = git -C $Path config user.email $userEmail if($LASTEXITCODE -ne 0){ - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')] $GITLASTERROR = "Git config user.email failed - $result1" return $null } From c3262a66703fc008f47cc6d603b4ed9bb774f66c Mon Sep 17 00:00:00 2001 From: rulasg Date: Fri, 1 Dec 2023 22:09:39 +0100 Subject: [PATCH 6/8] improving testing.ps1 --- test.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.ps1 b/test.ps1 index 65cc1c6..6379ca5 100644 --- a/test.ps1 +++ b/test.ps1 @@ -71,7 +71,7 @@ Import-TestingHelper -AllowPrerelease # Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName StagingModuleTest_* if($TestName){ - Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName $TestName + Invoke-TestingHelper -TestName $TestName } else { - Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors + Invoke-TestingHelper } \ No newline at end of file From dfdc3a6b50124957d49671116319345acc5e733a Mon Sep 17 00:00:00 2001 From: rulasg Date: Fri, 1 Dec 2023 23:03:48 +0100 Subject: [PATCH 7/8] fix test bug --- TestingHelperTest/public/New-ModuleV3.Tests.ps1 | 10 ++++++---- public/Add-ToModule.ps1 | 4 ++-- public/New-ModuleV3.ps1 | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/TestingHelperTest/public/New-ModuleV3.Tests.ps1 b/TestingHelperTest/public/New-ModuleV3.Tests.ps1 index 9c5ed3b..b461eac 100644 --- a/TestingHelperTest/public/New-ModuleV3.Tests.ps1 +++ b/TestingHelperTest/public/New-ModuleV3.Tests.ps1 @@ -46,22 +46,24 @@ function TestingHelperTest_NewModuleV3_WithOutName_LocalPath { function TestingHelperTest_NewModuleV3_WithOutName_withPath { $folder = New-TestingFolder -Name "ModulefolderName" -PassThru + $finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName" $result = New-TT_ModuleV3 -Path $folder @ErrorParameters - Assert-AreEqualPath -Expected $folder -Presented $result - Assert-AddModuleV3 -Path $folder + Assert-AreEqualPath -Expected $finalFolder -Presented $result + Assert-AddModuleV3 -Path $finalFolder } function TestingHelperTest_NewModuleV3_WithOutName_WithPath_AddAll { $folder = New-TestingFolder -Name "ModulefolderName" -PassThru + $finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName" $result = New-TT_ModuleV3 -Path $folder -AddAll @ErrorParameters - Assert-AreEqualPath -Expected $folder -Presented $result + Assert-AreEqualPath -Expected $finalFolder -Presented $result Assert-AddAll -Path $folder - + } function TestingHelperTest_NewModuleV3_AddTesting{ diff --git a/public/Add-ToModule.ps1 b/public/Add-ToModule.ps1 index 3903a43..fd29f0d 100644 --- a/public/Add-ToModule.ps1 +++ b/public/Add-ToModule.ps1 @@ -23,10 +23,10 @@ function Add-ToModuleSampleCode{ $modulePath = NormalizePath -Path:$Path ?? return $null $destination = $modulePath | Join-Path -ChildPath "public" - Import-Template -Path $destination -File "samplePublicFunction.ps1" -Template "template.module.functions.public.ps1" + $null = Import-Template -Path $destination -File "samplePublicFunction.ps1" -Template "template.module.functions.public.ps1" $destination = $modulePath | Join-Path -ChildPath "private" - Import-Template -Path $destination -File "samplePrivateFunction.ps1" -Template "template.module.functions.private.ps1" + $null = Import-Template -Path $destination -File "samplePrivateFunction.ps1" -Template "template.module.functions.private.ps1" return ReturnValue -Path $Path -Force:$Force -Passthru:$Passthru } diff --git a/public/New-ModuleV3.ps1 b/public/New-ModuleV3.ps1 index 454c80b..ef8304a 100644 --- a/public/New-ModuleV3.ps1 +++ b/public/New-ModuleV3.ps1 @@ -72,7 +72,7 @@ function New-ModuleV3 { $retModulePath = $null - $modulePath = Get-ModulePath -RootPath $Path -Name $Name + $modulePath = Get-ModulePath -RootPath $Path -Name $Name $moduleName = Get-ModuleName -Path $modulePath # check $modulePath and return if null From dba891a904f908a9b99756361647ed8f27561964 Mon Sep 17 00:00:00 2001 From: rulasg Date: Fri, 1 Dec 2023 23:04:44 +0100 Subject: [PATCH 8/8] Allow call Invoke-TetingHelper without Path --- public/Invoke-TestingHelper.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/public/Invoke-TestingHelper.ps1 b/public/Invoke-TestingHelper.ps1 index 65ef05f..d4c6a2b 100644 --- a/public/Invoke-TestingHelper.ps1 +++ b/public/Invoke-TestingHelper.ps1 @@ -81,6 +81,12 @@ function Invoke-TestingHelper { process { + if([string]::IsNullOrWhiteSpace($Path)) { + $Path = '.' + } + + "Inovking Testing Helper on path [$Path]" | Write-Verbose + $manifest = Get-ModuleManifest -Path ($Path | Convert-Path) $testingmodulemanifest = Get-TestingModuleManifest -ModulePath $manifest.Path $versionString = "{0} {1} {2}" -f $manifest.Name, $manifest.ModuleVersion, $manifest.PrivateData.PSData.Prerelease