|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Runs xUnit |
| 4 | +#> |
| 5 | + |
| 6 | +[CmdletBinding()] |
| 7 | +Param( |
| 8 | + [Parameter(Mandatory=$true)] |
| 9 | + [ValidateNotNullOrEmpty()] |
| 10 | + [string] |
| 11 | + $Project, |
| 12 | + [int] |
| 13 | + $TimeoutDuration, |
| 14 | + [string] |
| 15 | + $Configuration, |
| 16 | + [switch] |
| 17 | + $AppVeyor = $false |
| 18 | +) |
| 19 | + |
| 20 | +$rootDirectory = Split-Path (Split-Path $MyInvocation.MyCommand.Path) |
| 21 | +Push-Location $rootDirectory |
| 22 | + |
| 23 | +$dll = "src\$Project\bin\$Configuration\$Project.dll" |
| 24 | + |
| 25 | +if ($AppVeyor) { |
| 26 | + $xunitDirectory = Join-Path $rootDirectory packages\xunit.runner.console.2.1.0\tools |
| 27 | + $consoleRunner = Join-Path $xunitDirectory xunit.console.x86.exe |
| 28 | + $args = $dll, "-noshadow", "-parallel", "all", "-appveyor" |
| 29 | + [object[]] $output = "$consoleRunner " + ($args -join " ") |
| 30 | + & $consoleRunner ($args | %{ "`"$_`"" }) |
| 31 | + if($LastExitCode -ne 0) { |
| 32 | + $host.SetShouldExit($LastExitCode) |
| 33 | + } |
| 34 | +} else { |
| 35 | + $xunitDirectory = Join-Path $rootDirectory packages\xunit.runner.console.2.1.0\tools |
| 36 | + $consoleRunner = Join-Path $xunitDirectory xunit.console.x86.exe |
| 37 | + $xml = Join-Path $rootDirectory "nunit-$Project.xml" |
| 38 | + $outputPath = [System.IO.Path]::GetTempFileName() |
| 39 | + |
| 40 | + $args = $dll, "-noshadow", "-xml", $xml, "-parallel", "all" |
| 41 | + |
| 42 | + [object[]] $output = "$consoleRunner " + ($args -join " ") |
| 43 | + |
| 44 | + $process = Start-Process -PassThru -NoNewWindow -RedirectStandardOutput $outputPath $consoleRunner ($args | %{ "`"$_`"" }) |
| 45 | + Wait-Process -InputObject $process -Timeout $TimeoutDuration -ErrorAction SilentlyContinue |
| 46 | + if ($process.HasExited) { |
| 47 | + $output += Get-Content $outputPath |
| 48 | + $exitCode = $process.ExitCode |
| 49 | + } else { |
| 50 | + $output += "Tests timed out. Backtrace:" |
| 51 | + $output += Get-DotNetStack $process.Id |
| 52 | + $exitCode = 9999 |
| 53 | + } |
| 54 | + Stop-Process -InputObject $process |
| 55 | + Remove-Item $outputPath |
| 56 | + Pop-Location |
| 57 | + |
| 58 | + $result = New-Object System.Object |
| 59 | + $result | Add-Member -Type NoteProperty -Name Output -Value $output |
| 60 | + $result | Add-Member -Type NoteProperty -Name ExitCode -Value $exitCode |
| 61 | + $result |
| 62 | +} |
0 commit comments