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]" } diff --git a/TestingHelperTest/public/New-ModuleV3.Tests.ps1 b/TestingHelperTest/public/New-ModuleV3.Tests.ps1 index b7d97fe..b461eac 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,31 @@ 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 + $finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName" + + $result = New-TT_ModuleV3 -Path $folder @ErrorParameters + + 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 $finalFolder -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. diff --git a/private/Git.Dependency.ps1 b/private/Git.Dependency.ps1 index 18846cb..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()] @@ -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 } 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/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 diff --git a/public/New-ModuleV3.ps1 b/public/New-ModuleV3.ps1 index abb109b..ef8304a 100644 --- a/public/New-ModuleV3.ps1 +++ b/public/New-ModuleV3.ps1 @@ -64,10 +64,15 @@ 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 - $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 @@ -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) { 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