From c3ab7e70f0f68926a170817b2e69b5e6cc4274cc Mon Sep 17 00:00:00 2001
From: Frode Flaten <3436158+fflaten@users.noreply.github.com>
Date: Fri, 2 Aug 2024 23:25:17 +0000
Subject: [PATCH] Update tests
---
tst/functions/Coverage.Tests.ps1 | 145 ++++++++++++++++++-------------
1 file changed, 87 insertions(+), 58 deletions(-)
diff --git a/tst/functions/Coverage.Tests.ps1 b/tst/functions/Coverage.Tests.ps1
index ae6b9edd3..7b87327d8 100644
--- a/tst/functions/Coverage.Tests.ps1
+++ b/tst/functions/Coverage.Tests.ps1
@@ -52,9 +52,16 @@ InPesterModuleScope {
if ($PSVersionTable.PSVersion.Major -ge 5) {
Add-Content -Path $testScriptPath -Value @'
- class MyClass
+ class MyBaseClass {
+ MyBaseClass()
+ {
+ 'I am the constructor of base class.'
+ }
+ }
+
+ class MyClass : MyBaseClass
{
- MyClass()
+ MyClass() : base()
{
'I am the constructor.'
}
@@ -79,11 +86,18 @@ InPesterModuleScope {
# Before that, let's just create equivalent commands to above class with exact same line numbers
Add-Content -Path $testScriptPath -Value @'
+ #class MyBaseClass {
+ function MyBaseClass
+ {
+ 'I am the constructor of base class.'
+ }
+ #}
+
#class MyClass
#{
function MyClass
{
- 'I am the constructor.'
+ MyBaseClass; 'I am the constructor.'
}
function MethodOne
@@ -131,7 +145,7 @@ InPesterModuleScope {
# Path deliberately duplicated to make sure the code doesn't produce multiple breakpoints for the same commands
$breakpoints = Enter-CoverageAnalysis -CodeCoverage $testScriptPath, $testScriptPath, $testScript2Path, $testScript3Path -UseBreakpoints $UseBreakpoints
- @($breakpoints).Count | Should -Be 18 -Because 'it has the proper number of breakpoints defined'
+ @($breakpoints).Count | Should -Be 19 -Because 'it has the proper number of breakpoints defined'
$sb = {
$null = & $testScriptPath
@@ -153,11 +167,11 @@ InPesterModuleScope {
}
It 'Reports the proper number of executed commands' {
- $coverageReport.NumberOfCommandsExecuted | Should -Be 15
+ $coverageReport.NumberOfCommandsExecuted | Should -Be 16
}
It 'Reports the proper number of analyzed commands' {
- $coverageReport.NumberOfCommandsAnalyzed | Should -Be 18
+ $coverageReport.NumberOfCommandsAnalyzed | Should -Be 19
}
It 'Reports the proper number of analyzed files' {
@@ -175,7 +189,7 @@ InPesterModuleScope {
}
It 'Reports the proper number of hit commands' {
- $coverageReport.HitCommands.Count | Should -Be 15
+ $coverageReport.HitCommands.Count | Should -Be 16
}
It 'Reports the correct hit command' {
@@ -186,7 +200,8 @@ InPesterModuleScope {
$coverageReport.HitCommands[0].Class | Should -BeNullOrEmpty
# Classes have been introduced in PowerShell 5.0
if ($PSVersionTable.PSVersion.Major -ge 5) {
- $coverageReport.HitCommands[9].Class | Should -Be 'MyClass'
+ $coverageReport.HitCommands[9].Class | Should -Be 'MyBaseClass'
+ $coverageReport.HitCommands[10].Class | Should -Be 'MyClass'
$coverageReport.MissedCommands[2].Class | Should -Be 'MyClass'
}
else {
@@ -198,7 +213,8 @@ InPesterModuleScope {
It 'Reports the correct function names' {
$coverageReport.HitCommands[0].Function | Should -Be 'NestedFunction'
$coverageReport.HitCommands[2].Function | Should -Be 'FunctionOne'
- $coverageReport.HitCommands[9].Function | Should -Be 'MyClass'
+ $coverageReport.HitCommands[9].Function | Should -Be 'MyBaseClass'
+ $coverageReport.HitCommands[10].Function | Should -Be 'MyClass'
$coverageReport.MissedCommands[2].Function | Should -Be 'MethodTwo'
}
@@ -237,24 +253,29 @@ InPesterModuleScope {
-
+
-
+
-
+
+
+
+
+
+
-
-
-
+
+
+
@@ -278,14 +299,15 @@ InPesterModuleScope {
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -295,13 +317,14 @@ InPesterModuleScope {
-
-
-
+
+
+
-
+
@@ -324,9 +347,9 @@ InPesterModuleScope {
-
-
-
+
+
+
')
@@ -370,24 +393,29 @@ InPesterModuleScope {
-
+
+
+
+
+
+
-
+
-
+
-
-
-
+
+
+
@@ -411,14 +439,15 @@ InPesterModuleScope {
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -428,9 +457,9 @@ InPesterModuleScope {
-
-
-
+
+
+
@@ -457,9 +486,9 @@ InPesterModuleScope {
-
-
-
+
+
+
')
@@ -642,7 +671,7 @@ InPesterModuleScope {
BeforeAll {
$breakpoints = Enter-CoverageAnalysis -CodeCoverage @{Path = "$(Join-Path -Path $root -ChildPath *.ps1)"; Function = '*' } -UseBreakpoints $UseBreakpoints
- @($breakpoints).Count | Should -Be 13 -Because 'it has the proper number of breakpoints defined'
+ @($breakpoints).Count | Should -Be 14 -Because 'it has the proper number of breakpoints defined'
if ($UseBreakpoints) {
& $testScriptPath
@@ -657,11 +686,11 @@ InPesterModuleScope {
}
It 'Reports the proper number of executed commands' {
- $coverageReport.NumberOfCommandsExecuted | Should -Be 10
+ $coverageReport.NumberOfCommandsExecuted | Should -Be 11
}
It 'Reports the proper number of analyzed commands' {
- $coverageReport.NumberOfCommandsAnalyzed | Should -Be 13
+ $coverageReport.NumberOfCommandsAnalyzed | Should -Be 14
}
It 'Reports the proper number of analyzed files' {
@@ -678,7 +707,7 @@ InPesterModuleScope {
}
It 'Reports the proper number of hit commands' {
- $coverageReport.HitCommands.Count | Should -Be 10
+ $coverageReport.HitCommands.Count | Should -Be 11
}
It 'Reports the correct hit command' {
@@ -747,7 +776,7 @@ InPesterModuleScope {
$breakpoints = Enter-CoverageAnalysis -CodeCoverage @{Path = $testScriptPath; Class = '*' } -UseBreakpoints $UseBreakpoints
- @($breakpoints).Count | Should -Be 3 -Because 'it has the proper number of breakpoints defined'
+ @($breakpoints).Count | Should -Be 4 -Because 'it has the proper number of breakpoints defined'
if ($UseBreakpoints) {
& $testScriptPath
@@ -762,11 +791,11 @@ InPesterModuleScope {
}
It 'Reports the proper number of executed commands' {
- $coverageReport.NumberOfCommandsExecuted | Should -Be 2
+ $coverageReport.NumberOfCommandsExecuted | Should -Be 3
}
It 'Reports the proper number of analyzed commands' {
- $coverageReport.NumberOfCommandsAnalyzed | Should -Be 3
+ $coverageReport.NumberOfCommandsAnalyzed | Should -Be 4
}
It 'Reports the proper number of missed commands' {
@@ -774,7 +803,7 @@ InPesterModuleScope {
}
It 'Reports the proper number of hit commands' {
- $coverageReport.HitCommands.Count | Should -Be 2
+ $coverageReport.HitCommands.Count | Should -Be 3
}
AfterAll {