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 10 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
58 changes: 38 additions & 20 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $env:TP_TOOLS_DIR = Join-Path $env:TP_ROOT_DIR "tools"
$env:TP_PACKAGES_DIR = Join-Path $env:TP_ROOT_DIR "packages"
$env:TP_OUT_DIR = Join-Path $env:TP_ROOT_DIR "artifacts"


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

#
# Dotnet configuration
#
Expand All @@ -63,15 +64,18 @@ $Script:TPT_SkipProjects = @("testhost.UnitTests", "vstest.console.UnitTests")
$Script:TPT_Pattern = $Pattern
$Script:TPT_FailFast = $FailFast
$Script:TPT_Parallel = $Parallel
$Script:TPT_TestResultsDir = Join-Path $env:TP_ROOT_DIR "TestResults"
$Script:TPT_DefaultTrxFileName = "TrxLogResults.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 +88,19 @@ function Write-VerboseLog([string] $message)
Write-Verbose $message
}

function Print-FailedTests($TrxFilePath)
{
if(![System.IO.File]::Exists($TrxFilePath)){
Write-Log "TrxFile: $TrxFilePath doesn't exists"
return
}
$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 +164,16 @@ function Invoke-Test
if ($TPT_Parallel) {
# Fill in the framework in test containers
$testContainerSet = $testContainers | % { [System.String]::Format($_, $fx) }

$trxLogFileName = [System.String]::Format("Parallel_{0}_{1}", $fx, $Script:TPT_DefaultTrxFileName)
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;LogFileName=$trxLogFileName`""
$output = & $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel /logger:"trx;LogFileName=$trxLogFileName"
} 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;LogFileName=$trxLogFileName`""
$output = & $dotNetPath $vstestConsolePath $testContainerSet /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /parallel /logger:"trx;LogFileName=$trxLogFileName"
}

Reset-TestEnvironment
Expand All @@ -165,8 +182,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 (Join-Path $Script:TPT_TestResultsDir $trxLogFileName)

Set-ScriptFailed

Expand All @@ -179,28 +196,29 @@ function Invoke-Test
$testContainers | % {
# Fill in the framework in test containers
$testContainer = [System.String]::Format($_, $fx)
$trxLogFileName = [System.String]::Format("{0}_{1}_{2}", ($(Get-ChildItem $testContainer).Name), $fx, $Script:TPT_DefaultTrxFileName)

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;LogFileName=$trxLogFileName`""
$output = & $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /logger:"trx;LogFileName=$trxLogFileName"
} 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;LogFileName=$trxLogFileName`""
$output = & $dotNetPath $vstestConsolePath $testContainer /platform:$testArchitecture /framework:$testFrameWork /testAdapterPath:"$testAdapterPath" /logger:"trx;LogFileName=$trxLogFileName"
}

Reset-TestEnvironment

if ($output[-2].Contains("Test Run Successful.")) {
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 (Join-Path $Script:TPT_TestResultsDir $trxLogFileName)

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