blob: 8055cfccba2590d851d24b7fda4669e99f01b68d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Cases.Expectations.Metadata;
using Mono.Linker.Tests.Extensions;
using Mono.Linker.Tests.TestCases;
namespace Mono.Linker.Tests.TestCasesRunner {
public class TestCaseMetadaProvider {
protected readonly TestCase _testCase;
protected readonly AssemblyDefinition _fullTestCaseAssemblyDefinition;
protected readonly TypeDefinition _testCaseTypeDefinition;
public TestCaseMetadaProvider (TestCase testCase, AssemblyDefinition fullTestCaseAssemblyDefinition)
{
_testCase = testCase;
_fullTestCaseAssemblyDefinition = fullTestCaseAssemblyDefinition;
// The test case types are never nested so we don't need to worry about that
_testCaseTypeDefinition = fullTestCaseAssemblyDefinition.MainModule.GetType (_testCase.ReconstructedFullTypeName);
if (_testCaseTypeDefinition == null)
throw new InvalidOperationException ($"Could not find the type definition for {_testCase.Name} in {_testCase.SourceFile}");
}
public virtual TestCaseLinkerOptions GetLinkerOptions ()
{
return new TestCaseLinkerOptions
{
CoreLink = GetOptionAttributeValue (nameof (CoreLinkAttribute), "skip"),
Il8n = GetOptionAttributeValue (nameof (Il8nAttribute), string.Empty),
IncludeBlacklistStep = GetOptionAttributeValue (nameof (IncludeBlacklistStepAttribute), false),
KeepTypeForwarderOnlyAssemblies = GetOptionAttributeValue (nameof (KeepTypeForwarderOnlyAssembliesAttribute), string.Empty)
};
}
public virtual IEnumerable<string> GetReferencedAssemblies (NPath workingDirectory)
{
yield return workingDirectory.Combine ("Mono.Linker.Tests.Cases.Expectations.dll").ToString ();
yield return "mscorlib.dll";
foreach (var referenceAttr in _testCaseTypeDefinition.CustomAttributes.Where (attr => attr.AttributeType.Name == nameof (ReferenceAttribute))) {
yield return (string) referenceAttr.ConstructorArguments.First ().Value;
}
}
public virtual IEnumerable<NPath> GetExtraLinkerSearchDirectories ()
{
yield break;
}
public bool IsIgnored (out string reason)
{
var ignoreAttribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == nameof (IgnoreTestCaseAttribute));
if (ignoreAttribute != null) {
reason = (string)ignoreAttribute.ConstructorArguments.First ().Value;
return true;
}
reason = null;
return false;
}
public virtual IEnumerable<NPath> AdditionalFilesToSandbox ()
{
foreach (var attr in _testCaseTypeDefinition.CustomAttributes) {
if (attr.AttributeType.Name != nameof (SandboxDependencyAttribute))
continue;
var relativeDepPath = ((string) attr.ConstructorArguments.First ().Value).ToNPath ();
yield return _testCase.SourceFile.Parent.Combine (relativeDepPath);
}
}
T GetOptionAttributeValue<T> (string attributeName, T defaultValue)
{
var attribute = _testCaseTypeDefinition.CustomAttributes.FirstOrDefault (attr => attr.AttributeType.Name == attributeName);
if (attribute != null)
return (T) attribute.ConstructorArguments.First ().Value;
return defaultValue;
}
}
}
|