...

Text file src/github.com/Azure/azure-sdk-for-go/eng/scripts/run_tests.ps1

Documentation: github.com/Azure/azure-sdk-for-go/eng/scripts

     1#Requires -Version 7.0
     2
     3Param(
     4    [string] $serviceDirectory,
     5    [string] $testTimeout
     6)
     7
     8Push-Location sdk/$serviceDirectory
     9Write-Host "##[command] Executing 'go test -timeout $testTimeout -v -coverprofile coverage.txt ./...' in sdk/$serviceDirectory"
    10
    11go test -timeout $testTimeout -v -coverprofile coverage.txt ./... | Tee-Object -FilePath outfile.txt
    12if ($LASTEXITCODE) {
    13    exit $LASTEXITCODE
    14}
    15
    16Get-Content outfile.txt | go-junit-report > report.xml
    17
    18# if no tests were actually run (e.g. examples) delete the coverage file so it's omitted from the coverage report
    19if (Select-String -path ./report.xml -pattern '<testsuites></testsuites>' -simplematch -quiet) {
    20    Write-Host "##[command]Deleting empty coverage file"
    21    Remove-Item coverage.txt
    22    Remove-Item outfile.txt
    23    Remove-Item report.xml
    24
    25    Pop-Location
    26} else {
    27    # Tests were actually run create a coverage report
    28    $repoRoot = Resolve-Path "$PSScriptRoot/../../"
    29
    30    gocov convert ./coverage.txt > ./coverage.json
    31
    32    # gocov converts rely on standard input
    33    Get-Content ./coverage.json | gocov-xml > ./coverage.xml
    34    Get-Content ./coverage.json | gocov-html > ./coverage.html
    35
    36    Move-Item ./coverage.xml $repoRoot
    37    Move-Item ./coverage.html $repoRoot
    38
    39    # use internal tool to fail if coverage is too low
    40    Pop-Location
    41
    42    go run $repoRoot/eng/tools/internal/coverage/coverage.go `
    43        -config $repoRoot/eng/config.json `
    44        -serviceDirectory $serviceDirectory `
    45        -searchDirectory $repoRoot
    46}

View as plain text