Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions TestingHelperTest/public/Copy-FunctionsToModule.Test.ps1
Original file line number Diff line number Diff line change
@@ -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)
}
33 changes: 33 additions & 0 deletions public/Copy-functionsToModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

function Copy-FunctionsToModule {

Check notice

Code scanning / PSScriptAnalyzer

The cmdlet 'Copy-FunctionsToModule' does not have a help comment.

The cmdlet 'Copy-FunctionsToModule' does not have a help comment.
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

34 changes: 30 additions & 4 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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{

Check warning

Code scanning / PSScriptAnalyzer

Function 'Set-TestName' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.

Function 'Set-TestName' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
[CmdletBinding()]
[Alias("st")]
param (
[Parameter(Position=0,ValueFromPipeline)][string]$TestName
)

process{
$global:TestName = $TestName

Check warning

Code scanning / PSScriptAnalyzer

Found global variable 'global:TestName'.

Found global variable 'global:TestName'.
}
}

function Clear-TestName{
[CmdletBinding()]
[Alias("ct")]
param (
)

$global:TestName = $null

Check warning

Code scanning / PSScriptAnalyzer

Found global variable 'global:TestName'.

Found global variable 'global:TestName'.

Check warning

Code scanning / PSScriptAnalyzer

The variable 'TestName' is assigned but never used.

The variable 'TestName' is assigned but never used.
}

function Import-TestingHelper{
[CmdletBinding()]
param (
Expand Down Expand Up @@ -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

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace

Line has trailing whitespace
# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName StagingModuleTest_*

if($TestName){
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName $TestName
} else {
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors
}