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
6 changes: 3 additions & 3 deletions source/functions/Add-MFProjectScripts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function Add-MFProjectScripts
Copies script templates from ModuleForge's resource\scripts folder into a scripts
subfolder at the project root. Skips existing files by default.

Includes Invoke-MFPester.ps1 a standalone Pester runner that does not depend on
Includes Invoke-MFPester.ps1 - a standalone Pester runner that does not depend on
the ModuleForge module, safe for use in clean CI environments.

This function is also called automatically by add-mfFilesAndFolders during project
Expand Down Expand Up @@ -65,7 +65,7 @@ function Add-MFProjectScripts

if(!(Test-Path $resourceFolder))
{
Write-Warning 'Add-MFProjectScripts: resource folder not found in ModuleForge module skipping script scaffold'
Write-Warning 'Add-MFProjectScripts: resource folder not found in ModuleForge module - skipping script scaffold'
$skipProcess = $true
}

Expand All @@ -74,7 +74,7 @@ function Add-MFProjectScripts
$resourceFolderScripts = Join-Path $resourceFolder 'scripts'
if(!(Test-Path $resourceFolderScripts))
{
Write-Warning 'Add-MFProjectScripts: scripts folder not found in ModuleForge resource skipping script scaffold'
Write-Warning 'Add-MFProjectScripts: scripts folder not found in ModuleForge resource - skipping script scaffold'
$skipProcess = $true
}
}
Expand Down
2 changes: 2 additions & 0 deletions source/functions/Build-MFProject.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ BeforeAll{
#Reference Current Path
$currentPath = $(get-location).path
$sourcePath = join-path -path $currentPath -childPath 'source'
# Captured before $sourcePath is reassigned to the temp build folder below
$mockPsScriptRoot = $sourcePath

$dependencies = [ordered]@{
functions = @('Get-MFFolderItems.ps1','Get-MFDependencyTree.ps1','Get-MFFolderItemDetails.ps1','New-MFProject.ps1','Register-MFLocalPsResourceRepository.ps1','Remove-MFLocalPsResourceRepository.ps1','Add-MFRepositoryXmlData.ps1','Add-MFProjectScripts.ps1')
Expand Down
1 change: 1 addition & 0 deletions source/functions/Get-MFDependencyTree.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BeforeAll{
#Reference Current Path
$currentPath = $(get-location).path
$sourcePath = join-path -path $currentPath -childPath 'source'
$mockPsScriptRoot = $sourcePath

$dependencies = [ordered]@{
functions = @('Get-MFFolderItems.ps1','Get-MFFolderItemDetails.ps1')
Expand Down
91 changes: 89 additions & 2 deletions source/functions/Get-MFFolderItemDetails.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ BeforeAll{
$currentPath = $(get-location).path
$sourcePath = join-path -path $currentPath -childPath 'source'

$mockPsScriptRoot = $sourcePath

$dependencies = [ordered]@{
functions = @('Get-MFFolderItems.ps1')
}
Expand All @@ -26,7 +28,6 @@ BeforeAll{
}
}


#Load This File
. $PSCommandPath.Replace('.Tests.ps1','.ps1')

Expand Down Expand Up @@ -62,5 +63,91 @@ Describe 'Get-MFFolderItemDetails' {
$folderItemDetails.where{$_.name -eq 'Get-MFFolderItemDetails.ps1'}.Dependencies.Reference | Should -be 'Get-MFFolderItems'
}

}

Describe 'Get-MFFolderItemDetails scriptblock - function analysis' {
BeforeAll {
$sbPath = Join-Path $sourcePath 'resource' 'scriptBlocks' 'Get-MFFolderItemDetails.scriptblock.ps1'
[scriptblock]$sb = [scriptblock]::Create((Get-Content $sbPath -Raw))

$testRoot = Join-Path ([System.IO.Path]::GetTempPath()) "MFSbTest_$([System.IO.Path]::GetRandomFileName())"
$testFunctionsDir = Join-Path $testRoot 'source' 'functions'
New-Item -ItemType Directory -Path $testFunctionsDir -Force | Out-Null

@'
function Do-Something {
param([string]$InputValue)
process { return $InputValue }
}
'@ | Set-Content (Join-Path $testFunctionsDir 'Do-Something.ps1')

@'
function Do-Other {
param([string]$InputValue)
process { return Do-Something $InputValue }
}
'@ | Set-Content (Join-Path $testFunctionsDir 'Do-Other.ps1')

}
$testFolderItems = Get-MFFolderItems -Path $testFunctionsDir -PSScriptsOnly
$sbResult = & $sb $testFunctionsDir $testFolderItems
}

AfterAll {
Remove-Item $testRoot -Recurse -Force -ErrorAction SilentlyContinue -ProgressAction SilentlyContinue
}

It 'Should return one result per file' {
$sbResult.Count | Should -Be 2
}
It 'Should identify function names correctly' {
$sbResult.FunctionDetails.functionName | Should -Contain 'Do-Something'
$sbResult.FunctionDetails.functionName | Should -Contain 'Do-Other'
}
It 'Should detect the cross-file dependency' {
$sbResult.Where{$_.Name -eq 'Do-Other.ps1'}.Dependencies.Reference | Should -Contain 'Do-Something'
}
It 'Should populate relativePath on each item' {
$sbResult | ForEach-Object { $_.relativePath | Should -Not -BeNullOrEmpty }
}
}

Describe 'Get-MFFolderItemDetails scriptblock - class analysis' {
BeforeAll {
$sbPath = Join-Path $sourcePath 'resource' 'scriptBlocks' 'Get-MFFolderItemDetails.scriptblock.ps1'
[scriptblock]$sb = [scriptblock]::Create((Get-Content $sbPath -Raw))

$testRoot = Join-Path ([System.IO.Path]::GetTempPath()) "MFSbClassTest_$([System.IO.Path]::GetRandomFileName())"
$testClassDir = Join-Path $testRoot 'source' 'classes'
New-Item -ItemType Directory -Path $testClassDir -Force | Out-Null

@'
class MyTestClass {
[string]$Name
[int]$Count
MyTestClass([string]$n) { $this.Name = $n }
[string] GetName() { return $this.Name }
}
'@ | Set-Content (Join-Path $testClassDir 'MyTestClass.ps1')

$testFolderItems = Get-MFFolderItems -Path $testClassDir -PSScriptsOnly
$sbResult = & $sb $testClassDir $testFolderItems
}

AfterAll {
Remove-Item $testRoot -Recurse -Force -ErrorAction SilentlyContinue -ProgressAction SilentlyContinue
}

It 'Should return a result for the class file' {
$sbResult | Should -Not -BeNullOrEmpty
}
It 'Should identify the class name' {
$sbResult.ClassDetails.className | Should -Contain 'MyTestClass'
}
It 'Should identify class methods' {
$sbResult.ClassDetails.Where{$_.className -eq 'MyTestClass'}.methods.Name | Should -Contain 'GetName'
}
It 'Should identify class properties' {
$sbResult.ClassDetails.Where{$_.className -eq 'MyTestClass'}.properties.Name | Should -Contain 'Name'
$sbResult.ClassDetails.Where{$_.className -eq 'MyTestClass'}.properties.Name | Should -Contain 'Count'
}
}
Loading
Loading