Skip to content
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

Add enhancement: trx logger can take logfile parameter #282

Merged
merged 15 commits into from
Dec 26, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ $Script:TPT_SkipProjects = @("testhost.UnitTests", "vstest.console.UnitTests")
$Script:TPT_Pattern = $Pattern
$Script:TPT_FailFast = $FailFast
$Script:TPT_Parallel = $Parallel
$Script:TPT_TrxFileName = "TestResults.trx"
$Script:TPT_ErrorMsgColor = "Red"

#
# Capture error state in any step globally to modify return code
$Script:ScriptFailed = $false

function Write-Log ([string] $message)
function Write-Log ([string] $message, $messageColor = "Green")
{
$currentColor = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = "Green"
$Host.UI.RawUI.ForegroundColor = $messageColor
if ($message)
{
Write-Output "... $message"
Expand All @@ -84,6 +86,15 @@ function Write-VerboseLog([string] $message)
Write-Verbose $message
}

function Print-FailedTests($TrxFilePath)
{
$xdoc = [xml] (get-content $TrxFilePath)
$FailedTestIds = $xdoc.TestRun.Results.UnitTestResult |?{$_.GetAttribute("outcome") -eq "Failed"} | %{$_.testId}
if ($FailedTestIds) {
Write-Log (".. .. . " + ($xdoc.TestRun.TestDefinitions.UnitTest | ?{ $FailedTestIds.Contains($_.GetAttribute("id")) } | %{ "$($_.TestMethod.className).$($_.TestMethod.name)"})) $Script:TPT_ErrorMsgColor
}
}

function Invoke-Test
{
$timer = Start-Timer
Expand Down Expand Up @@ -147,16 +158,16 @@ function Invoke-Test
if ($TPT_Parallel) {
# Fill in the framework in test containers
$testContainerSet = $testContainers | % { [System.String]::Format($_, $fx) }

$trxLogFile = Join-Path $src ("Parallel_"+ $fx + "_" + $Script:TPT_TrxFileName)
Set-TestEnvironment
if($fx -eq $TPT_TargetFrameworkFullCLR){
if($fx -eq $TPT_TargetFrameworkFullCLR) {

Write-Verbose "$vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /parallel"
$output = & $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel
}else{
Write-Verbose "$vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /parallel /logger:`"trx;logfile=$trxLogFile`""
$output = & $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel /logger:"trx;logfile=$trxLogFile"
} else {

Write-Verbose "$dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /parallel"
$output = & $dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel
Write-Verbose "$dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /parallel /logger:`"trx;logfile=$trxLogFile`""
$output = & $dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel /logger:"trx;logfile=$trxLogFile"
}

Reset-TestEnvironment
Expand All @@ -165,8 +176,8 @@ function Invoke-Test
Write-Log ".. . $($output[-3])"
} else {
Write-Log ".. . $($output[-2])"
Write-Log ".. . Failed tests:"
Write-Log ".. . $($output -match '^Failed')"
Write-Log ".. . Failed tests:" $Script:TPT_ErrorMsgColor
Print-FailedTests $trxLogFile

Set-ScriptFailed

Expand All @@ -179,18 +190,19 @@ function Invoke-Test
$testContainers | % {
# Fill in the framework in test containers
$testContainer = [System.String]::Format($_, $fx)
$trxLogFile = Join-Path ($(Get-ChildItem $testContainer).Directory.FullName) $Script:TPT_TrxFileName
Write-Log ".. Container: $testContainer"

Set-TestEnvironment

if($fx -eq $TPT_TargetFrameworkFullCLR){
if($fx -eq $TPT_TargetFrameworkFullCLR) {

Write-Verbose "$vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath"
$output = & $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath"
}else{
Write-Verbose "$vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /logger:`"trx;logfile=$trxLogFile`""
$output = & $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /logger:"trx;logfile=$trxLogFile"
} else {

Write-Verbose "$dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath"
$output = & $dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath"
Write-Verbose "$dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:$testAdapterPath /logger:`"trx;logfile=$trxLogFile`""
$output = & $dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /logger:"trx;logfile=$trxLogFile"
}

Reset-TestEnvironment
Expand All @@ -199,8 +211,8 @@ function Invoke-Test
Write-Log ".. . $($output[-3])"
} else {
Write-Log ".. . $($output[-2])"
Write-Log ".. . Failed tests:"
Write-Log ".. . $($output -match '^Failed')"
Write-Log ".. . Failed tests:" $Script:TPT_ErrorMsgColor
Print-FailedTests $trxLogFile

Set-ScriptFailed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ private Dictionary<string, string> UpdateLoggerParamters(Dictionary<string, stri
}

// Add default logger parameters...
// todo Read Output Directory from RunSettings
loggerParams[DefaultLoggerParameterNames.TestRunDirectory] = null;
loggerParams[DefaultLoggerParameterNames.TestRunDirectory] = this.GetResultsDirectory(RunSettingsManager.Instance.ActiveRunSettings);
return loggerParams;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,7 @@ Error Details: {1}:{2}</value>
<data name="TS_UncategorizedResults" xml:space="preserve">
<value>Results Not in a List</value>
</data>
<data name="TrxLoggerResultsFileOverwriteWarning" xml:space="preserve">
<value>WARNING: Overwriting results file: {0}</value>
</data>
</root>
Loading