blob: 7eb29f4b7c8a51d3764d845bb65b4e915dc6a381 (
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
|
using System;
using System.Collections.Generic;
using Mono.Linker.Tests.Cases.Expectations.Assertions;
using Mono.Linker.Tests.Extensions;
using Mono.Linker.Tests.TestCases;
namespace Mono.Linker.Tests.TestCasesRunner {
public class TestCaseSandbox {
protected readonly TestCase _testCase;
protected readonly NPath _directory;
public TestCaseSandbox (TestCase testCase)
: this (testCase, NPath.SystemTemp)
{
}
public TestCaseSandbox (TestCase testCase, NPath rootTemporaryDirectory)
: this (testCase, rootTemporaryDirectory, string.Empty)
{
}
public TestCaseSandbox (TestCase testCase, string rootTemporaryDirectory, string namePrefix)
: this (testCase, rootTemporaryDirectory.ToNPath (), namePrefix)
{
}
public TestCaseSandbox (TestCase testCase, NPath rootTemporaryDirectory, string namePrefix)
{
_testCase = testCase;
var name = string.IsNullOrEmpty (namePrefix) ? "linker_tests" : $"{namePrefix}_linker_tests";
_directory = rootTemporaryDirectory.Combine (name);
_directory.DeleteContents ();
InputDirectory = _directory.Combine ("input").EnsureDirectoryExists ();
OutputDirectory = _directory.Combine ("output").EnsureDirectoryExists ();
ExpectationsDirectory = _directory.Combine ("expectations").EnsureDirectoryExists ();
}
public NPath InputDirectory { get; }
public NPath OutputDirectory { get; }
public NPath ExpectationsDirectory { get; }
public IEnumerable<NPath> SourceFiles {
get { return _directory.Files ("*.cs"); }
}
public IEnumerable<NPath> InputDirectoryReferences {
get { return InputDirectory.Files ("*.dll"); }
}
public IEnumerable<NPath> ExpectationsDirectoryReferences {
get { return ExpectationsDirectory.Files ("*.dll"); }
}
public IEnumerable<NPath> LinkXmlFiles {
get { return InputDirectory.Files ("*.xml"); }
}
public virtual void Populate (TestCaseMetadaProvider metadataProvider)
{
_testCase.SourceFile.Copy (_directory);
if (_testCase.HasLinkXmlFile)
_testCase.LinkXmlFile.Copy (InputDirectory);
GetExpectationsAssemblyPath ().Copy (InputDirectory);
foreach (var dep in metadataProvider.AdditionalFilesToSandbox ()) {
dep.FileMustExist ().Copy (_directory);
}
InputDirectoryReferences.Copy (ExpectationsDirectory);
}
private static NPath GetExpectationsAssemblyPath ()
{
return new Uri (typeof (KeptAttribute).Assembly.CodeBase).LocalPath.ToNPath ();
}
}
}
|