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
86
87
|
using System.Linq;
using Mono.Cecil;
using Mono.Linker.Tests.TestCases;
using NUnit.Framework;
namespace Mono.Linker.Tests.TestCasesRunner {
public class TestRunner {
private readonly ObjectFactory _factory;
public TestRunner (ObjectFactory factory)
{
_factory = factory;
}
public LinkedTestCaseResult Run (TestCase testCase)
{
using (var fullTestCaseAssemblyDefinition = AssemblyDefinition.ReadAssembly (testCase.OriginalTestCaseAssemblyPath.ToString ())) {
var metadataProvider = _factory.CreateMetadataProvider (testCase, fullTestCaseAssemblyDefinition);
string ignoreReason;
if (metadataProvider.IsIgnored (out ignoreReason))
Assert.Ignore (ignoreReason);
var sandbox = Sandbox (testCase, metadataProvider);
var compilationResult = Compile (sandbox, metadataProvider);
// PrepForLink (sandbox, compilationResult);
return Link (testCase, sandbox, compilationResult, metadataProvider);
}
}
private TestCaseSandbox Sandbox (TestCase testCase, TestCaseMetadaProvider metadataProvider)
{
var sandbox = _factory.CreateSandbox (testCase);
sandbox.Populate (metadataProvider);
return sandbox;
}
private ManagedCompilationResult Compile (TestCaseSandbox sandbox, TestCaseMetadaProvider metadataProvider)
{
var compiler = _factory.CreateCompiler (sandbox, metadataProvider);
var sourceFiles = sandbox.SourceFiles.Select(s => s.ToString()).ToArray();
var references = metadataProvider.GetReferencedAssemblies(sandbox.InputDirectory);
var inputAssemblyPath = compiler.CompileTestIn (sandbox.InputDirectory, "test.exe", sourceFiles, references, null);
references = metadataProvider.GetReferencedAssemblies(sandbox.ExpectationsDirectory);
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 ();
var builder = _factory.CreateLinkerArgumentBuilder ();
var caseDefinedOptions = metadataProvider.GetLinkerOptions ();
builder.AddOutputDirectory (sandbox.OutputDirectory);
foreach (var linkXmlFile in sandbox.LinkXmlFiles)
builder.AddLinkXmlFile (linkXmlFile);
builder.AddSearchDirectory (sandbox.InputDirectory);
foreach (var extraSearchDir in metadataProvider.GetExtraLinkerSearchDirectories ())
builder.AddSearchDirectory (extraSearchDir);
builder.ProcessOptions (caseDefinedOptions);
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);
}
protected virtual void AddAdditionalLinkOptions (LinkerArgumentBuilder builder, TestCaseMetadaProvider metadataProvider)
{
}
}
}
|