-
Notifications
You must be signed in to change notification settings - Fork 202
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
Open
spetersenms
wants to merge
122
commits into
microsoft:main
Choose a base branch
from
spetersenms:CodeCoverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Code coverage #2165
Changes from 95 commits
Commits
Show all changes
122 commits
Select commit
Hold shift + click to select a range
afe4c12
Initial CC implementation
spetersenms 0fd2190
Load order fix
spetersenms 90ad23d
Installing wfc dependencies
spetersenms c557dd4
error handling
spetersenms 8985267
Additional dependency stuff
spetersenms 6fe02a9
trying again
spetersenms fbf101d
Write log temp implementation
spetersenms c76d7ee
Disable SSL
spetersenms b4fec54
Building url correctly
spetersenms 904153f
Fixes
spetersenms 4bcee77
Supporting Covertura output format.
spetersenms 9d5d8a3
Syntax fix
spetersenms bb351c3
Fixed parsing issue
spetersenms 6bc1026
Getting all line data
spetersenms 7cc0235
CC visualizer
spetersenms d1bcd1c
Path fix
spetersenms 72aa358
FIxed path and import issue
spetersenms babdf32
Fixed path
spetersenms c22a048
supporting other exporters
spetersenms 3d0a40d
Fixed display bug in visualizer
spetersenms cc692bd
Use correct data for total lines
spetersenms f98686d
Importing new CC module
spetersenms fc12fd2
Fix
spetersenms c7dc6fc
Build artifact folder as global var.
spetersenms 4dd313c
Improved source and report generation
spetersenms 3ea7df4
Better error handling
spetersenms 840ab9a
Better handling of xml method tags
spetersenms c3eb8c0
Correctly handle empty xml tags
spetersenms 9406cfa
Restructure output markdown to be much more compact.
spetersenms e6b602f
Use workspace root to find source files
spetersenms bc89d87
Putting details in collapsable container.
spetersenms 3827e30
Function moved to other file
spetersenms b229aaf
Better parsing
spetersenms a515576
Improvements to coverage calculations
spetersenms 8dfa10e
Use collection type
spetersenms 5218035
Re-structured test runner.
spetersenms 93594fa
Using global to access PSVersionTable in class
spetersenms a6b22c9
Count correct total lines
spetersenms d2c7a15
Use correct list of app roots per project for CC
spetersenms f0064ef
Action for CC summary for all projects
spetersenms a1ad6dc
Pass dependencies json to RunALPipeline to use with CC
spetersenms 189afb3
CC merge summary job
spetersenms 70e6fa1
Correctly run all test apps
spetersenms a217bd5
Made CC conditional
spetersenms 39d5024
Use file indexes
spetersenms b6cf566
Documentation and release notes.
spetersenms 01ea3e5
Run CC merge with incomplete data
spetersenms 77694c3
Added more cases for non executable lines
spetersenms ca950af
Use correct unicode dashes
spetersenms dd1db07
New settings for Code Coverage
spetersenms a799705
Handling new settings object correctly
spetersenms 94eefa7
Initializing list to work with strict mode
spetersenms 30d32b9
Rename .Modules/CodeCoverage to .Modules/TestRunner
spetersenms 79043b3
Add enableCodeCoverage and codeCoverageSetup settings definitions
spetersenms 170fa30
Fix missing TestPage parameter in Run-NextTest function
spetersenms 3275c96
Fix undefined variable and broken string in Print-TestResults
spetersenms b2182d7
Use OutputWarning instead of raw Write-Host for warnings
spetersenms af5fedc
Fix line number sorting in CoberturaMerger
spetersenms e1574c6
Add null check for projectDeps after JSON parsing
spetersenms 8ac7615
Add README for MergeCoverageSummaries action
spetersenms 39ff9bd
Add error handling for XML file reads in CoberturaMerger
spetersenms 6540604
Remove unused mergeStats variable
spetersenms d8d703c
Fix typo: oututFile -> outputFile
spetersenms eddceb0
Add test infrastructure and BCCoverageParser tests (WIP)
spetersenms c553f1d
Remove temporary debug script
spetersenms 1e3d87f
Additional test data and tests.
spetersenms da5f0ab
Removed how it works section
spetersenms deeb6d2
Cleanup
spetersenms 1d8a4a8
Merge branch 'main' into CodeCoverage
spetersenms 81603f3
Fixing CalculateArtifactsName test.
spetersenms 9a82e24
Merge branch 'CodeCoverage' of github.com:spetersenms/AL-Go into Code…
spetersenms 57dfa36
Add MergeCoverage job to PostProcess needs in ModifyBuildWorkflows
spetersenms fceb252
Added coverage processor tests
spetersenms 223f6d4
Consistent decimal handling
spetersenms 8e1a71b
Cobertura formatter and merger tests
spetersenms d5aa70d
Covererage report action tests
spetersenms a6fc0d5
Pre-commit
spetersenms fab2ba2
exclude intentional invalid test xml file
spetersenms 69113fd
Run CC tests in CI
spetersenms cf2ced8
Tests for summary logic
spetersenms a30c7fd
Merge branch 'main' into CodeCoverage
spetersenms 07319ef
Merge branch 'main' into CodeCoverage
spetersenms 6160792
Use GetAttribute to for safe property access
spetersenms 8a5ebf8
More test xml files.
spetersenms df44581
Fix strict mode violations in CoverageProcessor modules
spetersenms cfd82e8
Add explanatory comment to MergeCoverage jobs in workflow templates
spetersenms 5b29cba
Fix codeCoverageSetup settings ignored, single-project artifact gap
spetersenms 1b0dbc1
Extract shared stats helper, add encoding and filename sanitization
spetersenms bfffec3
Add schema defaults and validation, remove unused output
spetersenms f9a5953
Align upload-artifact version in build workflow templates
spetersenms 7037066
Add 49 new tests for untested functions and code paths
spetersenms 187d675
Guard optional stats properties in external code section
spetersenms ba472cc
Handle both hashtable and PSCustomObject for codeCoverageSetup
spetersenms 26846f7
Wrap XML results in @() for PS5 .Count compatibility in tests
spetersenms ef917d5
Handle as array.
spetersenms e9551ec
Remove unused sourcePath param, stale step id, and output docs
spetersenms 957cf94
Fix failedTest.message bug and Setup-Enviroment typo
spetersenms c660f6e
Fix cross-platform test paths and add clarifying comments
spetersenms f760a5e
Merge branch 'main' into CodeCoverage
spetersenms abc7ac1
Merge branch 'main' into CodeCoverage
spetersenms c68de87
Merge branch 'CodeCoverage' of github.com:spetersenms/AL-Go into Code…
spetersenms 3473433
Exclude TypeNotFound PSScriptAnalyzer rule in TestRunner
spetersenms 479e9b6
Handle both windows and unix paths.
spetersenms 11fa194
Getting rid of unicode characters
spetersenms 3a25903
Error preference and strict mode for all new modules.
spetersenms 262c418
Move RunPipeline script block to new file.
spetersenms 1fa938f
De-duplicate Test-PropertyExist function
spetersenms 75b1af7
Find-AlSourceFolders - pack files in arrays.
spetersenms a6d852e
Additional tests
spetersenms c5ed195
Additional documentation
spetersenms 2c1874c
Retention days used for CC artifacts.
spetersenms e19bb6b
Initialize variables to avoid strict mode error
spetersenms 29c0e3b
Cosmetic PSScriptAnalyzer issues fixed.
spetersenms 96a0d36
Additional function documentation
spetersenms 40d895c
Supress PSScriptAnalyzer error
spetersenms 3d6e9a7
Additional PSScriptAnalyzerRules
spetersenms 3f0747a
Additional PSScriptAnalyzer fixes
spetersenms 65b529b
Pre-commit
spetersenms 65c68cd
Supress global var warning in tests.
spetersenms 1139a81
Merge branch 'main' into CodeCoverage
spetersenms d5d660f
Correctly handle no .testResults property.
spetersenms 48106a4
Merge branch 'CodeCoverage' of github.com:spetersenms/AL-Go into Code…
spetersenms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| function Run-AlTests | ||
| ( | ||
| [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, | ||
| [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 | ||
| [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 | ||
| ( | ||
| [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 = $failedTests.message | ||
|
spetersenms marked this conversation as resolved.
Outdated
|
||
| 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 | ||
| } | ||
|
|
||
| function Get-CodeunitTestIsolationTestRunnerId() | ||
| { | ||
| return $global:TestRunnerIsolationCodeunit | ||
| } | ||
|
|
||
| . "$PSScriptRoot\Internal\Constants.ps1" | ||
| Import-Module "$PSScriptRoot\Internal\ALTestRunnerInternal.psm1" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.