diff --git a/TestingHelperTest/public/Copy-FunctionsToModule.Test.ps1 b/TestingHelperTest/public/Copy-FunctionsToModule.Test.ps1 new file mode 100644 index 0000000..1ca5bd1 --- /dev/null +++ b/TestingHelperTest/public/Copy-FunctionsToModule.Test.ps1 @@ -0,0 +1,45 @@ + +function TestingHelperTest_FunctionsToModule_Copy{ + + New-ModuleV3 -name sourceModule -AddTesting + New-ModuleV3 -name destinationModule -AddTesting + + New-TestingFile -Name Function1.ps1 -Path sourceModule/public + New-TestingFile -Name Function6.txt -Path sourceModule/private/childFolder + New-TestingFile -Name Function2.ps1 -Path sourceModule/private + New-TestingFile -Name Function3.ps1 -Path sourceModule/sourceModuleTest/public + New-TestingFile -Name Function4.ps1 -Path sourceModule/sourceModuleTest/private + + Copy-TT_FunctionsToModule -Source sourceModule -Destination destinationModule + + Assert-ItemExist -path destinationModule/public/Function1.ps1 + Assert-ItemExist -path destinationModule/private/Function2.ps1 + Assert-ItemExist -path destinationModule/private/childFolder/Function6.txt + + Assert-ItemExist -path destinationModule/destinationModuleTest/public/Function3.ps1 + Assert-ItemExist -path destinationModule/destinationModuleTest/private/Function4.ps1 + +} + +function TestingHelperTest_FunctionsToModule_Copy_FilesExist{ + + New-ModuleV3 -name sourceModule -AddTesting + New-ModuleV3 -name destinationModule -AddTesting + + New-TestingFile -Name Function1.ps1 -Content 'Function1 source' -Path sourceModule/public + New-TestingFile -Name Function6.txt -Content 'Function6 source' -Path sourceModule/private/childFolder + New-TestingFile -Name Function2.ps1 -Content 'Function2 source' -Path sourceModule/private + New-TestingFile -Name Function3.ps1 -Content 'Function3 source' -Path sourceModule/sourceModuleTest/public + New-TestingFile -Name Function4.ps1 -Content 'Function4 source' -Path sourceModule/sourceModuleTest/private + + # Adding files on destination + New-TestingFile -Name Function1.ps1 -Content 'Function1 destination' -Path destinationModule/public + New-TestingFile -Name Function6.txt -Content 'Function6 destination' -Path destinationModule/private/childFolder + New-TestingFile -Name Function3.ps1 -Content 'Function3 destination' -Path destinationModule/destinationModuleTest/public + + Copy-TT_FunctionsToModule -Source sourceModule -Destination destinationModule @InfoParameters + + Assert-AreEqual -Expected 'Function1 source' -Presented $(Get-Content -Path destinationModule/public/Function1.ps1) + Assert-AreEqual -Expected 'Function6 source' -Presented $(Get-Content -Path destinationModule/private/childFolder/Function6.txt) + Assert-AreEqual -Expected 'Function3 source' -Presented $(Get-Content -Path destinationModule/destinationModuleTest/public/Function3.ps1) +} diff --git a/public/Copy-functionsToModule.ps1 b/public/Copy-functionsToModule.ps1 new file mode 100644 index 0000000..e261401 --- /dev/null +++ b/public/Copy-functionsToModule.ps1 @@ -0,0 +1,33 @@ + +function Copy-FunctionsToModule { + param( + [Parameter(Mandatory,Position=0)][string]$Source, + [Parameter(Mandatory,Position=1)][string]$Destination + ) + + $Source = Convert-Path $Source + $Destination = Convert-Path $Destination + + $sourceModuleName = $Source | Split-Path -Leaf + $destinationModuleName = $Destination | Split-Path -Leaf + + $sourcePublic = $Source | Join-Path -ChildPath 'public' + $sourcePrivate = $Source | Join-Path -ChildPath 'private' + + $sourceTestPublic = $Source | Join-Path -ChildPath $($sourceModuleName + 'Test') -AdditionalChildPath 'public' + $sourceTestPrivate = $Source | Join-Path -ChildPath $($sourceModuleName + 'Test') -AdditionalChildPath 'private' + + $destinationPublic = $Destination | Join-Path -ChildPath 'public' + $destinationPrivate = $Destination | Join-Path -ChildPath 'private' + + $destinationTestPublic = $Destination | Join-Path -ChildPath $($destinationModuleName + 'Test') -AdditionalChildPath 'public' + $destinationTestPrivate = $Destination | Join-Path -ChildPath $($destinationModuleName + 'Test') -AdditionalChildPath 'private' + + Copy-Item -Path $sourcePublic/* -Destination $destinationPublic -Recurse -Force + Copy-Item -Path $sourcePrivate/* -Destination $destinationPrivate -Recurse -Force + + Copy-Item -Path $sourceTestPublic/* -Destination $destinationTestPublic -Recurse -Force + Copy-Item -Path $sourceTestPrivate/* -Destination $destinationTestPrivate -Recurse -Force + +} Export-ModuleMember -Function Copy-FunctionsToModule + diff --git a/test.ps1 b/test.ps1 index fb2e9e6..65cc1c6 100644 --- a/test.ps1 +++ b/test.ps1 @@ -7,17 +7,37 @@ Using TestingHelper this script will search for a Test module and run the tests This script will be referenced from launch.json to run the tests on VSCode .LINK - https://raw.githubusercontent.com/rulasg/DemoPsModule/main/test.ps1 + https://raw.githubusercontent.com/rulasg/StagingModule/main/test.ps1 .EXAMPLE > ./test.ps1 #> [CmdletBinding()] param ( - #Switch ShowTestErrors [Parameter()][switch]$ShowTestErrors ) +function Set-TestName{ + [CmdletBinding()] + [Alias("st")] + param ( + [Parameter(Position=0,ValueFromPipeline)][string]$TestName + ) + + process{ + $global:TestName = $TestName + } +} + +function Clear-TestName{ + [CmdletBinding()] + [Alias("ct")] + param ( + ) + + $global:TestName = $null +} + function Import-TestingHelper{ [CmdletBinding()] param ( @@ -47,5 +67,11 @@ function Import-TestingHelper{ Import-TestingHelper -AllowPrerelease # Run test by PSD1 file -# Invoke-TestingHelper -ShowTestErrors:$ShowTestErrors -TestName TestingHelperTest_Deploy_With_VersionTag* -Invoke-TestingHelper -ShowTestErrors:$ShowTestErrors +# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors +# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName StagingModuleTest_* + +if($TestName){ + Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName $TestName +} else { + Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors +} \ No newline at end of file