-
Notifications
You must be signed in to change notification settings - Fork 331
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
Logger extensibility #557
Logger extensibility #557
Changes from 15 commits
3014f9b
5d8aac7
89288db
ffa89e1
409dc44
34d23db
01d1eb6
8b56fd4
d9d8aa6
7be3bd9
935afb6
689cdc7
b71b303
afe0a00
e40a450
73129bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,13 @@ function Invoke-Test | |
# Fill in the framework in test containers | ||
$testContainerSet = $testContainers | % { [System.String]::Format($_, $fx) } | ||
$trxLogFileName = [System.String]::Format("Parallel_{0}_{1}", $fx, $Script:TPT_DefaultTrxFileName) | ||
|
||
# Remove already existed trx file name as due to which warning will get generated and since we are expecting result in a particular format, that will break | ||
$fullTrxFilePath = Join-Path $Script:TPT_TestResultsDir $trxLogFileName | ||
if([System.IO.File]::Exists($fullTrxFilePath)) { | ||
Remove-Item $fullTrxFilePath | ||
} | ||
|
||
Set-TestEnvironment | ||
if($fx -eq $TPT_TargetFrameworkFullCLR) { | ||
|
||
|
@@ -177,10 +184,10 @@ function Invoke-Test | |
|
||
Reset-TestEnvironment | ||
|
||
if ($output[-2].Contains("Test Run Successful.")) { | ||
Write-Log ".. . $($output[-3])" | ||
if ($output[-3].Contains("Test Run Successful.")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not quite sure how it is working today in clean machines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we have added trx in our test, after summary it will add trx file info which is increasing the result by one line. Since every time we are deleting the trx file before running test, its equal to clean machine run |
||
Write-Log ".. . $($output[-4])" | ||
} else { | ||
Write-Log ".. . $($output[-2])" | ||
Write-Log ".. . $($output[-3])" | ||
Write-Log ".. . Failed tests:" $Script:TPT_ErrorMsgColor | ||
Print-FailedTests (Join-Path $Script:TPT_TestResultsDir $trxLogFileName) | ||
|
||
|
@@ -196,6 +203,12 @@ function Invoke-Test | |
# 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) | ||
|
||
# Remove already existed trx file name as due to which warning will get generated and since we are expecting result in a particular format, that will break | ||
$fullTrxFilePath = Join-Path $Script:TPT_TestResultsDir $trxLogFileName | ||
if([System.IO.File]::Exists($fullTrxFilePath)) { | ||
Remove-Item $fullTrxFilePath | ||
} | ||
|
||
Write-Log ".. Container: $testContainer" | ||
|
||
|
@@ -212,10 +225,10 @@ function Invoke-Test | |
} | ||
|
||
Reset-TestEnvironment | ||
if ($output[-2].Contains("Test Run Successful.")) { | ||
Write-Log ".. . $($output[-3])" | ||
if ($output[-3].Contains("Test Run Successful.")) { | ||
Write-Log ".. . $($output[-4])" | ||
} else { | ||
Write-Log ".. . $($output[-2])" | ||
Write-Log ".. . $($output[-3])" | ||
Write-Log ".. . Failed tests:" $Script:TPT_ErrorMsgColor | ||
Print-FailedTests (Join-Path $Script:TPT_TestResultsDir $trxLogFileName) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,27 +6,33 @@ namespace Microsoft.VisualStudio.TestPlatform.Client | |
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Microsoft.VisualStudio.TestPlatform.Client.Discovery; | ||
using Microsoft.VisualStudio.TestPlatform.Client.Execution; | ||
using Microsoft.VisualStudio.TestPlatform.Common; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Logging; | ||
using Microsoft.VisualStudio.TestPlatform.Common.Utilities; | ||
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; | ||
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; | ||
|
||
/// <summary> | ||
/// Implementation for TestPlatform | ||
/// </summary> | ||
public class TestPlatform : ITestPlatform | ||
{ | ||
protected IFileHelper fileHelper; | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TestPlatform"/> class. | ||
/// </summary> | ||
public TestPlatform() : this(new TestEngine()) | ||
{ | ||
fileHelper = new FileHelper(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better is inject IFileHelper via ctor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, its a valid point. Fixed in next commit. |
||
} | ||
|
||
/// <summary> | ||
|
@@ -62,7 +68,7 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite | |
|
||
var runconfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(discoveryCriteria.RunSettings); | ||
var testHostManager = this.TestEngine.GetDefaultTestHostManager(runconfiguration); | ||
|
||
var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria); | ||
discoveryManager.Initialize(); | ||
|
||
|
@@ -85,6 +91,16 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria) | |
UpdateTestAdapterPaths(testRunCriteria.TestRunSettings); | ||
|
||
var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings); | ||
|
||
// Update and initialize loggers only when DesignMode is false | ||
if (runConfiguration.DesignMode == false) | ||
{ | ||
UpdateTestLoggerPath(testRunCriteria.Sources); | ||
|
||
// Initialize loggers | ||
TestLoggerManager.Instance.InitializeLoggers(); | ||
} | ||
|
||
var testHostManager = this.TestEngine.GetDefaultTestHostManager(runConfiguration); | ||
|
||
if (testRunCriteria.TestHostLauncher != null) | ||
|
@@ -147,15 +163,43 @@ private void UpdateTestAdapterPaths(string runSettings) | |
EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); | ||
continue; | ||
} | ||
|
||
List<string> adapterFiles = new List<string>( | ||
Directory.EnumerateFiles(adapterPath,TestPlatformConstants.TestAdapterPattern , SearchOption.AllDirectories) | ||
this.fileHelper.EnumerateFiles(adapterPath, TestPlatformConstants.TestAdapterResxPattern, SearchOption.AllDirectories) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: typo RegexPattern instead of ResxPattern There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in next commit |
||
); | ||
if (adapterFiles.Count > 0) | ||
{ | ||
this.UpdateExtensions(adapterFiles, false); | ||
this.UpdateExtensions(adapterFiles, true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Update the test logger paths from source directory | ||
/// </summary> | ||
private void UpdateTestLoggerPath(IEnumerable<string> sources) | ||
{ | ||
if (sources == null) | ||
{ | ||
return; | ||
} | ||
|
||
List<string> loggersToUpdate = new List<string>(); | ||
|
||
foreach (var source in sources) | ||
{ | ||
var sourceDirectory = Path.GetDirectoryName(source); | ||
if (!string.IsNullOrEmpty(sourceDirectory) && this.fileHelper.DirectoryExists(sourceDirectory)) | ||
{ | ||
loggersToUpdate.AddRange(this.fileHelper.EnumerateFiles(sourceDirectory, TestPlatformConstants.TestLoggerResxPattern, SearchOption.TopDirectoryOnly).ToList()); | ||
} | ||
} | ||
|
||
if (loggersToUpdate.Count > 0) | ||
{ | ||
this.UpdateExtensions(loggersToUpdate, true); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.Common.Exceptions | ||
{ | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using System; | ||
|
||
public class InvalidLoggerException : TestPlatformException | ||
{ | ||
#region Constructors | ||
|
||
/// <summary> | ||
/// Initializes with the message. | ||
/// </summary> | ||
/// <param name="message">Message for the exception.</param> | ||
public InvalidLoggerException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes with message and inner exception. | ||
/// </summary> | ||
/// <param name="message">Message for the exception.</param> | ||
/// <param name="innerException">The inner exception.</param> | ||
public InvalidLoggerException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
} | ||
|
||
#endregion | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.Common.Logging | ||
{ | ||
using System.Collections.Generic; | ||
public class LoggerInfo | ||
{ | ||
public string arument; | ||
public string loggerIdentifier; | ||
public Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||
|
||
public LoggerInfo(string arument, string loggerIdentifier, Dictionary<string, string> parameters) | ||
{ | ||
this.arument = arument; | ||
this.loggerIdentifier = loggerIdentifier; | ||
this.parameters = parameters; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't trx file be overwritten automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or is it a warning that requires this step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it the warning due to which we required this step