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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Module manifest for module 'DummyModule1Test'
# Module manifest for module 'Test'
#
# Generated by: raulg
#
Expand All @@ -9,7 +9,7 @@
@{

# Script module or binary module file associated with this manifest.
RootModule = 'DummyModule1Test.psm1'
RootModule = 'Test.psm1'

# Version number of this module.
ModuleVersion = '1.0'
Expand Down Expand Up @@ -126,7 +126,7 @@ PrivateData = @{
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
DefaultCommandPrefix = 'DummyModule1Test'
DefaultCommandPrefix = 'Test'

}

Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

Write-Host "Loading DummyModule1Test ..." -ForegroundColor DarkYellow
Write-Host "Loading Test ..." -ForegroundColor DarkYellow

Check warning

Code scanning / PSScriptAnalyzer

File 'Test.psm1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.

File 'Test.psm1' uses Write-Host. Avoid using Write-Host because it might not work in all hosts, does not work when there is no host, and (prior to PS 5.0) cannot be suppressed, captured, or redirected. Instead, use Write-Output, Write-Verbose, or Write-Information.

$InstanceId = New-Guid
function Get-InstanceId{
return $InstanceId
}

function DummyModule1Test_Intro{
function Test_Intro{
Assert-IsTrue -Condition $true
}

function DummyModule1Test_Description{
function Test_Description{

[string] $result = Get-DummyModule1Description

Expand Down
12 changes: 3 additions & 9 deletions TestingHelperTest/private/Add-ModuleSections.Tests.Asserts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ function Assert-AddTestSampleCodes{
process{
$Path = $Path | Convert-Path

$name = $Path | Split-Path -LeafBase
$testingModuleName = $Name + "Test"
$testingModuleName = "Test"
$testingModulePath = $path | Join-Path -ChildPath $testingModuleName

$samplePublicPath = $testingModulePath | Join-Path -ChildPath "public" -AdditionalChildPath SampleFunctionTests.ps1
Expand Down Expand Up @@ -355,10 +354,7 @@ function Assert-AddTestModuleV3{
process{
$Path = $Path | Convert-Path

$name = $Path | Split-Path -LeafBase

# $modulePath = $Path | Join-Path -ChildPath $Name
$testingModuleName = $name + "Test"
$testingModuleName = "Test"
$testingModulePath = $path | Join-Path -ChildPath $testingModuleName

Assert-AddModuleV3 -Path $testingModulePath
Expand All @@ -375,10 +371,8 @@ function Assert-AddTestAll {
process{
$Path = $Path | Convert-Path

$name = $Path | Split-Path -LeafBase

# $modulePath = $Path | Join-Path -ChildPath $Name
$testingModuleName = $name + "Test"
$testingModuleName = "Test"
$testingModulePath = $path | Join-Path -ChildPath $testingModuleName

Assert-AddModuleV3 -Path $testingModulePath
Expand Down
16 changes: 8 additions & 8 deletions TestingHelperTest/public/Copy-FunctionsToModule.Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ function TestingHelperTest_FunctionsToModule_Copy{
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
New-TestingFile -Name Function3.ps1 -Path sourceModule/Test/public
New-TestingFile -Name Function4.ps1 -Path sourceModule/Test/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
Assert-ItemExist -path destinationModule/Test/public/Function3.ps1
Assert-ItemExist -path destinationModule/Test/private/Function4.ps1

}

Expand All @@ -29,17 +29,17 @@ function TestingHelperTest_FunctionsToModule_Copy_FilesExist{
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
New-TestingFile -Name Function3.ps1 -Content 'Function3 source' -Path sourceModule/Test/public
New-TestingFile -Name Function4.ps1 -Content 'Function4 source' -Path sourceModule/Test/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
New-TestingFile -Name Function3.ps1 -Content 'Function3 destination' -Path destinationModule/Test/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)
Assert-AreEqual -Expected 'Function3 source' -Presented $(Get-Content -Path destinationModule/Test/public/Function3.ps1)
}
20 changes: 11 additions & 9 deletions TestingHelperTest/public/Import-Modules.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ function TestingHelperTest_ImportTestingModule_TargetModule{

Import-TT_TestingModule -TargetModule $Dummy1

Assert-IsNotNull -Object (Get-Module -Name ($Dummy1 +"Test"))
Assert-IsNotNull -Object (Get-Module -Name "Test")

$instance1 = Get-DummyModule1TestInstanceId
$instance1 = Get-TestInstanceId

Import-TT_TestingModule -TargetModule $Dummy1 -Force

$instance2 = Get-DummyModule1TestInstanceId
$instance2 = Get-TestInstanceId

Assert-AreNotEqual -Expected $instance1 -Presented $instance2
}
Expand Down Expand Up @@ -45,7 +45,7 @@ function TestingHelperTest_ImportTestingModule_TargetModule_AlreadyLoaded{

Import-TT_TestingModule -TargetModule $Dummy1 @WarningParameters

Assert-IsNotNull -Object (Get-Module -Name ($Dummy1 +"Test"))
Assert-IsNotNull -Object (Get-Module -Name "Test")

Assert-Count -Expected 1 -Presented $WarningVar
Assert-AreEqual -Presented $WarningVar[0].Message -Expected ("[Import-TestingModule] TargetModule {0} is already loaded" -f $Dummy1)
Expand All @@ -54,7 +54,7 @@ function TestingHelperTest_ImportTestingModule_TargetModule_AlreadyLoaded{
function TestingHelperTest_ImportTestingModule_TestingModule {
[CmdletBinding()] param ()

$TestDummy1 = $Dummy1 + "Test"
$TestDummy1 = "Test"

Import-Module -name $DUMMY_1_PATH -Global

Expand All @@ -68,15 +68,17 @@ function TestingHelperTest_ImportTestingModule_TestingModule {

Assert-IsNotNull -Object (Get-Module -Name $TestDummy1)

$instance1 = Get-DummyModule1TestInstanceId
$instance1 = Get-TestInstanceId

Import-TT_TestingModule -Name $TestDummyPath -Force

$instance2 = Get-DummyModule1TestInstanceId
$instance2 = Get-TestInstanceId

Assert-AreNotEqual -Expected $instance1 -Presented $instance2

Get-Module -Name $Dummy1* | Remove-Module -Force
Get-Module -Name $Dummy1 | Remove-Module -Force
Assert-IsNull -Object (Get-Module -Name $Dummy1)

Assert-IsNull -Object (Get-Module -Name $TestDummy1*)
Get-module -Name $TestDummy1 | Remove-Module -Force
Assert-IsNull -Object (Get-Module -Name $TestDummy1)
}
10 changes: 6 additions & 4 deletions TestingHelperTest/public/testPS1.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ function TestingHelperTest_TestPS1{
$result = & $test @InfoParameters

Assert-AreEqual -Expected "ModuleName" -Presented $result.Name
Assert-AreEqual -Expected "ModuleNameTest" -Presented $result.TestModule
Assert-AreEqual -Expected "ModuleNameTest_*" -Presented $result.TestsName
# Assert-AreEqual -Expected "ModuleNameTest" -Presented $result.TestModule
Assert-AreEqual -Expected "Test" -Presented $result.TestModule
# Assert-AreEqual -Expected "ModuleNameTest_*" -Presented $result.TestsName
Assert-AreEqual -Expected "Test_*" -Presented $result.TestsName

Remove-ImportedModule -Module "ModuleName"
}
Expand All @@ -26,8 +28,8 @@ function TestingHelperTest_TestPS1_WithPath{
$result = Invoke-TT_TestingHelper -Path "./$moduleName"

Assert-AreEqual -Expected $moduleName -Presented $result.Name
Assert-AreEqual -Expected ("{0}Test" -f $moduleName) -Presented $result.TestModule
Assert-AreEqual -Expected ("{0}Test_*" -f $moduleName) -Presented $result.TestsName
Assert-AreEqual -Expected "Test" -Presented $result.TestModule
Assert-AreEqual -Expected "Test_*" -Presented $result.TestsName
Assert-AreEqual -Expected 2 -Presented $result.Tests
Assert-AreEqual -Expected 2 -Presented $result.Pass

Expand Down
5 changes: 3 additions & 2 deletions private/Module.Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ function Get-ModuleHeader {

function Get-TestingModuleName {
[CmdletBinding()]
[OutputType([string])]
param (
[parameter(Mandatory)] [string] $TargetModule
)
return ($TargetModule + "Test")

return "Test"
}

9 changes: 3 additions & 6 deletions private/New-ModuleV3.Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ function Get-TestModulePath{
[Parameter()][string]$Path
)

$moduleName = Get-ModuleName -Path $Path

$testModulePath = $path | Join-Path -ChildPath ($moduleName + "Test")
$testModulePath = $path | Join-Path -ChildPath ("Test")

return $testModulePath
}
Expand All @@ -57,9 +55,8 @@ function Get-TestModuleName {
param (
[parameter(Mandatory)] [string] $Path
)

$testPath = Get-TestModulePath -Path $Path
$name = Get-ModuleName -Path $testPath

$name = "Test"

return $name
}
Expand Down
8 changes: 4 additions & 4 deletions public/Copy-functionsToModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ function Copy-FunctionsToModule {
$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'
$sourceTestPublic = $Source | Join-Path -ChildPath 'Test' -AdditionalChildPath 'public'
$sourceTestPrivate = $Source | Join-Path -ChildPath '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'
$destinationTestPublic = $Destination | Join-Path -ChildPath 'Test' -AdditionalChildPath 'public'
$destinationTestPrivate = $Destination | Join-Path -ChildPath 'Test' -AdditionalChildPath 'private'

Copy-Item -Path $sourcePublic/* -Destination $destinationPublic -Recurse -Force
Copy-Item -Path $sourcePrivate/* -Destination $destinationPrivate -Recurse -Force
Expand Down
Loading