diff options
author | Mike Voorhees <michaelv@unity3d.com> | 2017-05-31 00:29:32 +0300 |
---|---|---|
committer | Marek Safar <marek.safar@gmail.com> | 2017-05-31 19:20:57 +0300 |
commit | 65fd2098ffb981b3162da4399ae07b90306c5270 (patch) | |
tree | 35ab2177179e2d24109ccc82e9ec08fbcf39d8fb | |
parent | a52adfbfeac99450ef14b26ad8d649619ba5d84d (diff) |
Test framework extensibility improvements
-rw-r--r-- | linker/Tests/TestCasesRunner/ResultChecker.cs | 31 | ||||
-rw-r--r-- | linker/Tests/TestCasesRunner/TestCaseCompiler.cs | 10 | ||||
-rw-r--r-- | linker/Tests/TestCasesRunner/TestRunner.cs | 4 |
3 files changed, 29 insertions, 16 deletions
diff --git a/linker/Tests/TestCasesRunner/ResultChecker.cs b/linker/Tests/TestCasesRunner/ResultChecker.cs index 542aee410..9abf9dc73 100644 --- a/linker/Tests/TestCasesRunner/ResultChecker.cs +++ b/linker/Tests/TestCasesRunner/ResultChecker.cs @@ -40,6 +40,8 @@ namespace Mono.Linker.Tests.TestCasesRunner { new AssemblyChecker (original, linked).Verify (); VerifyLinkingOfOtherAssemblies (original); + + AdditionalChecking (linkResult, original, linked); } finally { @@ -87,6 +89,10 @@ namespace Mono.Linker.Tests.TestCasesRunner { } } + protected virtual void AdditionalChecking (LinkedTestCaseResult linkResult, AssemblyDefinition original, AssemblyDefinition linked) + { + } + void VerifyLinkingOfOtherAssemblies (AssemblyDefinition original) { var checks = BuildOtherAssemblyCheckTable (original); @@ -114,7 +120,7 @@ namespace Mono.Linker.Tests.TestCasesRunner { VerifyKeptMemberInAssembly (checkAttrInAssembly, linkedType); } else { - throw new NotImplementedException ($"Type {expectedTypeName}, has an unknown other assembly attribute of type {checkAttrInAssembly.AttributeType}"); + UnhandledOtherAssemblyAssertion (expectedTypeName, checkAttrInAssembly, linkedType); } } } @@ -199,17 +205,22 @@ namespace Mono.Linker.Tests.TestCasesRunner { } } - TypeDefinition GetOriginalTypeFromInAssemblyAttribute (CustomAttribute inAssemblyAttribute) + protected TypeDefinition GetOriginalTypeFromInAssemblyAttribute (CustomAttribute inAssemblyAttribute) { var attributeValueAsTypeReference = inAssemblyAttribute.ConstructorArguments [1].Value as TypeReference; if (attributeValueAsTypeReference != null) return attributeValueAsTypeReference.Resolve (); var assembly = ResolveOriginalsAssembly (inAssemblyAttribute.ConstructorArguments [0].Value.ToString ()); - return assembly.MainModule.GetType (inAssemblyAttribute.ConstructorArguments [1].Value.ToString ()); + + var expectedTypeName = inAssemblyAttribute.ConstructorArguments [1].Value.ToString (); + var originalType = assembly.MainModule.GetType (expectedTypeName); + if (originalType == null) + throw new InvalidOperationException ($"Unable to locate the original type `{expectedTypeName}`"); + return originalType; } - static Dictionary<string, List<CustomAttribute>> BuildOtherAssemblyCheckTable (AssemblyDefinition original) + Dictionary<string, List<CustomAttribute>> BuildOtherAssemblyCheckTable (AssemblyDefinition original) { var checks = new Dictionary<string, List<CustomAttribute>> (); @@ -227,12 +238,14 @@ namespace Mono.Linker.Tests.TestCasesRunner { return checks; } - static bool IsTypeInOtherAssemblyAssertion (CustomAttribute attr) + protected virtual void UnhandledOtherAssemblyAssertion (string expectedTypeName, CustomAttribute checkAttrInAssembly, TypeDefinition linkedType) + { + throw new NotImplementedException ($"Type {expectedTypeName}, has an unknown other assembly attribute of type {checkAttrInAssembly.AttributeType}"); + } + + bool IsTypeInOtherAssemblyAssertion (CustomAttribute attr) { - return attr.AttributeType.Name == nameof (RemovedTypeInAssemblyAttribute) - || attr.AttributeType.Name == nameof (KeptTypeInAssemblyAttribute) - || attr.AttributeType.Name == nameof (RemovedMemberInAssemblyAttribute) - || attr.AttributeType.Name == nameof (KeptMemberInAssemblyAttribute); + return attr.AttributeType.Resolve ().DerivesFrom (nameof (BaseInAssemblyAttribute)); } } }
\ No newline at end of file diff --git a/linker/Tests/TestCasesRunner/TestCaseCompiler.cs b/linker/Tests/TestCasesRunner/TestCaseCompiler.cs index ce203b478..cbebd5e06 100644 --- a/linker/Tests/TestCasesRunner/TestCaseCompiler.cs +++ b/linker/Tests/TestCasesRunner/TestCaseCompiler.cs @@ -7,9 +7,9 @@ using Mono.Linker.Tests.Extensions; namespace Mono.Linker.Tests.TestCasesRunner { public class TestCaseCompiler { - public virtual NPath CompileTestIn (NPath outputDirectory, IEnumerable<string> sourceFiles, IEnumerable<string> references, IEnumerable<string> defines) + public virtual NPath CompileTestIn (NPath outputDirectory, string outputName, IEnumerable<string> sourceFiles, IEnumerable<string> references, IEnumerable<string> defines) { - var compilerOptions = CreateCompilerOptions (outputDirectory, references, defines); + var compilerOptions = CreateCompilerOptions (outputDirectory, outputName, references, defines); var provider = CodeDomProvider.CreateProvider ("C#"); var result = provider.CompileAssemblyFromFile (compilerOptions, sourceFiles.ToArray ()); if (!result.Errors.HasErrors) @@ -21,14 +21,14 @@ namespace Mono.Linker.Tests.TestCasesRunner { throw new Exception ("Compilation errors: " + errors); } - protected virtual CompilerParameters CreateCompilerOptions (NPath outputDirectory, IEnumerable<string> references, IEnumerable<string> defines) + protected virtual CompilerParameters CreateCompilerOptions (NPath outputDirectory, string outputName, IEnumerable<string> references, IEnumerable<string> defines) { - var outputPath = outputDirectory.Combine ("test.exe"); + var outputPath = outputDirectory.Combine (outputName); var compilerParameters = new CompilerParameters { OutputAssembly = outputPath.ToString (), - GenerateExecutable = true + GenerateExecutable = outputName.EndsWith(".exe") }; compilerParameters.CompilerOptions = defines?.Aggregate (string.Empty, (buff, arg) => $"{buff} /define:{arg}"); diff --git a/linker/Tests/TestCasesRunner/TestRunner.cs b/linker/Tests/TestCasesRunner/TestRunner.cs index f29774064..24b766c8b 100644 --- a/linker/Tests/TestCasesRunner/TestRunner.cs +++ b/linker/Tests/TestCasesRunner/TestRunner.cs @@ -41,10 +41,10 @@ namespace Mono.Linker.Tests.TestCasesRunner { var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray(); var references = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory); - var inputAssemblyPath = compiler.CompileTestIn (sandbox.InputDirectory, sourceFiles, references, null); + var inputAssemblyPath = compiler.CompileTestIn (sandbox.InputDirectory, "test.exe", sourceFiles, references, null); references = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory); - var expectationsAssemblyPath = compiler.CompileTestIn (sandbox.ExpectationsDirectory, sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }); + var expectationsAssemblyPath = compiler.CompileTestIn (sandbox.ExpectationsDirectory, "test.exe", sourceFiles, references, new [] { "INCLUDE_EXPECTATIONS" }); return new ManagedCompilationResult (inputAssemblyPath, expectationsAssemblyPath); } |