Skip to content

Commit

Permalink
[devops] Update and add tests (#15920)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Sep 12, 2022
1 parent c63f238 commit 1552a1e
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tools/devops/automation/scripts/TestResults.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,113 @@ Describe "TestResults tests" {
}
}

Context "new test summmary results" {
It "computes the right summary with missing test results" {
$VerbosePreference = "Continue"
$Env:MyVerbosePreference = 'Continue'
[Environment]::SetEnvironmentVariable("TESTS_JOBSTATUS_LINKER", "Succeeded")
[Environment]::SetEnvironmentVariable("TESTS_JOBSTATUS_INTROSPECTION", "Succeeded")

$testDirectory = Join-Path "." "subdir"
New-Item -Path "$testDirectory" -ItemType "directory" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-1" -Name "TestSummary.md" -Value "# :tada: All 1 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-2" -Name "TestSummary.md" -Value "# :tada: All 2 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-200" -Name "TestSummary.md" -Value "# :tada: All 3 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-3" -Name "TestSummary.md" -Value "# :tada: All 4 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixintrospection-2" -Name "TestSummary.md" -Value "# :tada: All 5 tests passed :tada:" -Force

$labels = "linker;introspection;monotouch-test".Split(";")
$testResults = New-TestSummaryResults -Path "$testDirectory" -Labels $labels -TestPrefix "prefix"

$parallelResults = New-ParallelTestsResults -Results $testResults -Context "context" -TestPrefix "prefix" -VSDropsIndex "vsdropsIndex"

$parallelResults.IsSuccess() | Should -Be $false

$sb = [System.Text.StringBuilder]::new()
$parallelResults.WriteComment($sb)

Remove-Item -Path $testDirectory -Recurse

$content = $sb.ToString()

# Write-Host $content

$content | Should -Be "# Test results
:x: Tests failed on context
1 tests crashed, 0 tests failed, 8 tests passed.
## Failures
### :x: monotouch_test tests
:fire: Failed catastrophically on - monotouch_test (no summary found).
[Html Report (VSDrops)](vsdropsIndex/prefixmonotouch_test/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-prefixmonotouch_test&api-version=6.0&`$format=zip)
## Successes
:white_check_mark: linker: All 3 tests passed. [attempt 200] [Html Report (VSDrops)](vsdropsIndex/prefixlinker/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-prefixlinker&api-version=6.0&`$format=zip)
:white_check_mark: introspection: All 5 tests passed. [attempt 2] [Html Report (VSDrops)](vsdropsIndex/prefixintrospection/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-prefixintrospection&api-version=6.0&`$format=zip)
"
}

It "computes the right summary with failing tests" {
$VerbosePreference = "Continue"
$Env:MyVerbosePreference = 'Continue'
[Environment]::SetEnvironmentVariable("TESTS_JOBSTATUS_LINKER", "Succeeded")
[Environment]::SetEnvironmentVariable("TESTS_JOBSTATUS_INTROSPECTION", "Failed")

$testDirectory = Join-Path "." "subdir"
New-Item -Path "$testDirectory" -ItemType "directory" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-1" -Name "TestSummary.md" -Value "# :tada: All 1 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-2" -Name "TestSummary.md" -Value "# :tada: All 2 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-200" -Name "TestSummary.md" -Value "# :tada: All 3 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixlinker-3" -Name "TestSummary.md" -Value "# :tada: All 4 tests passed :tada:" -Force
New-Item -Path "$testDirectory/TestSummary-prefixintrospection-1" -Name "TestSummary.md" -Value "<summary>5 tests failed, 6 tests passed.</summary>" -Force

$labels = "linker;introspection;monotouch-test".Split(";")
$testResults = New-TestSummaryResults -Path "$testDirectory" -Labels $labels -TestPrefix "prefix"

$parallelResults = New-ParallelTestsResults -Results $testResults -Context "context" -TestPrefix "prefix" -VSDropsIndex "vsdropsIndex"

$parallelResults.IsSuccess() | Should -Be $false

$sb = [System.Text.StringBuilder]::new()
$parallelResults.WriteComment($sb)

Remove-Item -Path $testDirectory -Recurse

$content = $sb.ToString()

# Write-Host $content

$content | Should -Be "# Test results
:x: Tests failed on context
1 tests crashed, 5 tests failed, 9 tests passed.
## Failures
### :x: introspection tests
<summary>5 tests failed, 6 tests passed.</summary>
<details>
</details>
[Html Report (VSDrops)](vsdropsIndex/prefixintrospection/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-prefixintrospection&api-version=6.0&`$format=zip)
### :x: monotouch_test tests
:fire: Failed catastrophically on - monotouch_test (no summary found).
[Html Report (VSDrops)](vsdropsIndex/prefixmonotouch_test/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-prefixmonotouch_test&api-version=6.0&`$format=zip)
## Successes
:white_check_mark: linker: All 3 tests passed. [attempt 200] [Html Report (VSDrops)](vsdropsIndex/prefixlinker/;/tests/vsdrops_index.html) [Download](/_apis/build/builds//artifacts?artifactName=HtmlReport-prefixlinker&api-version=6.0&`$format=zip)
"
}
}
}

5 comments on commit 1552a1e

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.