From 75f6151c817268ee236139573e5117859e7925f8 Mon Sep 17 00:00:00 2001 From: Mike Voorhees Date: Mon, 23 Oct 2017 10:24:45 -0400 Subject: Add ability to customize the name of the output assembly in tests --- .../Metadata/SetupCompileAssemblyNameAttribute.cs | 12 ++++++++++++ .../Mono.Linker.Tests.Cases.Expectations.csproj | 1 + linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs | 5 +++++ linker/Tests/TestCasesRunner/TestRunner.cs | 6 ++++-- 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAssemblyNameAttribute.cs diff --git a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAssemblyNameAttribute.cs b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAssemblyNameAttribute.cs new file mode 100644 index 000000000..ceb0842eb --- /dev/null +++ b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupCompileAssemblyNameAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Mono.Linker.Tests.Cases.Expectations.Metadata { + [AttributeUsage (AttributeTargets.Class, AllowMultiple = false)] + public class SetupCompileAssemblyNameAttribute : BaseMetadataAttribute { + public SetupCompileAssemblyNameAttribute (string outputName) + { + if (string.IsNullOrEmpty (outputName)) + throw new ArgumentNullException (nameof (outputName)); + } + } +} \ No newline at end of file diff --git a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj index 5c063734c..a33c18638 100644 --- a/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj +++ b/linker/Tests/Mono.Linker.Tests.Cases.Expectations/Mono.Linker.Tests.Cases.Expectations.csproj @@ -52,6 +52,7 @@ + diff --git a/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs b/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs index fbd5f0fe3..f26ad15f2 100644 --- a/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs +++ b/linker/Tests/TestCasesRunner/TestCaseMetadaProvider.cs @@ -101,6 +101,11 @@ namespace Mono.Linker.Tests.TestCasesRunner { .Select (attr => (string) attr.ConstructorArguments.First ().Value); } + public virtual string GetAssemblyName () + { + return GetOptionAttributeValue (nameof (SetupCompileAssemblyNameAttribute), "test.exe"); + } + T GetOptionAttributeValue (string attributeName, T defaultValue) { var attribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == attributeName); diff --git a/linker/Tests/TestCasesRunner/TestRunner.cs b/linker/Tests/TestCasesRunner/TestRunner.cs index b9255435a..141241f93 100644 --- a/linker/Tests/TestCasesRunner/TestRunner.cs +++ b/linker/Tests/TestCasesRunner/TestRunner.cs @@ -40,11 +40,13 @@ namespace Mono.Linker.Tests.TestCasesRunner { var compiler = _factory.CreateCompiler (sandbox, metadataProvider); var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray(); + var assemblyName = metadataProvider.GetAssemblyName (); + var references = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory); - var inputAssemblyPath = compiler.CompileTestIn (sandbox.InputDirectory, "test.exe", sourceFiles, references, null); + var inputAssemblyPath = compiler.CompileTestIn (sandbox.InputDirectory, assemblyName, sourceFiles, references, null); references = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory); - var expectationsAssemblyPath = compiler.CompileTestIn (sandbox.ExpectationsDirectory, "test.exe", sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }); + var expectationsAssemblyPath = compiler.CompileTestIn (sandbox.ExpectationsDirectory, assemblyName, sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }); return new ManagedCompilationResult (inputAssemblyPath, expectationsAssemblyPath); } /* -- cgit v1.2.3