diff options
Diffstat (limited to 'linker/Tests/TestCasesRunner')
-rw-r--r-- | linker/Tests/TestCasesRunner/LinkerArgumentBuilder.cs | 21 | ||||
-rw-r--r-- | linker/Tests/TestCasesRunner/ResultChecker.cs | 21 | ||||
-rw-r--r-- | linker/Tests/TestCasesRunner/TestCaseLinkerOptions.cs | 8 | ||||
-rw-r--r-- | linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs | 15 | ||||
-rw-r--r-- | linker/Tests/TestCasesRunner/TestRunner.cs | 9 |
5 files changed, 59 insertions, 15 deletions
diff --git a/linker/Tests/TestCasesRunner/LinkerArgumentBuilder.cs b/linker/Tests/TestCasesRunner/LinkerArgumentBuilder.cs index ce86808c7..3b095f5c3 100644 --- a/linker/Tests/TestCasesRunner/LinkerArgumentBuilder.cs +++ b/linker/Tests/TestCasesRunner/LinkerArgumentBuilder.cs @@ -29,6 +29,12 @@ namespace Mono.Linker.Tests.TestCasesRunner { Append (value); } + public virtual void LinkFromAssembly (string fileName) + { + Append ("-a"); + Append (fileName); + } + public virtual void IncludeBlacklist (bool value) { Append ("-z"); @@ -47,6 +53,13 @@ namespace Mono.Linker.Tests.TestCasesRunner { Append ("-t"); } + public virtual void AddAssemblyAction (string action, string assembly) + { + Append ("-p"); + Append (action); + Append (assembly); + } + public string [] ToArgs () { return _arguments.ToArray (); @@ -59,7 +72,13 @@ namespace Mono.Linker.Tests.TestCasesRunner { public virtual void ProcessOptions (TestCaseLinkerOptions options) { - AddCoreLink (options.CoreLink); + if (options.CoreAssembliesAction != null) + AddCoreLink (options.CoreAssembliesAction); + + if (options.AssembliesAction != null) { + foreach (var entry in options.AssembliesAction) + AddAssemblyAction (entry.Key, entry.Value); + } // Running the blacklist step causes a ton of stuff to be preserved. That's good for normal use cases, but for // our test cases that pollutes the results diff --git a/linker/Tests/TestCasesRunner/ResultChecker.cs b/linker/Tests/TestCasesRunner/ResultChecker.cs index fcc175346..1deef5870 100644 --- a/linker/Tests/TestCasesRunner/ResultChecker.cs +++ b/linker/Tests/TestCasesRunner/ResultChecker.cs @@ -107,24 +107,35 @@ namespace Mono.Linker.Tests.TestCasesRunner { var expectedTypeName = checkAttrInAssembly.ConstructorArguments [1].Value.ToString (); var linkedType = linkedAssembly.MainModule.GetType (expectedTypeName); - if (checkAttrInAssembly.AttributeType.Name == nameof (RemovedTypeInAssemblyAttribute)) { + switch (checkAttrInAssembly.AttributeType.Name) { + case nameof (RemovedTypeInAssemblyAttribute): if (linkedType != null) Assert.Fail ($"Type `{expectedTypeName}' should have been removed"); - } else if (checkAttrInAssembly.AttributeType.Name == nameof (KeptTypeInAssemblyAttribute)) { + break; + case nameof (KeptTypeInAssemblyAttribute): if (linkedType == null) Assert.Fail ($"Type `{expectedTypeName}' should have been kept"); - } else if (checkAttrInAssembly.AttributeType.Name == nameof (RemovedMemberInAssemblyAttribute)) { + break; + case nameof (RemovedMemberInAssemblyAttribute): if (linkedType == null) continue; VerifyRemovedMemberInAssembly (checkAttrInAssembly, linkedType); - } else if (checkAttrInAssembly.AttributeType.Name == nameof (KeptMemberInAssemblyAttribute)) { + break; + case nameof (KeptMemberInAssemblyAttribute): if (linkedType == null) Assert.Fail ($"Type `{expectedTypeName}' should have been kept"); VerifyKeptMemberInAssembly (checkAttrInAssembly, linkedType); - } else { + break; + case nameof (RemovedForwarderAttribute): + if (linkedAssembly.MainModule.ExportedTypes.Any (l => l.Name == expectedTypeName)) + Assert.Fail ($"Forwarder `{expectedTypeName}' should have been removed"); + + break; + default: UnhandledOtherAssemblyAssertion (expectedTypeName, checkAttrInAssembly, linkedType); + break; } } } diff --git a/linker/Tests/TestCasesRunner/TestCaseLinkerOptions.cs b/linker/Tests/TestCasesRunner/TestCaseLinkerOptions.cs index 4fdb8dee2..f47a4e0c4 100644 --- a/linker/Tests/TestCasesRunner/TestCaseLinkerOptions.cs +++ b/linker/Tests/TestCasesRunner/TestCaseLinkerOptions.cs @@ -1,7 +1,11 @@ -namespace Mono.Linker.Tests.TestCasesRunner { +using System.Collections.Generic; + +namespace Mono.Linker.Tests.TestCasesRunner { public class TestCaseLinkerOptions { - public string CoreLink; + public string CoreAssembliesAction; + public List<KeyValuePair<string, string>> AssembliesAction = new List<KeyValuePair<string, string>> (); + public string Il8n; public bool IncludeBlacklistStep; public string KeepTypeForwarderOnlyAssemblies; diff --git a/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs b/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs index 46b981793..fbd5f0fe3 100644 --- a/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs +++ b/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs @@ -26,13 +26,20 @@ namespace Mono.Linker.Tests.TestCasesRunner { public virtual TestCaseLinkerOptions GetLinkerOptions () { - return new TestCaseLinkerOptions - { - CoreLink = GetOptionAttributeValue (nameof (CoreLinkAttribute), "skip"), + var tclo = new TestCaseLinkerOptions { Il8n = GetOptionAttributeValue (nameof (Il8nAttribute), string.Empty), IncludeBlacklistStep = GetOptionAttributeValue (nameof (IncludeBlacklistStepAttribute), false), - KeepTypeForwarderOnlyAssemblies = GetOptionAttributeValue (nameof (KeepTypeForwarderOnlyAssembliesAttribute), string.Empty) + KeepTypeForwarderOnlyAssemblies = GetOptionAttributeValue (nameof (KeepTypeForwarderOnlyAssembliesAttribute), string.Empty), + CoreAssembliesAction = GetOptionAttributeValue<string> (nameof (SetupLinkerCoreActionAttribute), null) }; + + foreach (var assemblyAction in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (SetupLinkerActionAttribute))) + { + var ca = assemblyAction.ConstructorArguments; + tclo.AssembliesAction.Add (new KeyValuePair<string, string> ((string)ca [0].Value, (string)ca [1].Value)); + } + + return tclo; } public virtual IEnumerable<string> GetReferencedAssemblies (NPath workingDirectory) diff --git a/linker/Tests/TestCasesRunner/TestRunner.cs b/linker/Tests/TestCasesRunner/TestRunner.cs index 9693eeaf7..b9255435a 100644 --- a/linker/Tests/TestCasesRunner/TestRunner.cs +++ b/linker/Tests/TestCasesRunner/TestRunner.cs @@ -23,7 +23,7 @@ namespace Mono.Linker.Tests.TestCasesRunner { var sandbox = Sandbox (testCase, metadataProvider); var compilationResult = Compile (sandbox, metadataProvider); - PrepForLink (sandbox, compilationResult); +// PrepForLink (sandbox, compilationResult); return Link (testCase, sandbox, compilationResult, metadataProvider); } } @@ -47,13 +47,13 @@ namespace Mono.Linker.Tests.TestCasesRunner { var expectationsAssemblyPath = compiler.CompileTestIn (sandbox.ExpectationsDirectory, "test.exe", sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }); return new ManagedCompilationResult (inputAssemblyPath, expectationsAssemblyPath); } - +/* private void PrepForLink (TestCaseSandbox sandbox, ManagedCompilationResult compilationResult) { var entryPointLinkXml = sandbox.InputDirectory.Combine ("entrypoint.xml"); LinkXmlHelpers.WriteXmlFileToPreserveEntryPoint (compilationResult.InputAssemblyPath, entryPointLinkXml); } - +*/ private LinkedTestCaseResult Link (TestCase testCase, TestCaseSandbox sandbox, ManagedCompilationResult compilationResult, TestCaseMetadaProvider metadataProvider) { var linker = _factory.CreateLinker (); @@ -72,6 +72,9 @@ namespace Mono.Linker.Tests.TestCasesRunner { AddAdditionalLinkOptions (builder, metadataProvider); + // TODO: Should be overridable + builder.LinkFromAssembly (compilationResult.InputAssemblyPath.ToString ()); + linker.Link (builder.ToArgs ()); return new LinkedTestCaseResult (testCase, compilationResult.InputAssemblyPath, sandbox.OutputDirectory.Combine (compilationResult.InputAssemblyPath.FileName), compilationResult.ExpectationsAssemblyPath); |