Skip to content

Commit

Permalink
Address PSSA findings and remove unused parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fflaten committed May 13, 2023
1 parent 60af84b commit cc24b4a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 25 deletions.
33 changes: 26 additions & 7 deletions src/functions/TestResults.JUnit4.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Write-JUnitReport($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-JUnitReport {
param($Result, [System.Xml.XmlWriter] $XmlWriter)
# Write the XML Declaration
$XmlWriter.WriteStartDocument($false)

Expand All @@ -21,7 +22,10 @@
$XmlWriter.WriteEndElement()
}

function Write-JUnitTestResultAttributes($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-JUnitTestResultAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Result, [System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteAttributeString('xmlns', 'xsi', $null, 'http://www.w3.org/2001/XMLSchema-instance')
$XmlWriter.WriteAttributeString('xsi', 'noNamespaceSchemaLocation', [Xml.Schema.XmlSchema]::InstanceNamespace , 'junit_schema_4.xsd')
$XmlWriter.WriteAttributeString('name', $Result.Configuration.TestResult.TestSuiteName.Value)
Expand All @@ -32,7 +36,10 @@ function Write-JUnitTestResultAttributes($Result, [System.Xml.XmlWriter] $XmlWri
$XmlWriter.WriteAttributeString('time', ($Result.Duration.TotalSeconds.ToString('0.000', [System.Globalization.CultureInfo]::InvariantCulture)))
}

function Write-JUnitTestSuiteElements($Container, [System.Xml.XmlWriter] $XmlWriter, [uint16] $Id) {
function Write-JUnitTestSuiteElements {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Container, [System.Xml.XmlWriter] $XmlWriter, [uint16] $Id)

$XmlWriter.WriteStartElement('testsuite')

if ('File' -eq $Container.Type) {
Expand All @@ -57,7 +64,10 @@ function Write-JUnitTestSuiteElements($Container, [System.Xml.XmlWriter] $XmlWri
$XmlWriter.WriteEndElement()
}

function Write-JUnitTestSuiteAttributes($Action, [System.Xml.XmlWriter] $XmlWriter, [string] $Package, [uint16] $Id) {
function Write-JUnitTestSuiteAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Action, [System.Xml.XmlWriter] $XmlWriter, [string] $Package, [uint16] $Id)

$environment = Get-RunTimeEnvironment

$XmlWriter.WriteAttributeString('name', $Package)
Expand Down Expand Up @@ -87,15 +97,21 @@ function Write-JUnitTestSuiteAttributes($Action, [System.Xml.XmlWriter] $XmlWrit
$XmlWriter.WriteEndElement()
}

function Write-JUnitTestCaseElements($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $Package) {
function Write-JUnitTestCaseElements {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $Package)

$XmlWriter.WriteStartElement('testcase')

Write-JUnitTestCaseAttributes -TestResult $TestResult -XmlWriter $XmlWriter -ClassName $Package

$XmlWriter.WriteEndElement()
}

function Write-JUnitTestCaseAttributes($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $ClassName) {
function Write-JUnitTestCaseAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestResult,[System.Xml.XmlWriter] $XmlWriter, [string] $ClassName)

$XmlWriter.WriteAttributeString('name', $TestResult.ExpandedPath)

$statusElementName = switch ($TestResult.Result) {
Expand All @@ -122,7 +138,10 @@ function Write-JUnitTestCaseAttributes($TestResult, [System.Xml.XmlWriter] $XmlW
}
}

function Write-JUnitTestCaseMessageElements($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $StatusElementName) {
function Write-JUnitTestCaseMessageElements {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestResult,[System.Xml.XmlWriter] $XmlWriter, [string] $StatusElementName)

$XmlWriter.WriteStartElement($StatusElementName)

$result = Get-ErrorForXmlReport -TestResult $TestResult
Expand Down
47 changes: 35 additions & 12 deletions src/functions/TestResults.NUnit25.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function Write-NUnitReport($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnitReport {
param($Result, [System.Xml.XmlWriter] $XmlWriter)
# Write the XML Declaration
$XmlWriter.WriteStartDocument($false)

Expand All @@ -11,7 +12,10 @@
$XmlWriter.WriteEndElement()
}

function Write-NUnitTestResultAttributes($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnitTestResultAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Result, [System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteAttributeString('xmlns', 'xsi', $null, 'http://www.w3.org/2001/XMLSchema-instance')
$XmlWriter.WriteAttributeString('xsi', 'noNamespaceSchemaLocation', [Xml.Schema.XmlSchema]::InstanceNamespace , 'nunit_schema_2.5.xsd')
$XmlWriter.WriteAttributeString('name', $Result.Configuration.TestResult.TestSuiteName.Value)
Expand All @@ -27,7 +31,10 @@ function Write-NUnitTestResultAttributes($Result, [System.Xml.XmlWriter] $XmlWri
$XmlWriter.WriteAttributeString('time', $Result.ExecutedAt.ToString('HH:mm:ss'))
}

function Write-NUnitTestResultChildNodes($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnitTestResultChildNodes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Result, [System.Xml.XmlWriter] $XmlWriter)

Write-NUnitEnvironmentInformation -Result $Result -XmlWriter $XmlWriter
Write-NUnitCultureInformation -Result $Result -XmlWriter $XmlWriter

Expand Down Expand Up @@ -62,7 +69,9 @@ function Write-NUnitTestResultChildNodes($Result, [System.Xml.XmlWriter] $XmlWri
$XmlWriter.WriteEndElement()
}

function Write-NUnitEnvironmentInformation($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnitEnvironmentInformation {
param([System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteStartElement('environment')

$environment = Get-RunTimeEnvironment
Expand All @@ -77,7 +86,9 @@ function Write-NUnitEnvironmentInformation($Result, [System.Xml.XmlWriter] $XmlW
$XmlWriter.WriteEndElement()
}

function Write-NUnitCultureInformation($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnitCultureInformation {
param([System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteStartElement('culture-info')

$XmlWriter.WriteAttributeString('current-culture', ([System.Threading.Thread]::CurrentThread.CurrentCulture).Name)
Expand All @@ -86,7 +97,10 @@ function Write-NUnitCultureInformation($Result, [System.Xml.XmlWriter] $XmlWrite
$XmlWriter.WriteEndElement()
}

function Write-NUnitTestSuiteElements($Node, [System.Xml.XmlWriter] $XmlWriter, [string] $Path) {
function Write-NUnitTestSuiteElements {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Node, [System.Xml.XmlWriter] $XmlWriter, [string] $Path)

$suiteInfo = Get-TestSuiteInfo -TestSuite $Node -Path $Path

$XmlWriter.WriteStartElement('test-suite')
Expand Down Expand Up @@ -142,7 +156,8 @@ function Write-NUnitTestSuiteElements($Node, [System.Xml.XmlWriter] $XmlWriter,
$XmlWriter.WriteEndElement()
}

function Get-ParameterizedTestSuiteInfo ([Microsoft.PowerShell.Commands.GroupInfo] $TestSuiteGroup) {
function Get-ParameterizedTestSuiteInfo {
param([Microsoft.PowerShell.Commands.GroupInfo] $TestSuiteGroup)
# this is generating info for a group of tests that were generated from the same test when TestCases are used
# I am using the Name from the first test as the name of the test group, even though we are grouping at
# the Id of the test (which is the line where the ScriptBlock of that test starts). This allows us to have
Expand Down Expand Up @@ -186,7 +201,8 @@ function Get-ParameterizedTestSuiteInfo ([Microsoft.PowerShell.Commands.GroupInf
return Get-TestSuiteInfo -TestSuite $node -Path $node.Path
}

function Get-TestSuiteInfo ($TestSuite, $Path) {
function Get-TestSuiteInfo {
param($TestSuite, $Path)
# if (-not $Path) {
# $Path = $TestSuite.Name
# }
Expand Down Expand Up @@ -232,7 +248,10 @@ function Get-TestSuiteInfo ($TestSuite, $Path) {
$suite
}

function Write-NUnitTestSuiteAttributes($TestSuiteInfo, [string] $TestSuiteType = 'TestFixture', [System.Xml.XmlWriter] $XmlWriter, [string] $Path) {
function Write-NUnitTestSuiteAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestSuiteInfo, [string] $TestSuiteType = 'TestFixture', [System.Xml.XmlWriter] $XmlWriter, [string] $Path)

$name = $TestSuiteInfo.Name

if ($TestSuiteType -eq 'ParameterizedTest' -and $Path) {
Expand All @@ -249,15 +268,19 @@ function Write-NUnitTestSuiteAttributes($TestSuiteInfo, [string] $TestSuiteType
$XmlWriter.WriteAttributeString('description', $TestSuiteInfo.Description)
}

function Write-NUnitTestCaseElement($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $ParameterizedSuiteName, [string] $Path) {
function Write-NUnitTestCaseElement {
param($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $ParameterizedSuiteName)

$XmlWriter.WriteStartElement('test-case')

Write-NUnitTestCaseAttributes -TestResult $TestResult -XmlWriter $XmlWriter -ParameterizedSuiteName $ParameterizedSuiteName -Path $Path
Write-NUnitTestCaseAttributes -TestResult $TestResult -XmlWriter $XmlWriter -ParameterizedSuiteName $ParameterizedSuiteName

$XmlWriter.WriteEndElement()
}

function Write-NUnitTestCaseAttributes($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $ParameterizedSuiteName, [string] $Path) {
function Write-NUnitTestCaseAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestResult, [System.Xml.XmlWriter] $XmlWriter, [string] $ParameterizedSuiteName)

$testName = $TestResult.ExpandedPath

Expand Down
33 changes: 27 additions & 6 deletions src/functions/TestResults.NUnit3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Write-NUnit3Report($Result, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnit3TestRunAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($Result, [System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteAttributeString('id', '0')
$XmlWriter.WriteAttributeString('name', $Result.Configuration.TestResult.TestSuiteName.Value) # required attr. in schema, but not in docs or nunit-console output...
$XmlWriter.WriteAttributeString('fullname', $Result.Configuration.TestResult.TestSuiteName.Value) # required attr. in schema, but not in docs or nunit-console output...
Expand Down Expand Up @@ -63,7 +64,12 @@ function Write-NUnit3TestRunChildNode {
}
}

function Write-NUnit3EnvironmentInformation([System.Xml.XmlWriter] $XmlWriter, [System.Collections.IDictionary] $Environment = (Get-RunTimeEnvironment)) {
function Write-NUnit3EnvironmentInformation {
param(
[System.Xml.XmlWriter] $XmlWriter,
[System.Collections.IDictionary] $Environment = (Get-RunTimeEnvironment)
)

$XmlWriter.WriteStartElement('environment')

foreach ($keyValuePair in $Environment.GetEnumerator()) {
Expand All @@ -84,7 +90,14 @@ function Write-NUnit3EnvironmentInformation([System.Xml.XmlWriter] $XmlWriter, [
$XmlWriter.WriteEndElement()
}

function Write-NUnit3TestSuiteElement($Node, [System.Xml.XmlWriter] $XmlWriter, [string] $ParentPath, [System.Collections.IDictionary] $RuntimeEnvironment) {
function Write-NUnit3TestSuiteElement {
param(
$Node,
[System.Xml.XmlWriter] $XmlWriter,
[string] $ParentPath,
[System.Collections.IDictionary] $RuntimeEnvironment
)

$XmlWriter.WriteStartElement('test-suite')
$suiteInfo = Get-NUnit3TestSuiteInfo -TestSuite $Node -ParentPath $ParentPath

Expand Down Expand Up @@ -201,7 +214,9 @@ function Write-NUnit3TestSuiteElement($Node, [System.Xml.XmlWriter] $XmlWriter,
$XmlWriter.WriteEndElement()
}

function Get-NUnit3TestSuiteInfo ($TestSuite, [string] $SuiteType, [string] $ParentPath) {
function Get-NUnit3TestSuiteInfo {
param($TestSuite, [string] $SuiteType, [string] $ParentPath)

if (-not $SuiteType) {
<# test-suite type-attribute mapping
Assembly = Container
Expand Down Expand Up @@ -292,6 +307,7 @@ function Get-NUnit3TestSuiteInfo ($TestSuite, [string] $SuiteType, [string] $Par
function Write-NUnit3TestSuiteAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestSuiteInfo, [System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteAttributeString('type', $TestSuiteInfo.type)
$XmlWriter.WriteAttributeString('id', (Get-NUnit3NodeId))
$XmlWriter.WriteAttributeString('name', $TestSuiteInfo.name)
Expand Down Expand Up @@ -363,7 +379,8 @@ function Get-NUnit3Site ($Node) {
return $site
}

function Get-NUnit3ParameterizedMethodSuiteInfo ([Microsoft.PowerShell.Commands.GroupInfo] $TestSuiteGroup, [string] $ParentPath) {
function Get-NUnit3ParameterizedMethodSuiteInfo {
param([Microsoft.PowerShell.Commands.GroupInfo] $TestSuiteGroup, [string] $ParentPath)
# this is generating info for a group of tests that were generated from the same test when TestCases are used

# Using the Name from the first test as the name of the test group, even though we are grouping at
Expand Down Expand Up @@ -409,7 +426,8 @@ function Get-NUnit3ParameterizedMethodSuiteInfo ([Microsoft.PowerShell.Commands.
return Get-NUnit3TestSuiteInfo -TestSuite $node -ParentPath $ParentPath -SuiteType 'ParameterizedMethod'
}

function Get-NUnit3ParameterizedFixtureSuiteInfo ([Microsoft.PowerShell.Commands.GroupInfo] $TestSuiteGroup, [string] $ParentPath) {
function Get-NUnit3ParameterizedFixtureSuiteInfo {
param([Microsoft.PowerShell.Commands.GroupInfo] $TestSuiteGroup, [string] $ParentPath)
# this is generating info for a group of blocks that were generated from the same block when ForEach are used

# Using the Name from the first block as the name of the block group, even though we are grouping at
Expand Down Expand Up @@ -454,7 +472,9 @@ function Get-NUnit3ParameterizedFixtureSuiteInfo ([Microsoft.PowerShell.Commands
return Get-NUnit3TestSuiteInfo -TestSuite $node -ParentPath $ParentPath -SuiteType 'ParameterizedFixture'
}

function Write-NUnit3TestCaseElement ($TestResult, [string] $ParentPath, [System.Xml.XmlWriter] $XmlWriter) {
function Write-NUnit3TestCaseElement {
param($TestResult, [string] $ParentPath, [System.Xml.XmlWriter] $XmlWriter)

$XmlWriter.WriteStartElement('test-case')

Write-NUnit3TestCaseAttributes -TestResult $TestResult -ParentPath $ParentPath -XmlWriter $XmlWriter
Expand Down Expand Up @@ -487,6 +507,7 @@ function Write-NUnit3TestCaseElement ($TestResult, [string] $ParentPath, [System
function Write-NUnit3TestCaseAttributes {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns','')]
param($TestResult, [string] $ParentPath, [System.Xml.XmlWriter] $XmlWriter)

# add parameters to name for testcase with data when not using variables in name
if ($TestResult.Data -and ($TestResult.Name -eq $TestResult.ExpandedName)) {
$paramString = Get-NUnit3ParamString -Node $TestResult
Expand Down

0 comments on commit cc24b4a

Please sign in to comment.