Skip to content

Commit

Permalink
Resolved conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Harsh Jain committed Apr 17, 2017
2 parents 7760729 + 368145d commit 11153a6
Show file tree
Hide file tree
Showing 31 changed files with 501 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Internal.TestPlatform.Extensions">
<Version>15.0.0</Version>
<Version>15.1.0-preview-678431</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Client\Microsoft.TestPlatform.Client.csproj" />
Expand Down
14 changes: 8 additions & 6 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ $env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1
# Dotnet build doesn't support --packages yet. See https://github.com/dotnet/cli/issues/2712
$env:NUGET_PACKAGES = $env:TP_PACKAGES_DIR
$env:NUGET_EXE_Version = "3.4.3"
# Dotnet build is not supporting -p: to pass arguments to msbuild. Revert to "latest" after the issue is resolved. See https://github.com/dotnet/cli/issues/6124
$env:DOTNET_CLI_VERSION = "2.0.0-preview1-005448"
$env:DOTNET_CLI_VERSION = "latest"
$env:LOCATE_VS_API_VERSION = "0.2.4-beta"
$env:MSBUILD_VERSION = "15.0"

Expand Down Expand Up @@ -133,8 +132,11 @@ function Install-DotNetCli
New-Item -ItemType directory -Path $dotnetInstallPath -Force | Out-Null
& $dotnetInstallScript -Channel "master" -InstallDir $dotnetInstallPath -NoPath -Version $env:DOTNET_CLI_VERSION

# Uncomment to pull in additional shared frameworks.
# This is added to get netcoreapp1.1 shared components.
# Pull in additional shared frameworks.
# Get netcoreapp1.0 shared components.
& $dotnetInstallScript -InstallDir $dotnetInstallPath -SharedRuntime -Version '1.0.4' -Channel 'preview'

# Get netcoreapp1.1 shared components.
& $dotnetInstallScript -InstallDir $dotnetInstallPath -SharedRuntime -Version '1.1.1' -Channel 'release/1.1.0'

Write-Log "Install-DotNetCli: Complete. {$(Get-ElapsedTime($timer))}"
Expand Down Expand Up @@ -258,7 +260,7 @@ function Publish-Package
Move-Item $coreCLR20PackageDir\$file $coreCLRExtensionsDir -Force
}

# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
# Note Note: If there are some dependencies for the TestHostRuntimeProvider assemblies, those need to be moved too.
$runtimeproviders = @("Microsoft.TestPlatform.TestHostRuntimeProvider.dll", "Microsoft.TestPlatform.TestHostRuntimeProvider.pdb")
foreach($file in $runtimeproviders) {
Write-Verbose "Move-Item $fullCLRPackageDir\$file $fullCLRExtensionsDir -Force"
Expand Down Expand Up @@ -299,7 +301,7 @@ function Create-VsixPackage
$packageDir = Get-FullCLRPackageDirectory

# Copy legacy dependencies
$legacyDir = Join-Path $env:TP_PACKAGES_DIR "Microsoft.Internal.TestPlatform.Extensions\15.0.0\contentFiles\any\any"
$legacyDir = Join-Path $env:TP_PACKAGES_DIR "Microsoft.Internal.TestPlatform.Extensions\15.1.0-preview-678431\contentFiles\any\any"
Copy-Item -Recurse $legacyDir\* $packageDir -Force

# Copy COM Components and their manifests over
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<MSTestFrameworkVersion>1.1.14</MSTestFrameworkVersion>
<MSTestAdapterVersion>1.1.14</MSTestAdapterVersion>
<MSTestAssertExtensionVersion>1.0.2-preview</MSTestAssertExtensionVersion>
<MSTestAssertExtensionVersion>1.0.3-preview</MSTestAssertExtensionVersion>

<XUnitFrameworkVersion>2.2.0</XUnitFrameworkVersion>
<XUnitAdapterVersion>2.2.0</XUnitAdapterVersion>
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- Static analysis dependencies -->
<ItemGroup Condition="$(EnableCodeAnalysis) == 'true'">
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.0-beta001</Version>
<Version>1.0.1</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
42 changes: 36 additions & 6 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ namespace Microsoft.VisualStudio.TestPlatform.Client
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Client.Discovery;
using Microsoft.VisualStudio.TestPlatform.Client.Execution;
using Microsoft.VisualStudio.TestPlatform.Common;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.Common.Hosting;
using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.Common.Utilities;
Expand All @@ -31,6 +33,14 @@ public class TestPlatform : ITestPlatform

private readonly IFileHelper fileHelper;

static TestPlatform()
{
// TODO This is not the right away to force initialization of default extensions. Test runtime providers
// require this today. They're getting initialized even before test adapter paths are provided, which is
// incorrect.
AddExtensionAssembliesFromExtensionDirectory();
}

/// <summary>
/// Initializes a new instance of the <see cref="TestPlatform"/> class.
/// </summary>
Expand Down Expand Up @@ -76,10 +86,11 @@ public IDiscoveryRequest CreateDiscoveryRequest(DiscoveryCriteria discoveryCrite
throw new ArgumentNullException(nameof(discoveryCriteria));
}

this.UpdateTestAdapterPaths(discoveryCriteria.RunSettings);
this.AddExtensionAssemblies(discoveryCriteria.RunSettings);

var testHostManager = this.testHostProviderManager.GetTestHostManagerByRunConfiguration(discoveryCriteria.RunSettings);

testHostManager.Initialize(TestSessionMessageLogger.Instance, discoveryCriteria.RunSettings);

var discoveryManager = this.TestEngine.GetDiscoveryManager(testHostManager, discoveryCriteria, protocolConfig);
discoveryManager.Initialize();

Expand All @@ -100,14 +111,14 @@ public ITestRunRequest CreateTestRunRequest(TestRunCriteria testRunCriteria, Pro
throw new ArgumentNullException(nameof(testRunCriteria));
}

this.UpdateTestAdapterPaths(testRunCriteria.TestRunSettings);
this.AddExtensionAssemblies(testRunCriteria.TestRunSettings);

var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(testRunCriteria.TestRunSettings);

// Update and initialize loggers only when DesignMode is false
if (runConfiguration.DesignMode == false)
{
this.UpdateTestLoggerPath(testRunCriteria);
this.AddExtensionAssembliesFromSource(testRunCriteria);

// Initialize loggers
TestLoggerManager.Instance.InitializeLoggers();
Expand Down Expand Up @@ -165,7 +176,7 @@ public void UpdateExtensions(IEnumerable<string> pathToAdditionalExtensions, boo
/// <param name="runSettings">
/// The run Settings.
/// </param>
private void UpdateTestAdapterPaths(string runSettings)
private void AddExtensionAssemblies(string runSettings)
{
IEnumerable<string> customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(runSettings);

Expand Down Expand Up @@ -199,7 +210,7 @@ private void UpdateTestAdapterPaths(string runSettings)
/// <param name="testRunCriteria">
/// The test Run Criteria.
/// </param>
private void UpdateTestLoggerPath(TestRunCriteria testRunCriteria)
private void AddExtensionAssembliesFromSource(TestRunCriteria testRunCriteria)
{
IEnumerable<string> sources = testRunCriteria.Sources;
if (testRunCriteria.HasSpecificTests)
Expand All @@ -224,5 +235,24 @@ private void UpdateTestLoggerPath(TestRunCriteria testRunCriteria)
this.UpdateExtensions(loggersToUpdate, true);
}
}

/// <summary>
/// Find all test platform extensions from the `.\Extensions` directory. This is used to load the inbox extensions like
/// Trx logger and legacy test extensions like mstest v1, mstest c++ etc..
/// </summary>
private static void AddExtensionAssembliesFromExtensionDirectory()
{
var fileHelper = new FileHelper();
var extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.Location), "Extensions");
var defaultExtensionPaths = new List<string>();
if (fileHelper.DirectoryExists(extensionsFolder))
{
var dlls = fileHelper.EnumerateFiles(extensionsFolder, ".*.dll", SearchOption.TopDirectoryOnly);
defaultExtensionPaths.AddRange(dlls);
var exes = fileHelper.EnumerateFiles(extensionsFolder, ".*.exe", SearchOption.TopDirectoryOnly);
defaultExtensionPaths.AddRange(exes);
TestPluginCache.Instance.DefaultExtensionPaths = defaultExtensionPaths;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class TestPluginCache

private static TestPluginCache instance;

private List<string> defaultExtensionPaths = new List<string>();

#endregion

#region Constructor
Expand Down Expand Up @@ -308,6 +310,21 @@ public void UpdateExtensions(IEnumerable<string> additionalExtensionsPath, bool

#region Utility methods

internal IEnumerable<string> DefaultExtensionPaths
{
get
{
return this.defaultExtensionPaths;
}
set
{
if (value != null)
{
this.defaultExtensionPaths.AddRange(value);
}
}
}

/// <summary>
/// Checks if a directory exists
/// </summary>
Expand Down Expand Up @@ -415,6 +432,12 @@ internal IList<string> GetDefaultResolutionPaths()
resolutionPaths.AddRange(extensionDirectories);
}

extensionDirectories = this.defaultExtensionPaths?.Select(e => Path.GetDirectoryName(Path.GetFullPath(e))).Distinct();
if (extensionDirectories != null && extensionDirectories.Any())
{
resolutionPaths.AddRange(extensionDirectories);
}

var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location);

if (!resolutionPaths.Contains(currentDirectory))
Expand Down Expand Up @@ -519,7 +542,7 @@ private Assembly CurrentDomainAssemblyResolve(AssemblyLoadContext loadContext, A
}
}
}

/// <summary>
/// Log the extensions
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Serializati
using System;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/// <summary>
/// Converter used by v1 protocol serializer to serialize TestCase object to and from v1 json
/// </summary>
public class TestCaseConverter : JsonConverter
{
/// <inheritdoc/>
public override bool CanRead => false;

/// <inheritdoc/>
public override bool CanConvert(Type objectType)
{
Expand All @@ -24,28 +22,133 @@ public override bool CanConvert(Type objectType)
/// <inheritdoc/>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
// We do not need this as SetPropetyValue inside StoreKvpList will
// set the properties as expected.
throw new NotImplementedException();
var testCase = new TestCase();

var data = JObject.Load(reader);
var properties = data["Properties"];

if (properties != null && properties.HasValues)
{
// Every class that inherits from TestObject uses a properties store for <Property, Object>
// key value pairs.
foreach (var property in properties.Values<JToken>())
{
var testProperty = property["Key"].ToObject<TestProperty>();

// Let the null values be passed in as null data
var token = property["Value"];
string propertyData = null;
if (token.Type != JTokenType.Null)
{
// If the property is already a string. No need to convert again.
if (token.Type == JTokenType.String)
{
propertyData = token.ToObject<string>();
}
else
{
// On deserialization, the value for each TestProperty is always a string. It is up
// to the consumer to deserialize it further as appropriate.
propertyData = token.ToString(Formatting.None).Trim('"');
}
}

switch (testProperty.Id)
{
case "TestCase.Id":
testCase.Id = Guid.Parse(propertyData); break;
case "TestCase.ExecutorUri":
testCase.ExecutorUri = new Uri(propertyData); break;
case "TestCase.FullyQualifiedName":
testCase.FullyQualifiedName = propertyData; break;
case "TestCase.DisplayName":
testCase.DisplayName = propertyData; break;
case "TestCase.Source":
testCase.Source = propertyData; break;
case "TestCase.CodeFilePath":
testCase.CodeFilePath = propertyData; break;
case "TestCase.LineNumber":
testCase.LineNumber = int.Parse(propertyData); break;
default:
testCase.SetPropertyValue(testProperty, propertyData);
break;
}
}
}

return testCase;
}

/// <inheritdoc/>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
// P2 to P1
var testCase = value as TestCase;
var properties = testCase.GetProperties();

writer.WriteStartObject();
writer.WritePropertyName("Properties");
writer.WriteStartArray();
foreach (var property in properties)

// Version Note: In 15.0.0, if some properties in TestCase were not set, they were not serialized.
// Starting 15.1.0, test platform sends in default values for properties that were not set. This is not
// a breaking change.

// TestCase.FullyQualifiedName
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.FullyQualifiedName, serializer);
writer.WriteValue(testCase.FullyQualifiedName);
writer.WriteEndObject();

// TestCase.ExecutorUri
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.ExecutorUri, serializer);
writer.WriteValue(testCase.ExecutorUri.OriginalString);
writer.WriteEndObject();

// TestCase.Source
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.Source, serializer);
writer.WriteValue(testCase.Source);
writer.WriteEndObject();

// TestCase.CodeFilePath
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.CodeFilePath, serializer);
writer.WriteValue(testCase.CodeFilePath);
writer.WriteEndObject();

// TestCase.DisplayName
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.DisplayName, serializer);
writer.WriteValue(testCase.DisplayName);
writer.WriteEndObject();

// TestCase.Id
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.Id, serializer);
writer.WriteValue(testCase.Id);
writer.WriteEndObject();

// TestCase.LineNumber
writer.WriteStartObject();
AddProperty(writer, TestCaseProperties.LineNumber, serializer);
writer.WriteValue(testCase.LineNumber);
writer.WriteEndObject();

foreach (var property in testCase.GetProperties())
{
serializer.Serialize(writer, property);
}

writer.WriteEndArray();
writer.WriteEndObject();
}

private static void AddProperty(JsonWriter writer, TestProperty property, JsonSerializer serializer)
{
writer.WritePropertyName("Key");
serializer.Serialize(writer, property);
writer.WritePropertyName("Value");
}
}
}
Loading

0 comments on commit 11153a6

Please sign in to comment.