Files
winutil/pester/functions.Tests.ps1
T

45 lines
1.2 KiB
PowerShell
Raw Normal View History

+2
2023-05-09 13:14:27 -05:00
#===========================================================================
# Tests - Functions
#===========================================================================
2024-01-12 00:34:41 -06:00
# Get all .ps1 files in the functions folder
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1
# Loop through each file
foreach ($file in $ps1Files) {
# Define the test name
$testName = "Syntax check for $($file.Name)"
# Define the test script
$testScript = {
# Import the script
. $file.FullName
# Check if any errors occurred
$scriptError = $error[0]
$scriptError | Should -Be $null
}
# Add the test to the Pester test suite
Describe $testName $testScript
}
+2
2023-05-09 13:14:27 -05:00
Describe "Functions"{
2023-10-19 17:12:55 -05:00
+2
2023-05-09 13:14:27 -05:00
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
context "$($psitem.BaseName)" {
BeforeEach -Scriptblock {
2024-01-12 00:34:41 -06:00
. $psitem.FullName
+2
2023-05-09 13:14:27 -05:00
}
2023-10-19 17:12:55 -05:00
+2
2023-05-09 13:14:27 -05:00
It "Imports with no errors" -TestCases @{
basename = $($psitem.BaseName)
fullname = $psitem.FullName
} {
Get-ChildItem function:\$basename | should -Not -BeNullOrEmpty
+12
2023-11-28 16:11:11 -06:00
}
+2
2023-05-09 13:14:27 -05:00
}
}
}