Skip to content

Commit

Permalink
Test fixes for casing (#42879)
Browse files Browse the repository at this point in the history
Fixed #42334
  • Loading branch information
LakshanF authored Sep 30, 2020
1 parent 05c1c58 commit 957fdb9
Showing 1 changed file with 66 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ public void ComponentWithNoDependenciesAndNoDeps()
[Fact]
public void ComponentWithNoDependenciesCaseChangedOnAsm()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Remove once https://github.com/dotnet/runtime/issues/42334 is resolved
return;
}
// Scenario: change the case of the first letter of component.AppDll file name

// Changing the casing of the first letter of a dependent assembly have different behavior in the 3 platforms
// Wisely the product code stays out of casing on dependent assemblies choosing the 1st assembly
// Linux: we fail
// Windows and Mac, probing succeeds but
// Windows: probing returns the original name
// Mac: probing return the new name including 2 assembly probing with the same new name and the changed deps file

var component = sharedTestState.ComponentWithNoDependencies.Copy();

Expand All @@ -65,6 +68,8 @@ public void ComponentWithNoDependenciesCaseChangedOnAsm()
string nameWOExtension = Path.GetFileNameWithoutExtension(fileName);
string nameWOExtensionCaseChanged = (Char.IsUpper(nameWOExtension[0]) ? nameWOExtension[0].ToString().ToLower() : nameWOExtension[0].ToString().ToUpper()) + nameWOExtension.Substring(1);
string changeFile = Path.Combine(Path.GetDirectoryName(fileName), (nameWOExtensionCaseChanged + Path.GetExtension(fileName)));
// on mac, hostpolicy returns the changed name for deps file as well
string changeDepsFile = Path.Combine(Path.GetDirectoryName(component.DepsJson), (nameWOExtensionCaseChanged + ".deps" + Path.GetExtension(component.DepsJson)));

// Rename
File.Move(fileName, changeFile);
Expand All @@ -79,24 +84,38 @@ public void ComponentWithNoDependenciesCaseChangedOnAsm()
.And.HaveStdErrContaining($"deps='{component.DepsJson}'")
.And.HaveStdErrContaining($"mgd_app='{component.AppDll}'");
}
else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
sharedTestState.RunComponentResolutionTest(component)
.Should().Pass()
.And.HaveStdOutContaining("corehost_resolve_component_dependencies:Success")
.And.HaveStdOutContaining($"corehost_resolve_component_dependencies assemblies:[{changeFile}{Path.PathSeparator}{changeFile}{Path.PathSeparator}]")
.And.HaveStdErrContaining($"app_root='{component.Location}{Path.DirectorySeparatorChar}'")
.And.HaveStdErrContaining($"deps='{changeDepsFile}'")
.And.HaveStdErrContaining($"mgd_app='{changeFile}'");
}
else
{
// See https://github.com/dotnet/runtime/issues/42334
// OSPlatform.Linux
// We expect the test to fail due to the the case change of AppDll
sharedTestState.RunComponentResolutionTest(component)
.Should().Pass()
.Should().Fail()
.And.HaveStdErrContaining($"Failed to locate managed application [{component.AppDll}]");
}
}

[Fact]
public void ComponentWithNoDependenciesCaseChangedOnDepsAndAsm()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Remove once https://github.com/dotnet/runtime/issues/42334 is resolved
return;
}

// Scenario: change the case of the first letter of component.AppDll and component.DepsJson file names

// Changing the casing of the first letter of a dependent assembly have different behavior in the 3 platforms
// Wisely the product code stays out of casing on dependent assemblies choosing the 1st assembly
// Linux: we fail
// Windows and Mac, probing succeeds but
// Windows: probing returns the original name
// Mac: probing return the new name including 2 assembly probing with the same new name and the changed deps file

var component = sharedTestState.ComponentWithNoDependencies.Copy();

Expand All @@ -122,24 +141,38 @@ public void ComponentWithNoDependenciesCaseChangedOnDepsAndAsm()
.And.HaveStdErrContaining($"deps='{component.DepsJson}'")
.And.HaveStdErrContaining($"mgd_app='{component.AppDll}'");
}
else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
sharedTestState.RunComponentResolutionTest(component)
.Should().Pass()
.And.HaveStdOutContaining("corehost_resolve_component_dependencies:Success")
.And.HaveStdOutContaining($"corehost_resolve_component_dependencies assemblies:[{changeFile}{Path.PathSeparator}{changeFile}{Path.PathSeparator}]")
.And.HaveStdErrContaining($"app_root='{component.Location}{Path.DirectorySeparatorChar}'")
.And.HaveStdErrContaining($"deps='{changeDepsFile}'")
.And.HaveStdErrContaining($"mgd_app='{changeFile}'");
}
else
{
// See https://github.com/dotnet/runtime/issues/42334
// OSPlatform.Linux
// We expect the test to fail due to the the case change of AppDll
sharedTestState.RunComponentResolutionTest(component)
.Should().Pass()
.Should().Fail()
.And.HaveStdErrContaining($"Failed to locate managed application [{component.AppDll}]");
}
}

[Fact]
public void ComponentWithNoDependenciesNoDepsCaseChangedOnAsm()
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Remove once https://github.com/dotnet/runtime/issues/42334 is resolved
return;
}

// Scenario: change the case of the first letter of component.AppDll file name and delete component.DepsJson file

// Changing the casing of the first letter of a dependent assembly have different behavior in the 3 platforms
// Wisely the product code stays out of casing on dependent assemblies choosing the 1st assembly
// Linux: we fail
// Windows and Mac, probing succeeds but
// Windows: probing returns the original name
// Mac: probing return the new name including assembly probing with the new name and the changed deps file

var component = sharedTestState.ComponentWithNoDependencies.Copy();

Expand All @@ -148,6 +181,8 @@ public void ComponentWithNoDependenciesNoDepsCaseChangedOnAsm()
string nameWOExtension = Path.GetFileNameWithoutExtension(fileName);
string nameWOExtensionCaseChanged = (Char.IsUpper(nameWOExtension[0]) ? nameWOExtension[0].ToString().ToLower() : nameWOExtension[0].ToString().ToUpper()) + nameWOExtension.Substring(1);
string changeFile = Path.Combine(Path.GetDirectoryName(fileName), (nameWOExtensionCaseChanged + Path.GetExtension(fileName)));
// on mac, hostpolicy returns the changed name for deps file as well
string changeDepsFile = Path.Combine(Path.GetDirectoryName(component.DepsJson), (nameWOExtensionCaseChanged + ".deps" + Path.GetExtension(component.DepsJson)));

// Rename
File.Move(fileName, changeFile);
Expand All @@ -164,12 +199,22 @@ public void ComponentWithNoDependenciesNoDepsCaseChangedOnAsm()
.And.HaveStdErrContaining($"deps='{component.DepsJson}'")
.And.HaveStdErrContaining($"mgd_app='{component.AppDll}'");
}
else if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
sharedTestState.RunComponentResolutionTest(component)
.Should().Pass()
.And.HaveStdOutContaining("corehost_resolve_component_dependencies:Success")
.And.HaveStdOutContaining($"corehost_resolve_component_dependencies assemblies:[{changeFile}{Path.PathSeparator}]")
.And.HaveStdErrContaining($"app_root='{component.Location}{Path.DirectorySeparatorChar}'")
.And.HaveStdErrContaining($"deps='{changeDepsFile}'")
.And.HaveStdErrContaining($"mgd_app='{changeFile}'");
}
else
{
// See https://github.com/dotnet/runtime/issues/42334
// OSPlatform.Linux
// We expect the test to fail due to the the case change of AppDll
sharedTestState.RunComponentResolutionTest(component)
.Should().Pass()
.Should().Fail()
.And.HaveStdErrContaining($"Failed to locate managed application [{component.AppDll}]");
}
}
Expand Down

0 comments on commit 957fdb9

Please sign in to comment.