Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TestContext.cs « ILLink.Tasks.Tests « test - github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 95e3d72ec15fb2fe397418a37e178b23db3c69f1 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.IO;
using System.Linq;
using Microsoft.DotNet.PlatformAbstractions;

namespace ILLink.Tests
{
	public class TestContext
	{
		/// <summary>
		///   The name of the tasks package to add to the integration
		///   projects.
		/// </summary>
		public string TasksPackageName { get; private set; }

		/// <summary>
		///   The version of the tasks package to add to the
		///   integration projects.
		/// </summary>
		public string TasksPackageVersion { get; private set; }

		/// <summary>
		///   The path of the directory from which to get the linker
		///   package.
		/// </summary>
		public string PackageSource { get; private set; }

		/// <summary>
		///   The path to the dotnet tool to use to run the
		///   integration tests.
		/// </summary>
		public string DotnetToolPath { get; set; }

		/// <summary>
		///   The RID to use when restoring, building, and linking the
		///   integration test projects.
		/// </summary>
		public string RuntimeIdentifier { get; private set; }

		/// <summary>
		///   The configuration to use to build the integration test
		///   projects.
		/// </summary>
		public string Configuration { get; private set; }

		/// <summary>
		///   The root testbin directory. Used to install test
		///   assets that don't depend on the configuration or
		///   target framework.
		/// </summary>
		public string TestBin { get; private set; }

		/// <summary>
		///   This is the context from which tests will be run in the
		///   linker repo. The local directory that contains the
		///   linker integration packages (hard-coded here) is
		///   searched for the tasks package. This assumes that only
		///   one version of the package is present, and uses it to
		///   unambiguously determine which pacakge to use in the tests.
		/// </summary>
		public static TestContext CreateDefaultContext()
		{
			var packageName = "ILLink.Tasks";
			// test working directory is test project's <baseoutputpath>/<config>/<tfm>
			var testBin = "../../";
			var repoRoot = Path.Combine(testBin, "..", "..", "..");
			var packageSource = Path.Combine(repoRoot, "src", "ILLink.Tasks", "bin", "nupkgs");
			var tasksPackages = Directory.GetFiles(packageSource)
				.Where(p => Path.GetExtension(p) == ".nupkg")
				.Select(p => Path.GetFileNameWithoutExtension(p))
				.Where(p => p.StartsWith(packageName));
			var nPackages = tasksPackages.Count();
			if (nPackages > 1) {
				throw new Exception($"duplicate {packageName} packages in {packageSource}");
			} else if (nPackages == 0) {
				throw new Exception($"{packageName} package not found in {packageSource}");
			}
			var tasksPackage = tasksPackages.Single();
			var version = tasksPackage.Remove(0, packageName.Length + 1);
			var dotnetDir = Path.Combine(repoRoot, "corebuild", "Tools", "dotnetcli");
			var dotnetToolNames = Directory.GetFiles(dotnetDir)
				.Select(p => Path.GetFileName(p))
				.Where(p => p.Contains("dotnet"));
			var nTools = dotnetToolNames.Count();
			if (nTools > 1) {
				throw new Exception($"multiple dotnet tools in {dotnetDir}");
			} else if (nTools == 0) {
				throw new Exception($"no dotnet tool found in {dotnetDir}");
			}
			var dotnetToolName = dotnetToolNames.Single();
			var dotnetToolPath = Path.Combine(dotnetDir, dotnetToolName);

			var context = new TestContext();
			context.PackageSource = packageSource;
			context.TasksPackageName = packageName;
			context.TasksPackageVersion = version;
			context.DotnetToolPath = dotnetToolPath;
			// This sets the RID to the RID of the currently-executing system.
			context.RuntimeIdentifier = RuntimeEnvironment.GetRuntimeIdentifier();
			// workaround: the osx.10.13-x64 RID doesn't exist yet.
			// see https://github.com/dotnet/core-setup/issues/3301
			if (context.RuntimeIdentifier == "osx.10.13-x64")
			{
				context.RuntimeIdentifier = "osx.10.12-x64";
			}
			// We want to build and link integration projects in the
			// release configuration.
			context.Configuration = "Release";
			context.TestBin = testBin;
			return context;
		}
	}
}