Skip to content

Commit 2d4565e

Browse files
committed
Update MyModule.Tests.ps1
1 parent 9439684 commit 2d4565e

File tree

1 file changed

+38
-108
lines changed

1 file changed

+38
-108
lines changed

.github/tests/MyModule.Tests.ps1

Lines changed: 38 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,42 @@ AfterAll {
4040
}
4141
}
4242

43+
Describe "Basic Tests" -Tags 'Basic' {
44+
45+
Context "Environment Check" {
46+
It "Should have valid PowerShell version" {
47+
$PSVersionTable.PSVersion.Major | Should -BeGreaterOrEqual 5
48+
}
49+
50+
It "Should be able to create test directory" {
51+
New-Item -ItemType Directory -Path $script:TestTempPath -Force | Out-Null
52+
Test-Path $script:TestTempPath | Should -BeTrue
53+
}
54+
}
55+
56+
Context "Script File Discovery" {
57+
It "Should find VALIDATE.ps1" {
58+
Write-Host "Looking for VALIDATE.ps1 at: $script:ValidateScript" -ForegroundColor Yellow
59+
Test-Path $script:ValidateScript | Should -BeTrue
60+
}
61+
62+
It "Should find DeepCleanPro.ps1" {
63+
Write-Host "Looking for DeepCleanPro.ps1 at: $script:DeepCleanScript" -ForegroundColor Yellow
64+
Test-Path $script:DeepCleanScript | Should -BeTrue
65+
}
66+
}
67+
}
68+
4369
Describe "VALIDATE.ps1 Tests" -Tags 'Validate', 'Unit' {
4470

4571
Context "Script Existence and Syntax" {
4672
It "Should exist at expected location" {
47-
Write-Host "Checking VALIDATE.ps1 at: $script:ValidateScript" -ForegroundColor Yellow
48-
Test-Path $script:ValidateScript | Should -BeTrue
73+
if (Test-Path $script:ValidateScript) {
74+
Test-Path $script:ValidateScript | Should -BeTrue
75+
} else {
76+
Write-Host "VALIDATE.ps1 not found at: $script:ValidateScript" -ForegroundColor Red
77+
Set-ItResult -Skipped -Because "Script file not found"
78+
}
4979
}
5080

5181
It "Should have valid PowerShell syntax" {
@@ -115,65 +145,18 @@ Describe "VALIDATE.ps1 Tests" -Tags 'Validate', 'Unit' {
115145
}
116146
}
117147
}
118-
119-
Context "Test-Feature Function" {
120-
BeforeAll {
121-
if (Test-Path $script:ValidateScript) {
122-
# Load just the Test-Feature function for isolated testing
123-
. $script:ValidateScript -QuickCheck
124-
}
125-
}
126-
127-
It "Should execute and return true for passing tests" {
128-
if (Test-Path $script:ValidateScript) {
129-
Mock Write-Host {}
130-
131-
$result = Test-Feature -Name "TestPass" -Test {
132-
return $true
133-
} -SuccessMessage "Pass" -FailureMessage "Fail"
134-
135-
$result | Should -BeTrue
136-
} else {
137-
Set-ItResult -Skipped -Because "Script file not found"
138-
}
139-
}
140-
141-
It "Should execute and return false for failing tests" {
142-
if (Test-Path $script:ValidateScript) {
143-
Mock Write-Host {}
144-
145-
$result = Test-Feature -Name "TestFail" -Test {
146-
return $false
147-
} -SuccessMessage "Pass" -FailureMessage "Fail"
148-
149-
$result | Should -BeFalse
150-
} else {
151-
Set-ItResult -Skipped -Because "Script file not found"
152-
}
153-
}
154-
155-
It "Should handle exceptions gracefully" {
156-
if (Test-Path $script:ValidateScript) {
157-
Mock Write-Host {}
158-
159-
$result = Test-Feature -Name "TestError" -Test {
160-
throw "Test exception"
161-
} -SuccessMessage "Pass" -FailureMessage "Fail"
162-
163-
$result | Should -BeFalse
164-
} else {
165-
Set-ItResult -Skipped -Because "Script file not found"
166-
}
167-
}
168-
}
169148
}
170149

171150
Describe "DeepCleanPro.ps1 Tests" -Tags 'DeepClean', 'Unit' {
172151

173152
Context "Script Existence and Syntax" {
174153
It "Should exist at expected location" {
175-
Write-Host "Checking DeepCleanPro.ps1 at: $script:DeepCleanScript" -ForegroundColor Yellow
176-
Test-Path $script:DeepCleanScript | Should -BeTrue
154+
if (Test-Path $script:DeepCleanScript) {
155+
Test-Path $script:DeepCleanScript | Should -BeTrue
156+
} else {
157+
Write-Host "DeepCleanPro.ps1 not found at: $script:DeepCleanScript" -ForegroundColor Red
158+
Set-ItResult -Skipped -Because "Script file not found"
159+
}
177160
}
178161

179162
It "Should have valid PowerShell syntax" {
@@ -354,59 +337,6 @@ Describe "Integration Tests" -Tags 'Integration' {
354337
}
355338
}
356339

357-
Describe "PSScriptAnalyzer Compliance" -Tags 'ScriptAnalyzer', 'Quality' {
358-
359-
BeforeAll {
360-
# Check if PSScriptAnalyzer is available
361-
$script:AnalyzerAvailable = Get-Module -ListAvailable -Name PSScriptAnalyzer
362-
363-
if ($script:AnalyzerAvailable) {
364-
Import-Module PSScriptAnalyzer -ErrorAction SilentlyContinue
365-
}
366-
}
367-
368-
Context "VALIDATE.ps1 Analysis" -Skip:(-not $script:AnalyzerAvailable) {
369-
It "Should pass PSScriptAnalyzer with no errors" {
370-
if (Test-Path $script:ValidateScript) {
371-
$analysis = Invoke-ScriptAnalyzer -Path $script:ValidateScript -Severity Error
372-
$analysis | Should -BeNullOrEmpty
373-
} else {
374-
Set-ItResult -Skipped -Because "Script file not found"
375-
}
376-
}
377-
378-
It "Should have minimal warnings" {
379-
if (Test-Path $script:ValidateScript) {
380-
$analysis = Invoke-ScriptAnalyzer -Path $script:ValidateScript -Severity Warning
381-
$analysis.Count | Should -BeLessThan 5
382-
} else {
383-
Set-ItResult -Skipped -Because "Script file not found"
384-
}
385-
}
386-
}
387-
388-
Context "DeepCleanPro.ps1 Analysis" -Skip:(-not $script:AnalyzerAvailable) {
389-
It "Should pass PSScriptAnalyzer with no errors" {
390-
if (Test-Path $script:DeepCleanScript) {
391-
$analysis = Invoke-ScriptAnalyzer -Path $script:DeepCleanScript -Severity Error
392-
$analysis | Should -BeNullOrEmpty
393-
} else {
394-
Set-ItResult -Skipped -Because "Script file not found"
395-
}
396-
}
397-
398-
It "Should have minimal warnings" {
399-
if (Test-Path $script:DeepCleanScript) {
400-
$analysis = Invoke-ScriptAnalyzer -Path $script:DeepCleanScript -Severity Warning
401-
# DeepCleanPro is complex, allow more warnings but should be reasonable
402-
$analysis.Count | Should -BeLessThan 10
403-
} else {
404-
Set-ItResult -Skipped -Because "Script file not found"
405-
}
406-
}
407-
}
408-
}
409-
410340
Describe "Security Tests" -Tags 'Security' {
411341

412342
Context "Privilege Requirements" {

0 commit comments

Comments
 (0)