Skip to content

Commit

Permalink
Add tests to show possible bug handling csc behavior quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvoorhe committed Nov 13, 2018
1 parent 13ea158 commit c524601
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@
<Compile Include="PreserveDependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssembly.cs" />
<Compile Include="PreserveDependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithCopyUsedAction.cs" />
<Compile Include="PreserveDependencies\PreserveDependencyOnUnusedMethodInNonReferencedAssemblyWithEmbeddedXml.cs" />
<Compile Include="References\AssemblyOnlyUsedByUsingWithCsc.cs" />
<Compile Include="References\AssemblyOnlyUsedByUsingWithMcs.cs" />
<Compile Include="References\Dependencies\AssemblyOnlyUsedByUsing_Copied.cs" />
<Compile Include="References\Dependencies\AssemblyOnlyUsedByUsing_Lib.cs" />
<Compile Include="References\Individual\CanSkipUnresolved.cs" />
<Compile Include="References\Individual\Dependencies\CanSkipUnresolved_Library.cs" />
<Compile Include="References\Dependencies\UserAssembliesAreLinkedByDefault_Library1.cs" />
Expand Down
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 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 need to keep library.dll because `copied.dll` references
[KeptAssembly ("library.dll")]
public class AssemblyOnlyUsedByUsingWithCsc {
public static void Main ()
{
// Use something to keep the reference at compile time
AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference ();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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")]
public class AssemblyOnlyUsedByUsingWithMcs {
public static void Main ()
{
// Use something to keep the reference at compile time
AssemblyOnlyUsedByUsing_Copied.UsedToKeepReference ();
}
}
}
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 ()
{
}
}
}
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 {
}
}

0 comments on commit c524601

Please sign in to comment.