-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests cover using statement difference between mcs and csc.
Add new [KeptReferencesInAssembly] attribute for asserting the expected references in an assembly
- Loading branch information
Showing
8 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...ests/Mono.Linker.Tests.Cases.Expectations/Assertions/KeptReferencesInAssemblyAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace Mono.Linker.Tests.Cases.Expectations.Assertions { | ||
[AttributeUsage (AttributeTargets.Class, AllowMultiple = true, Inherited = false)] | ||
public class KeptReferencesInAssemblyAttribute : BaseInAssemblyAttribute { | ||
public KeptReferencesInAssemblyAttribute (string assemblyFileName, string [] expectedReferenceAssemblyNames) | ||
{ | ||
if (string.IsNullOrEmpty (assemblyFileName)) | ||
throw new ArgumentNullException (nameof (assemblyFileName)); | ||
|
||
if (expectedReferenceAssemblyNames == null) | ||
throw new ArgumentNullException (nameof (expectedReferenceAssemblyNames)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
linker/Tests/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithCsc.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
using Mono.Linker.Tests.Cases.References.Dependencies; | ||
|
||
namespace Mono.Linker.Tests.Cases.References { | ||
/// <summary> | ||
/// We can't detect the using usage in the assembly. As a result, nothing in `library` is going to be marked and that assembly will be deleted. | ||
/// Because of that, `copied` needs to have it's reference to `library` removed even though we specified an assembly action of `copy` | ||
/// </summary> | ||
[SetupLinkerAction ("copy", "copied")] | ||
[SetupCompileBefore ("library.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Lib.cs"})] | ||
|
||
// When csc is used, `copied.dll` will have a reference to `library.dll` | ||
[SetupCompileBefore ("copied.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Copied.cs"}, new [] {"library.dll"}, compilerToUse: "csc")] | ||
|
||
// Here to assert that the test is setup correctly to copy the copied assembly. This is an important aspect of the bug | ||
[KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_Copied), "Unused()")] | ||
|
||
// We library should be gone. The `using` statement leaves no traces in the IL so nothing in `library` will be marked | ||
[RemovedAssembly ("library.dll")] | ||
[KeptReferencesInAssembly ("copied.dll", new [] {"mscorlib"})] | ||
public class AssemblyOnlyUsedByUsingWithCsc { | ||
public static void Main () | ||
{ | ||
// Use something to keep the reference at compile time | ||
AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference (); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
linker/Tests/Mono.Linker.Tests.Cases/References/AssemblyOnlyUsedByUsingWithMcs.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
using Mono.Linker.Tests.Cases.References.Dependencies; | ||
|
||
namespace Mono.Linker.Tests.Cases.References { | ||
[SetupLinkerAction ("copy", "copied")] | ||
[SetupCompileBefore ("library.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Lib.cs"})] | ||
|
||
// When mcs is used, `copied.dll` will not have a reference to `library.dll` | ||
[SetupCompileBefore ("copied.dll", new [] {"Dependencies/AssemblyOnlyUsedByUsing_Copied.cs"}, new [] {"library.dll"}, compilerToUse: "mcs")] | ||
|
||
// Here to assert that the test is setup correctly to copy the copied assembly. This is an important aspect of the bug | ||
[KeptMemberInAssembly ("copied.dll", typeof (AssemblyOnlyUsedByUsing_Copied), "Unused()")] | ||
|
||
[RemovedAssembly ("library.dll")] | ||
[KeptReferencesInAssembly ("copied.dll", new [] {"mscorlib"})] | ||
public class AssemblyOnlyUsedByUsingWithMcs { | ||
public static void Main () | ||
{ | ||
// Use something to keep the reference at compile time | ||
AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference (); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...r/Tests/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Copied.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
// This is what triggers the behavior difference between Roslyn and mcs. Roslyn will keep the reference | ||
// to this assembly because of this whereas mcs will not | ||
using ImportantForBug = Mono.Linker.Tests.Cases.References.Dependencies.AssemblyOnlyUsedByUsing_Lib; | ||
|
||
namespace Mono.Linker.Tests.Cases.References.Dependencies { | ||
public class AssemblyOnlyUsedByUsing_Copied { | ||
public static void UsedToKeepReference () | ||
{ | ||
} | ||
|
||
private static void Unused () | ||
{ | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
linker/Tests/Mono.Linker.Tests.Cases/References/Dependencies/AssemblyOnlyUsedByUsing_Lib.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace Mono.Linker.Tests.Cases.References.Dependencies { | ||
public class AssemblyOnlyUsedByUsing_Lib { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters