Skip to content

Commit 2f0d127

Browse files
JamesWTruherTravisEz13
authored andcommitted
Check to be sure that the test result file has actual results before uploading (PowerShell#9253)
VSTS produces a warning if the result set is 0, we will skip uploading this to avoid the warning and better support automation scenarios. ## PR Context We have automation which checks our test results and if the result set is 0 for that file, a warning is produced. This PR will avoid uploading that file into the test results (which is valid, as there are no run tests). We will still add the file to our artifact list for completeness.
1 parent 8a0ecaf commit 2f0d127

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

build.psm1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,13 @@ function Publish-TestResults
12301230
$_ -replace 'result="Ignored"', 'result="Skipped"'
12311231
} | Out-File -FilePath $tempFilePath -Encoding ascii -Force
12321232

1233-
Write-Host "##vso[results.publish type=$Type;mergeResults=true;runTitle=$Title;publishRunAttachments=true;resultFiles=$tempFilePath;]"
1233+
# If we attempt to upload a result file which has no test cases in it, then vsts will produce a warning
1234+
# so check to be sure we actually have a result file that contains test cases to upload.
1235+
# If the the "test-case" count is greater than 0, then we have results.
1236+
# Regardless, we want to upload this as an artifact, so this logic doesn't pertain to that.
1237+
if ( @(([xml](Get-Content $Path)).SelectNodes(".//test-case")).Count -gt 0 -or $Type -eq 'XUnit' ) {
1238+
Write-Host "##vso[results.publish type=$Type;mergeResults=true;runTitle=$Title;publishRunAttachments=true;resultFiles=$tempFilePath;]"
1239+
}
12341240

12351241
$resolvedPath = (Resolve-Path -Path $Path).ProviderPath
12361242
Write-Host "##vso[artifact.upload containerfolder=testResults;artifactname=testResults]$resolvedPath"

0 commit comments

Comments
 (0)