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

Logger extensibility #557

Merged
merged 16 commits into from
Mar 3, 2017
Merged
Show file tree
Hide file tree
Changes from 15 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
4 changes: 2 additions & 2 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ function Update-VsixVersion
Write-Log "Update-VsixVersion: Started."

$packageDir = Get-FullCLRPackageDirectory
$vsixVersion = "15.0.3" # Hardcode since we want to keep 15.0.0 for other assemblies.
$vsixVersion = "15.1.0" # Hardcode since we want to keep 15.0.0 for other assemblies.

# VersionSuffix in microbuild comes in the form preview-20170111-01(preview-yyyymmdd-buildNoOfThatDay)
# So Version of the vsix will be 15.0.3.2017011101
# So Version of the vsix will be 15.1.0.2017011101
$vsixVersionSuffix = $VersionSuffix.Split("-");
if($vsixVersionSuffix.Length -ige 2) {
$vsixVersion = "$vsixVersion.$($vsixVersionSuffix[1])$($vsixVersionSuffix[2])"
Expand Down
25 changes: 19 additions & 6 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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

if([System.IO.File]::Exists($fullTrxFilePath)) {
Remove-Item $fullTrxFilePath
}

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

Expand All @@ -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.")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite sure how it is working today in clean machines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

Expand All @@ -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"

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
Expand All @@ -10,7 +10,7 @@
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.5' ">$(PackageTargetFallback);dnxcore50;portable-net45+win8</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Resources.resx"/>
<EmbeddedResource Include="Resources\Resources.resx" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
Expand Down
50 changes: 47 additions & 3 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it better is inject IFileHelper via ctor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, its a valid point. Fixed in next commit.

}

/// <summary>
Expand Down Expand Up @@ -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();

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo RegexPattern instead of ResxPattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
}
}
}
}
8 changes: 4 additions & 4 deletions src/Microsoft.TestPlatform.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public static class TestPlatformDefaults
public static class TestPlatformConstants
{
/// <summary>
/// string pattern used to find the test adapters
/// Regex pattern used to find the test adapters
/// </summary>
public const string TestAdapterPattern = @"*.TestAdapter.dll";
public const string TestAdapterResxPattern = @".*.TestAdapter.dll";

/// <summary>
/// Regex pattern used to find the test adapters
/// Regex pattern used to find the test logger
/// </summary>
public const string TestAdapterRedexPattern = @".*.TestAdapter.dll";
public const string TestLoggerResxPattern = @".*.TestLogger.dll";

}
}
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
}
}

1 change: 1 addition & 0 deletions src/Microsoft.TestPlatform.Common/Friends.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[assembly: InternalsVisibleTo("datacollector, PublicKey =002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.TestPlatform.CommunicationUtilities, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Common, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Microsoft.VisualStudio.TestPlatform.Client, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]

#endregion

Expand Down
20 changes: 20 additions & 0 deletions src/Microsoft.TestPlatform.Common/Logging/LoggerInfo.cs
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;
}
}
}
Loading