-
Notifications
You must be signed in to change notification settings - Fork 200
Code coverage #2165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Code coverage #2165
Changes from 104 commits
afe4c12
0fd2190
90ad23d
c557dd4
8985267
6fe02a9
fbf101d
c76d7ee
b4fec54
904153f
4bcee77
9d5d8a3
bb351c3
6bc1026
7cc0235
d1bcd1c
72aa358
babdf32
c22a048
3d0a40d
cc692bd
f98686d
fc12fd2
c7dc6fc
4dd313c
3ea7df4
840ab9a
c3eb8c0
9406cfa
e6b602f
bc89d87
3827e30
b229aaf
a515576
8dfa10e
5218035
93594fa
a6b22c9
d2c7a15
f0064ef
a1ad6dc
189afb3
70e6fa1
a217bd5
39d5024
b6cf566
01ea3e5
77694c3
ca950af
dd1db07
a799705
94eefa7
30d32b9
79043b3
170fa30
3275c96
b2182d7
af5fedc
e1574c6
8ac7615
39ff9bd
6540604
d8d703c
eddceb0
c553f1d
1e3d87f
da5f0ab
deeb6d2
1d8a4a8
81603f3
9a82e24
57dfa36
fceb252
223f6d4
8e1a71b
d5aa70d
a6fc0d5
fab2ba2
69113fd
cf2ced8
a30c7fd
07319ef
6160792
8a5ebf8
df44581
cfd82e8
5b29cba
1b0dbc1
bfffec3
f9a5953
7037066
187d675
ba472cc
26846f7
ef917d5
e9551ec
957cf94
c660f6e
f760a5e
abc7ac1
c68de87
3473433
479e9b6
11fa194
3a25903
262c418
1fa938f
75b1af7
a6d852e
c5ed195
2c1874c
e19bb6b
29c0e3b
96a0d36
40d895c
3d6e9a7
3f0747a
65b529b
65c68cd
1139a81
d5d660f
48106a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,30 @@ | ||
| # See https://pre-commit.com for more information | ||
| # See https://pre-commit.com/hooks.html for more hooks | ||
|
|
||
| repos: | ||
| - repo: https://github.com/executablebooks/mdformat | ||
| rev: 0.7.21 | ||
| hooks: | ||
| - id: mdformat | ||
| args: [--end-of-line=keep] | ||
|
|
||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 | ||
| hooks: | ||
| - id: check-added-large-files | ||
| - id: check-case-conflict | ||
| - id: check-json | ||
| - id: check-xml | ||
| - id: check-yaml | ||
| - id: check-merge-conflict | ||
| - id: detect-private-key | ||
| - id: end-of-file-fixer | ||
| - id: trailing-whitespace | ||
| - id: mixed-line-ending | ||
| - id: sort-simple-yaml | ||
|
|
||
| - repo: https://github.com/gitleaks/gitleaks | ||
| rev: v8.16.3 | ||
| hooks: | ||
| - id: gitleaks | ||
| # See https://pre-commit.com for more information | ||
| # See https://pre-commit.com/hooks.html for more hooks | ||
|
|
||
| repos: | ||
| - repo: https://github.com/executablebooks/mdformat | ||
| rev: 0.7.21 | ||
| hooks: | ||
| - id: mdformat | ||
| args: [--end-of-line=keep] | ||
|
|
||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v5.0.0 | ||
| hooks: | ||
| - id: check-added-large-files | ||
| - id: check-case-conflict | ||
| - id: check-json | ||
| - id: check-xml | ||
| exclude: 'Tests/CodeCoverage/TestData/CoberturaFiles/cobertura-malformed\.xml$' | ||
| - id: check-yaml | ||
| - id: check-merge-conflict | ||
| - id: detect-private-key | ||
| - id: end-of-file-fixer | ||
| - id: trailing-whitespace | ||
| - id: mixed-line-ending | ||
| - id: sort-simple-yaml | ||
|
|
||
| - repo: https://github.com/gitleaks/gitleaks | ||
| rev: v8.16.3 | ||
| hooks: | ||
| - id: gitleaks |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| function Run-AlTests | ||
Check warningCode scanning / PSScriptAnalyzer The cmdlet 'Run-AlTests' uses an unapproved verb. Warning
The cmdlet 'Run-AlTests' uses an unapproved verb.
|
||
| ( | ||
| [string] $TestSuite = $script:DefaultTestSuite, | ||
| [string] $TestCodeunitsRange = "", | ||
| [string] $TestProcedureRange = "", | ||
| [string] $ExtensionId = "", | ||
| [ValidateSet('None','Disabled','Codeunit','Function')] | ||
| [string] $RequiredTestIsolation = "None", | ||
| [ValidateSet('','None','UnitTest','IntegrationTest','Uncategorized','AITest')] | ||
| [string] $TestType = "", | ||
| [ValidateSet("Disabled", "Codeunit")] | ||
| [string] $TestIsolation = "Codeunit", | ||
| [ValidateSet('Windows','NavUserPassword','AAD')] | ||
| [string] $AutorizationType = $script:DefaultAuthorizationType, | ||
| [string] $TestPage = $global:DefaultTestPage, | ||
Check warningCode scanning / PSScriptAnalyzer Found global variable 'global:DefaultTestPage'. Warning
Found global variable 'global:DefaultTestPage'.
|
||
| [switch] $DisableSSLVerification, | ||
| [Parameter(Mandatory=$true)] | ||
| [string] $ServiceUrl, | ||
| [Parameter(Mandatory=$false)] | ||
| [pscredential] $Credential, | ||
| [array] $DisabledTests = @(), | ||
| [bool] $Detailed = $true, | ||
| [ValidateSet('no','error','warning')] | ||
| [string] $AzureDevOps = 'no', | ||
| [bool] $SaveResultFile = $true, | ||
| [string] $ResultsFilePath = "$PSScriptRoot\TestResults.xml", | ||
| [ValidateSet('XUnit','JUnit')] | ||
| [string] $ResultsFormat = 'JUnit', | ||
| [string] $AppName = '', | ||
| [ValidateSet('Disabled', 'PerRun', 'PerCodeunit', 'PerTest')] | ||
| [string] $CodeCoverageTrackingType = 'Disabled', | ||
| [ValidateSet('Disabled','PerCodeunit','PerTest')] | ||
| [string] $ProduceCodeCoverageMap = 'Disabled', | ||
| [string] $CodeCoverageOutputPath = "$PSScriptRoot\CodeCoverage", | ||
| [string] $CodeCoverageExporterId = $script:DefaultCodeCoverageExporter, | ||
| [switch] $CodeCoverageTrackAllSessions, | ||
| [string] $CodeCoverageFilePrefix = ("TestCoverageMap_" + (get-date -Format 'yyyyMMdd')), | ||
| [bool] $StabilityRun | ||
| ) | ||
| { | ||
| $testRunArguments = @{ | ||
| TestSuite = $TestSuite | ||
| TestCodeunitsRange = $TestCodeunitsRange | ||
| TestProcedureRange = $TestProcedureRange | ||
| ExtensionId = $ExtensionId | ||
| RequiredTestIsolation = $RequiredTestIsolation | ||
| TestType = $TestType | ||
| TestRunnerId = (Get-TestRunnerId -TestIsolation $TestIsolation) | ||
| CodeCoverageTrackingType = $CodeCoverageTrackingType | ||
| ProduceCodeCoverageMap = $ProduceCodeCoverageMap | ||
| CodeCoverageOutputPath = $CodeCoverageOutputPath | ||
| CodeCoverageFilePrefix = $CodeCoverageFilePrefix | ||
| CodeCoverageExporterId = $CodeCoverageExporterId | ||
| AutorizationType = $AutorizationType | ||
| TestPage = $TestPage | ||
| DisableSSLVerification = $DisableSSLVerification | ||
| ServiceUrl = $ServiceUrl | ||
| Credential = $Credential | ||
| DisabledTests = $DisabledTests | ||
| Detailed = $Detailed | ||
| StabilityRun = $StabilityRun | ||
| } | ||
|
|
||
| [array]$testRunResult = Run-AlTestsInternal @testRunArguments | ||
|
|
||
| if($SaveResultFile -and $testRunResult) | ||
| { | ||
| # Import the formatter module | ||
| $formatterPath = Join-Path $PSScriptRoot "TestResultFormatter.psm1" | ||
| Import-Module $formatterPath -Force | ||
|
|
||
| Save-TestResults -TestRunResultObject $testRunResult -ResultsFilePath $ResultsFilePath -Format $ResultsFormat -ExtensionId $ExtensionId -AppName $AppName | ||
| } | ||
| elseif ($SaveResultFile -and -not $testRunResult) { | ||
| Write-Host "Warning: No test results to save - tests may not have run" | ||
| } | ||
|
|
||
| if($AzureDevOps -ne 'no' -and $testRunResult) | ||
| { | ||
| Report-ErrorsInAzureDevOps -AzureDevOps $AzureDevOps -TestRunResultObject $testRunResult | ||
| } | ||
| } | ||
|
|
||
| function Invoke-ALTestResultVerification | ||
| ( | ||
| [string] $TestResultsFolder = $(throw "Missing argument TestResultsFolder"), | ||
| [switch] $IgnoreErrorIfNoTestsExecuted | ||
| ) | ||
| { | ||
| $failedTestList = Get-FailedTestsFromXMLFiles -TestResultsFolder $TestResultsFolder | ||
|
|
||
| if($failedTestList.Count -gt 0) | ||
| { | ||
| $testsExecuted = $true; | ||
| Write-Log "Failed tests:" | ||
| $testsFailed = "" | ||
| foreach($failedTest in $failedTestList) | ||
| { | ||
| $testsFailed += "Name: " + $failedTest.name + [environment]::NewLine | ||
| $testsFailed += "Method: " + $failedTest.method + [environment]::NewLine | ||
| $testsFailed += "Time: " + $failedTest.time + [environment]::NewLine | ||
| $testsFailed += "Message: " + [environment]::NewLine + $failedTest.message + [environment]::NewLine | ||
| $testsFailed += "StackTrace: "+ [environment]::NewLine + $failedTest.stackTrace + [environment]::NewLine + [environment]::NewLine | ||
| } | ||
|
|
||
| Write-Log $testsFailed | ||
| throw "Test execution failed due to the failing tests, see the list of the failed tests above." | ||
| } | ||
|
|
||
| if(-not $testsExecuted) | ||
| { | ||
| [array]$testResultFiles = Get-ChildItem -Path $TestResultsFolder -Filter "*.xml" | Foreach { "$($_.FullName)" } | ||
|
|
||
| foreach($resultFile in $testResultFiles) | ||
| { | ||
| [xml]$xmlDoc = Get-Content "$resultFile" | ||
| [array]$otherTests = $xmlDoc.assemblies.assembly.collection.ChildNodes | Where-Object {$_.result -ne 'Fail'} | ||
| if($otherTests.Length -gt 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| if (-not $IgnoreErrorIfNoTestsExecuted) { | ||
| throw "No test codeunits were executed" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function Get-FailedTestsFromXMLFiles | ||
| ( | ||
| [string] $TestResultsFolder = $(throw "Missing argument TestResultsFolder") | ||
| ) | ||
| { | ||
| $failedTestList = New-Object System.Collections.ArrayList | ||
| $testsExecuted = $false | ||
Check warningCode scanning / PSScriptAnalyzer The variable 'testsExecuted' is assigned but never used. Warning
The variable 'testsExecuted' is assigned but never used.
|
||
| [array]$testResultFiles = Get-ChildItem -Path $TestResultsFolder -Filter "*.xml" | Foreach { "$($_.FullName)" } | ||
|
|
||
| if($testResultFiles.Length -eq 0) | ||
| { | ||
| throw "No test results were found" | ||
| } | ||
|
|
||
| foreach($resultFile in $testResultFiles) | ||
| { | ||
| [xml]$xmlDoc = Get-Content "$resultFile" | ||
| [array]$failedTests = $xmlDoc.assemblies.assembly.collection.ChildNodes | Where-Object {$_.result -eq 'Fail'} | ||
| if($failedTests) | ||
| { | ||
| $testsExecuted = $true | ||
| foreach($failedTest in $failedTests) | ||
| { | ||
| $failedTestObject = @{ | ||
| codeunitID = [int]($failedTest.ParentNode.ParentNode.'x-code-unit'); | ||
| codeunitName = $failedTest.name; | ||
| method = $failedTest.method; | ||
| time = $failedTest.time; | ||
| message = $failedTest.failure.message; | ||
| stackTrace = $failedTest.failure.'stack-trace'; | ||
| } | ||
|
|
||
| $failedTestList.Add($failedTestObject) > $null | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $failedTestList | ||
| } | ||
|
|
||
| function Write-DisabledTestsJson | ||
| ( | ||
| $FailedTests, | ||
| [string] $OutputFolder = $(throw "Missing argument OutputFolder"), | ||
| [string] $FileName = 'DisabledTests.json' | ||
| ) | ||
| { | ||
| $testsToDisable = New-Object -TypeName "System.Collections.ArrayList" | ||
| foreach($failedTest in $failedTests) | ||
| { | ||
| $test = @{ | ||
| codeunitID = $failedTest.codeunitID; | ||
| codeunitName = $failedTest.name; | ||
| method = $failedTest.method; | ||
| } | ||
|
|
||
| $testsToDisable.Add($test) | ||
| } | ||
|
|
||
| $outputFile = Join-Path $OutputFolder $FileName | ||
| if(-not (Test-Path $outputFolder)) | ||
| { | ||
| New-Item -Path $outputFolder -ItemType Directory | ||
| } | ||
|
|
||
| Add-Content -Value (ConvertTo-Json $testsToDisable) -Path $outputFile | ||
| } | ||
|
|
||
| function Report-ErrorsInAzureDevOps | ||
Check warningCode scanning / PSScriptAnalyzer The cmdlet 'Report-ErrorsInAzureDevOps' uses an unapproved verb. Warning
The cmdlet 'Report-ErrorsInAzureDevOps' uses an unapproved verb.
|
||
| ( | ||
| [ValidateSet('no','error','warning')] | ||
| [string] $AzureDevOps = 'no', | ||
| $TestRunResultObject | ||
| ) | ||
| { | ||
| if ($AzureDevOps -eq 'no') | ||
| { | ||
| return | ||
| } | ||
|
|
||
| $failedCodeunits = $TestRunResultObject | Where-Object { $_.result -eq $script:FailureTestResultType } | ||
| $failedTests = $failedCodeunits.testResults | Where-Object { $_.result -eq $script:FailureTestResultType } | ||
|
|
||
| foreach($failedTest in $failedTests) | ||
| { | ||
| $methodName = $failedTest.method; | ||
| $errorMessage = $failedTest.message | ||
| Write-Host "##vso[task.logissue type=$AzureDevOps;sourcepath=$methodName;]$errorMessage" | ||
| } | ||
| } | ||
|
|
||
| function Get-DisabledAlTests | ||
| ( | ||
| [string] $DisabledTestsPath | ||
| ) | ||
| { | ||
| $DisabledTests = @() | ||
| if(Test-Path $DisabledTestsPath) | ||
| { | ||
| $DisabledTests = Get-Content $DisabledTestsPath | ConvertFrom-Json | ||
| } | ||
|
|
||
| return $DisabledTests | ||
| } | ||
|
|
||
| function Get-TestRunnerId | ||
| ( | ||
| [ValidateSet("Disabled", "Codeunit")] | ||
| [string] $TestIsolation = "Codeunit" | ||
| ) | ||
| { | ||
| switch($TestIsolation) | ||
| { | ||
| "Codeunit" | ||
| { | ||
| return Get-CodeunitTestIsolationTestRunnerId | ||
| } | ||
| "Disabled" | ||
| { | ||
| return Get-DisabledTestIsolationTestRunnerId | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function Get-DisabledTestIsolationTestRunnerId() | ||
| { | ||
| return $global:TestRunnerIsolationDisabled | ||
Check warningCode scanning / PSScriptAnalyzer Found global variable 'global:TestRunnerIsolationDisabled'. Warning
Found global variable 'global:TestRunnerIsolationDisabled'.
|
||
| } | ||
|
|
||
| function Get-CodeunitTestIsolationTestRunnerId() | ||
| { | ||
| return $global:TestRunnerIsolationCodeunit | ||
Check warningCode scanning / PSScriptAnalyzer Found global variable 'global:TestRunnerIsolationCodeunit'. Warning
Found global variable 'global:TestRunnerIsolationCodeunit'.
|
||
| } | ||
|
|
||
| . "$PSScriptRoot\Internal\Constants.ps1" | ||
| Import-Module "$PSScriptRoot\Internal\ALTestRunnerInternal.psm1" | ||
Uh oh!
There was an error while loading. Please reload this page.