Skip to content

Commit

Permalink
Fixed broken tests for escaped fqn test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
Haplois committed Feb 9, 2021
1 parent 8396e1d commit 6f17937
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 17 deletions.
10 changes: 5 additions & 5 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ function Invoke-Build
& $dotnetExe build $TPB_Solution --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:TestPlatform.binlog
Write-Log ".. .. Build: Complete."

Write-Log ".. .. Build: Source: $TPB_TestAssets_CILAssets"
Write-Verbose "$dotnetExe build $TPB_TestAssets_CILAssets --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild"
& $dotnetExe build $TPB_TestAssets_CILAssets --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:"$($env:TP_ROOT_DIR)\CILAssets.binlog"
Write-Log ".. .. Build: Complete."

Set-ScriptFailedOnError

Write-Log "Invoke-Build: Complete. {$(Get-ElapsedTime($timer))}"
Expand All @@ -294,11 +299,6 @@ function Invoke-TestAssetsBuild
& $dotnetExe build $TPB_TestAssets_Solution --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:"$($env:TP_ROOT_DIR)\TestAssets.binlog"
Write-Log ".. .. Build: Complete."

Write-Log ".. .. Build: Source: $TPB_TestAssets_CILAssets"
Write-Verbose "$dotnetExe build $TPB_TestAssets_CILAssets --configuration $TPB_Configuration -v:minimal -p:Version=$TPB_Version -p:CIBuild=$TPB_CIBuild"
& $dotnetExe build $TPB_TestAssets_CILAssets --configuration $TPB_Configuration -v:minimal -p:CIBuild=$TPB_CIBuild -p:LocalizedBuild=$TPB_LocalizedBuild -bl:"$($env:TP_ROOT_DIR)\CILAssets.binlog"
Write-Log ".. .. Build: Complete."

Set-ScriptFailedOnError

Write-Log "Invoke-TestAssetsBuild: Complete. {$(Get-ElapsedTime($timer))}"
Expand Down
1 change: 1 addition & 0 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ function Invoke-Test
}
else
{
Write-Log ".. . $testContainerName test container found. ($testOutputPath)"
$testContainers += ,"$testContainerPath"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ public static void GetManagedName(MethodBase method, out string managedTypeName,
method = ((MethodInfo)method).GetGenericMethodDefinition();
}

var methodBuilder = new StringBuilder();
var typeBuilder = new StringBuilder();
var methodBuilder = new StringBuilder();

// Namespace and Type Name (with arity designation)
AppendTypeString(typeBuilder, semanticType, closedType: false);

// Method Name with method arity
AppendMethodString(methodBuilder, method.Name);
var arity = method.GetGenericArguments().Length;
AppendMethodString(methodBuilder, method.Name, arity);
if (arity > 0)
{
methodBuilder.Append('`');
Expand Down Expand Up @@ -268,11 +268,30 @@ private static void AppendTypeString(StringBuilder b, Type type, bool closedType
}
}

private static void AppendMethodString(StringBuilder methodBuilder, string name)
private static void AppendMethodString(StringBuilder methodBuilder, string name, int methodArity)
{
var arityStart = name.LastIndexOf('`');
var arity = 0;
if (arityStart > 0)
{
arityStart++;
var arityString = name.Substring(arityStart, name.Length - arityStart);
if (int.TryParse(arityString, out arity))
{
if (arity == methodArity)
{
name = name.Substring(0, arityStart - 1);
}
}
}

if (IsNormalized(name))
{
methodBuilder.Append(name);
if (arity > 0 && methodArity == arity)
{
methodBuilder.Append($"`{arity}");
}
return;
}

Expand All @@ -293,13 +312,17 @@ private static void AppendMethodString(StringBuilder methodBuilder, string name)
}
}
methodBuilder.Append("'");
if (arity > 0 && methodArity == arity)
{
methodBuilder.Append($"`{arity}");
}
}

private static bool IsNormalized(string s)
{
for (int i = 0; i < s.Length; i++)
{
if (NeedsEscaping(s[i], i))
if (NeedsEscaping(s[i], i) && s[i] != '.')
{
return false;
}
Expand Down Expand Up @@ -334,14 +357,39 @@ private static bool NeedsEscaping(char c, int pos)
return true;
}

private static void AppendNestedTypeName(StringBuilder b, Type type)
private static int AppendNestedTypeName(StringBuilder b, Type type)
{
var outerArity = 0;
if (type.IsNested)
{
AppendNestedTypeName(b, type.DeclaringType);
outerArity = AppendNestedTypeName(b, type.DeclaringType);
b.Append('+');
}
AppendMethodString(b, type.Name);

var typeName = type.Name;
var stars = 0;
if (type.IsPointer)
{
for (int i = typeName.Length - 1; i > 0; i--)
{
if (typeName[i] != '*')
{
stars = typeName.Length - i - 1;
typeName = typeName.Substring(0, i + 1);
break;
}
}
}

var info = type.GetTypeInfo();
var arity = info.IsGenericType == false ? 0
: info.GenericTypeParameters.Length > 0
? info.GenericTypeParameters.Length
: info.GenericTypeArguments.Length;

AppendMethodString(b, typeName, arity - outerArity);
b.Append('*', stars);
return arity;
}

private static void AppendGenericTypeParameters(StringBuilder b, Type type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ public void GenericExplicitInterfaceImplementation1()
containingTypeSymbol: implT,
methodSymbol: implT.FindMethod("TestClasses.IImplementation<T>.ImplMethod0"),
managedTypeName: "TestClasses.Impl`1",
managedMethodName: "TestClasses.IImplementation<T>.ImplMethod0");
managedMethodName: "'TestClasses\\u002eIImplementation\\u003cT\\u003e\\u002eImplMethod0'"); // "TestClasses.IImplementation<T>.ImplMethod0"
}

[TestMethod]
Expand All @@ -464,7 +464,7 @@ public void GenericExplicitInterfaceImplementation2()
containingTypeSymbol: implT,
methodSymbol: implT.FindMethod("TestClasses.IImplementation<T>.ImplMethod1"),
managedTypeName: "TestClasses.Impl`1",
managedMethodName: "TestClasses.IImplementation<T>.ImplMethod1(!0)");
managedMethodName: "'TestClasses\\u002eIImplementation\\u003cT\\u003e\\u002eImplMethod1'(!0)"); // "TestClasses.IImplementation<T>.ImplMethod1(!0)"
}

[TestMethod]
Expand All @@ -477,7 +477,7 @@ public void GenericExplicitInterfaceImplementation3()
containingTypeSymbol: implT,
methodSymbol: implT.FindMethod("TestClasses.IImplementation<T>.ImplMethod2"),
managedTypeName: "TestClasses.Impl`1",
managedMethodName: "TestClasses.IImplementation<T>.ImplMethod2`1(!0,!!0,System.String)");
managedMethodName: "'TestClasses\\u002eIImplementation\\u003cT\\u003e\\u002eImplMethod2'`1(!0,!!0,System.String)"); // "TestClasses.IImplementation<T>.ImplMethod2`1(!0,!!0,System.String)"
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace Microsoft.TestPlatform.AdapterUtilities.ManagedNameUtilities.UnitTests
using System.Reflection;

[TestClass]
[TestCategory("Windows")]
[TestCategory("AcceptanceTests")]
public class SpecialNameTests
{
[TestMethod]
Expand All @@ -17,8 +19,8 @@ public void VerifyThatInvalidIdentifierNamesAreParsed()
var environment = new IntegrationTestEnvironment();
var asset = environment.GetTestAsset("CILProject.dll", "net451");
var assembly = Assembly.LoadFrom(asset);

var types = assembly.GetTypes();

foreach (var type in types)
{
var methods = type.GetMethods();
Expand Down
2 changes: 1 addition & 1 deletion test/TestAssets/CILProject/CILProject.proj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PropertyGroup>
<TargetFramework>net451</TargetFramework>
<OutputPath>bin\$(Configuration)</OutputPath>
<RunningOnUnix Condition="'$(OS)'!='Windows_NT'">true</RunningOnUnix>
<RunningOnUnix Condition="$([MSBuild]::IsOSUnixLike())">true</RunningOnUnix>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>

Expand Down

0 comments on commit 6f17937

Please sign in to comment.