Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/FilterEscape' into FilterEscape
Browse files Browse the repository at this point in the history
  • Loading branch information
genlu committed Jun 1, 2018
2 parents 57ef9c5 + 9657101 commit 2d032d2
Show file tree
Hide file tree
Showing 32 changed files with 448 additions and 99 deletions.
2 changes: 1 addition & 1 deletion scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.7.63</MoqVersion>
<TestPlatformExternalsVersion>15.8.0-preview-1705516</TestPlatformExternalsVersion>
<TestPlatformExternalsVersion>15.8.0-preview-1734347</TestPlatformExternalsVersion>
<MSInternalCodeCoverageVersion>1.0.7</MSInternalCodeCoverageVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion scripts/verify-sign.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $env:TP_TOOLS_DIR = Join-Path $env:TP_ROOT_DIR "tools"
Write-Verbose "Setup build configuration."
$TPB_SignCertificate = $Certificate
$TPB_Configuration = $Configuration
$TPB_AssembliesPattern = @("*test*.dll", "*qualitytools*.dll", "*test*.exe", "*datacollector*.dll", "*datacollector*.exe", "QTAgent*.exe", "VsWebSite.Interop.dll", "Microsoft.VisualStudio*.dll", "Microsoft.TestPlatform.Build.dll", "Microsoft.DiaSymReader.dll", "Microsoft.IntelliTrace*.dll", "concrt140.dll", "msvcp140.dll", "vccorlib140.dll", "vcruntime140.dll", "codecoveragemessages.dll", "covrun32.dll", "msdia140.dll", "covrun64.dll", "IntelliTrace.exe", "ProcessSnapshotCleanup.exe", "TDEnvCleanup.exe", "CodeCoverage.exe", "Microsoft.ShDocVw.dll", "UIAComwrapper.dll", "Interop.UIAutomationClient.dll")
$TPB_AssembliesPattern = @("*test*.dll", "*qualitytools*.dll", "*test*.exe", "*datacollector*.dll", "*datacollector*.exe", "QTAgent*.exe", "VsWebSite.Interop.dll", "Microsoft.VisualStudio*.dll", "Microsoft.TestPlatform.Build.dll", "Microsoft.DiaSymReader.dll", "Microsoft.IntelliTrace*.dll", "concrt140.dll", "msvcp140.dll", "vccorlib140.dll", "vcruntime140.dll", "codecoveragemessages.dll", "covrun32.dll", "msdia140.dll", "covrun64.dll", "IntelliTrace.exe", "ProcessSnapshotCleanup.exe", "TDEnvCleanup.exe", "CodeCoverage.exe", "Microsoft.ShDocVw.dll", "UIAComwrapper.dll", "Interop.UIAutomationClient.dll", "SettingsMigrator.exe")

function Verify-Assemblies
{
Expand Down
19 changes: 15 additions & 4 deletions src/Microsoft.TestPlatform.Common/Filtering/FilterHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ namespace Microsoft.VisualStudio.TestPlatform.Common.Filtering
public static class FilterHelpers
{
private const char EscapePrefix = '%';
private static readonly Dictionary<char, char> LookUpMap =
new Dictionary<char, char>()
private static readonly Dictionary<char, char> LookUpMap;
private static readonly Dictionary<char, char> ReverseLookUpMap;
private static readonly char[] SpecialCharacters;

static FilterHelpers()
{
LookUpMap = new Dictionary<char, char>()
{
{ '%', '0'},
{ '(', '1'},
Expand All @@ -26,8 +31,14 @@ public static class FilterHelpers
{ '~', '7'},
};

private static readonly Dictionary<char, char> ReverseLookUpMap = LookUpMap.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
private static readonly char[] SpecialCharacters = LookUpMap.Keys.ToArray();
ReverseLookUpMap = new Dictionary<char, char>();
foreach (var kvp in LookUpMap)
{
ReverseLookUpMap[kvp.Value] = kvp.Key;
}

SpecialCharacters = LookUpMap.Keys.ToArray();
}

/// <summary>
/// Escapes a set of special characters for filter (%, (, ), &, |, =, !, ~) by replacing them with their escape sequences.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public static class TelemetryDataConstants

public static string TestSettingsUsed = "VS.TestRun.IsTestSettingsUsed";

public static string LegacySettingElements = "VS.TestRun.LegacySettingsElements";
// All data related to legacy settings nodes will be prefixed with this.
public static string LegacySettingPrefix = "VS.TestRun.LegacySettings";

public static string DataCollectorsEnabled = "VS.TestRun.DataCollectorsEnabled";

Expand Down
57 changes: 54 additions & 3 deletions src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class InferRunSettingsHelper
private const string CodeCoverageFriendlyName = "Code Coverage";
private const string FakesFriendlyName = "UnitTestIsolation";

private const string LegacyElementsString = "Elements";
private const string DeploymentAttributesString = "DeploymentAttributes";
private const string ExecutionAttributesString = "ExecutionAttributes";
private static readonly List<string> ExecutionNodesPaths = new List<string> { @"/RunSettings/LegacySettings/Execution/TestTypeSpecific/UnitTestRunConfig/AssemblyResolution", @"/RunSettings/LegacySettings/Execution/Timeouts", @"/RunSettings/LegacySettings/Execution/Hosts" };

/// <summary>
/// Make runsettings compatible with testhost of version 15.0.0-preview
/// Due to bug https://github.com/Microsoft/vstest/issues/970 we need this function
Expand Down Expand Up @@ -289,11 +294,11 @@ public static bool AreRunSettingsCollectorsInCompatibleWithTestSettings(string r
/// Returns true if legacy settings node is present in runsettings
/// </summary>
/// <param name="runsettingsXml">The run settings xml string</param>
/// <param name="legacySettingElements">The list of elements inside legacy settings</param>
/// <param name="legacySettingsTelemetry">The telemetry data that needs to be captured</param>
/// <returns></returns>
public static bool TryGetLegacySettingElements(string runsettingsXml, out List<string> legacySettingElements)
public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictionary<string, string> legacySettingsTelemetry)
{
legacySettingElements = new List<string>();
legacySettingsTelemetry = new Dictionary<string, string>();
try
{
using (var stream = new StringReader(runsettingsXml))
Expand All @@ -311,10 +316,39 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out List<s

var childNodes = node.SelectChildren(XPathNodeType.Element);

var legacySettingElements = new List<string>();
while (childNodes.MoveNext())
{
legacySettingElements.Add(childNodes.Current.Name);
}

foreach (var executionNodePath in ExecutionNodesPaths)
{
var executionNode = runSettingsNavigator.SelectSingleNode(executionNodePath);
if (executionNode != null)
{
legacySettingElements.Add(executionNode.Name);
}
}

if(legacySettingElements.Count > 0)
{
legacySettingsTelemetry.Add(LegacyElementsString, string.Join(", ", legacySettingElements));
}

var deploymentNode = runSettingsNavigator.SelectSingleNode(@"/RunSettings/LegacySettings/Deployment");
var deploymentAttributes = GetNodeAttributes(deploymentNode);
if (deploymentAttributes != null)
{
legacySettingsTelemetry.Add(DeploymentAttributesString, string.Join(", ", deploymentAttributes));
}

var executiontNode = runSettingsNavigator.SelectSingleNode(@"/RunSettings/LegacySettings/Execution");
var executiontAttributes = GetNodeAttributes(executiontNode);
if (executiontAttributes != null)
{
legacySettingsTelemetry.Add(ExecutionAttributesString, string.Join(", ", executiontAttributes));
}
}
}
catch(Exception ex)
Expand All @@ -326,6 +360,23 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out List<s
return true;
}

private static List<string> GetNodeAttributes(XPathNavigator node)
{
if (node != null && node.HasAttributes)
{
var attributes = new List<string>();
node.MoveToFirstAttribute();
attributes.Add(node.Name);
while (node.MoveToNextAttribute())
{
attributes.Add(node.Name);
}
return attributes;
}

return null;
}

/// <summary>
/// Updates the <c>RunConfiguration.TargetPlatform</c> value for a run settings. if the value is already set, behavior depends on overwrite.
/// </summary>
Expand Down
28 changes: 22 additions & 6 deletions src/SettingsMigrator/Migrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Migrator

private const string ParallelTestCountAttributeName = "parallelTestCount";

private const string HostProcessPlatformAttributeName = "hostProcessPlatform";

private const string RunTimeoutAttributeName = "runTimeout";

private const string LegacySettingsNodeName = "LegacySettings";
Expand Down Expand Up @@ -65,11 +67,11 @@ public void Migrate(string oldFilePath, string newFilePath)
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ValidUsage));
}

if (string.Equals(Path.GetExtension(oldFilePath), TestSettingsExtension))
if (string.Equals(Path.GetExtension(oldFilePath), TestSettingsExtension, StringComparison.OrdinalIgnoreCase))
{
this.MigrateTestSettings(oldFilePath, newFilePath);
}
else if (string.Equals(Path.GetExtension(oldFilePath), RunSettingsExtension))
else if (string.Equals(Path.GetExtension(oldFilePath), RunSettingsExtension, StringComparison.OrdinalIgnoreCase))
{
this.MigrateRunSettings(oldFilePath, newFilePath);
}
Expand Down Expand Up @@ -168,14 +170,20 @@ private void MigrateTestSettingsNodesToRunSettings(string testSettingsPath, XmlD
parallelTestCount = testSettingsNodes.Execution.Attributes[ParallelTestCountAttributeName].Value;
}

string hostProcessPlatform = null;
if (testSettingsNodes.Execution != null && testSettingsNodes.Execution.Attributes[HostProcessPlatformAttributeName] != null)
{
hostProcessPlatform = testSettingsNodes.Execution.Attributes[HostProcessPlatformAttributeName].Value;
}

// WebTestRunConfiguration node.
if (testSettingsNodes.WebSettings != null)
{
runSettingsXmlDoc.DocumentElement.AppendChild(runSettingsXmlDoc.ImportNode(testSettingsNodes.WebSettings, deep: true));
}

// LegacySettings node.
this.AddLegacyNodes(testSettingsNodes, testTimeout, parallelTestCount, runSettingsXmlDoc);
this.AddLegacyNodes(testSettingsNodes, testTimeout, parallelTestCount, hostProcessPlatform, runSettingsXmlDoc);

// TestSessionTimeout node.
if (!string.IsNullOrEmpty(runTimeout))
Expand Down Expand Up @@ -241,11 +249,12 @@ private void RemoveEmbeddedTestSettings(XmlDocument newXmlDoc)
/// <param name="testSettingsNodes">testSettingsNodes</param>
/// <param name="testTimeout">testTimeout</param>
/// <param name="parallelTestCount">parallelTestCount</param>
/// <param name="hostProcessPlatform">hostProcessPlatform</param>
/// <param name="newXmlDoc">newXmlDoc</param>
private void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string testTimeout, string parallelTestCount, XmlDocument newXmlDoc)
private void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string testTimeout, string parallelTestCount, string hostProcessPlatform, XmlDocument newXmlDoc)
{
if (!(testSettingsNodes.Deployment != null || testSettingsNodes.Script != null || testSettingsNodes.UnitTestConfig != null ||
!string.IsNullOrEmpty(parallelTestCount) || !string.IsNullOrEmpty(testTimeout) || testSettingsNodes.Hosts != null))
if (testSettingsNodes.Deployment == null && testSettingsNodes.Script == null && testSettingsNodes.UnitTestConfig == null &&
string.IsNullOrEmpty(parallelTestCount) && string.IsNullOrEmpty(testTimeout) && string.IsNullOrEmpty(hostProcessPlatform) && testSettingsNodes.Hosts == null)
{
return;
}
Expand Down Expand Up @@ -302,6 +311,13 @@ private void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string testTime
newExecutionNode.Attributes.Append(paralellAttribute);
}

if (!string.IsNullOrEmpty(hostProcessPlatform))
{
var hostProcessPlatformAttribute = newXmlDoc.CreateAttribute(HostProcessPlatformAttributeName);
hostProcessPlatformAttribute.Value = hostProcessPlatform;
newExecutionNode.Attributes.Append(hostProcessPlatformAttribute);
}

if (!string.IsNullOrEmpty(testTimeout))
{
var newTimeoutsNode = newXmlDoc.CreateNode(XmlNodeType.Element, TimeoutsNodeName, null);
Expand Down
48 changes: 48 additions & 0 deletions src/SettingsMigrator/PathResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.SettingsMigrator
{
using System;
using System.Globalization;
using System.IO;

/// <summary>
/// Used to resolve the inputs provided by the user to paths needed by migrator.
/// </summary>
public class PathResolver
{
private const string RunSettingsExtension = ".runsettings";

/// <summary>
/// Gets the target path based on user inputs.
/// </summary>
/// <param name="args">User inputs</param>
/// <returns>New file path to create</returns>
public string GetTargetPath(string[] args)
{
string newFilePath = null;
if (args.Length < 1 || !Path.IsPathRooted(args[0]))
{
return newFilePath;
}

if (args.Length == 1)
{
var oldFilePath = args[0];
var newFileName = string.Concat(Path.GetFileNameWithoutExtension(oldFilePath), "_", DateTime.Now.ToString("MM-dd-yyyy_hh-mm-ss"), RunSettingsExtension);
newFilePath = Path.Combine(Path.GetDirectoryName(oldFilePath), newFileName);
}
else if (args.Length == 2)
{
newFilePath = args[1];
if (!Path.IsPathRooted(newFilePath) || !string.Equals(Path.GetExtension(newFilePath), RunSettingsExtension, StringComparison.OrdinalIgnoreCase))
{
newFilePath = null;
}
}

return newFilePath;
}
}
}
20 changes: 10 additions & 10 deletions src/SettingsMigrator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ namespace Microsoft.VisualStudio.TestPlatform.SettingsMigrator
/// </summary>
public static class Program
{
private const string RunSettingsExtension = ".runsettings";

/// <summary>
/// Main entry point. Hands off execution to Migrator.
/// </summary>
/// <param name="args">Arguments on the commandline</param>
/// <returns>Exit code</returns>
public static int Main(string[] args)
{
if (args.Length != 1)
var pathResolver = new PathResolver();
string newFilePath = pathResolver.GetTargetPath(args);

if (!string.IsNullOrEmpty(newFilePath))
{
string oldFilePath = args[0];
var migrator = new Migrator();
migrator.Migrate(oldFilePath, newFilePath);
}
else
{
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.ValidUsage));
return 1;
}

string oldFilePath = args[0];
var newFileName = string.Concat(Guid.NewGuid().ToString(), RunSettingsExtension);
string newFilePath = Path.Combine(Path.GetDirectoryName(oldFilePath), newFileName);

var migrator = new Migrator();
migrator.Migrate(oldFilePath, newFilePath);

return 0;
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/SettingsMigrator/Resources/Resources.Designer.cs

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

11 changes: 8 additions & 3 deletions src/SettingsMigrator/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@
<value>The attributes agentNotRespondingTimeout, deploymentTimeout, scriptTimeout of Timeouts node are not supported, so these will not be migrated.</value>
</data>
<data name="ValidUsage" xml:space="preserve">
<value>Valid usage: SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt;
Example: SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings
Example: SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings</value>
<value>Valid usage:
SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt;
SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt; &lt;Full path to runsettings file to be created&gt;
Examples:
SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings
SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings
SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings E:\MyTest\MyNewRunSettings.runsettings
SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings E:\MyTest\MyNewRunSettings.runsettings</value>
</data>
</root>
11 changes: 8 additions & 3 deletions src/SettingsMigrator/Resources/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@
<note></note>
</trans-unit>
<trans-unit id="ValidUsage">
<source>Valid usage: SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt;
Example: SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings
Example: SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings</source>
<source>Valid usage:
SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt;
SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt; &lt;Full path to runsettings file to be created&gt;
Examples:
SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings
SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings
SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings E:\MyTest\MyNewRunSettings.runsettings
SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings E:\MyTest\MyNewRunSettings.runsettings</source>
<target state="new">Valid usage: SettingsMigrator.exe &lt;Full path to testsettings file or runsettings file to be migrated&gt; &lt;Full path to new runsettings file&gt;
Example: SettingsMigrator.exe E:\MyTest\MyTestSettings.testsettings E:\MyTest\MyRunSettings.runsettings
Example: SettingsMigrator.exe E:\MyTest\MyOldRunSettings.runsettings E:\MyTest\MyRunSettings.runsettings</target>
Expand Down
Loading

0 comments on commit 2d032d2

Please sign in to comment.