-
Notifications
You must be signed in to change notification settings - Fork 1k
/
GivenACompilationOptionsConverter.cs
109 lines (102 loc) · 4.53 KB
/
GivenACompilationOptionsConverter.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Reflection;
using FluentAssertions;
using Microsoft.Build.Framework;
using Microsoft.Extensions.DependencyModel;
using Xunit;
namespace Microsoft.NET.Build.Tasks.UnitTests
{
public class GivenACompilationOptionsConverter
{
private static MethodInfo s_convertFromMethod = typeof(GenerateDepsFile)
.GetTypeInfo()
.Assembly
.GetType("Microsoft.NET.Build.Tasks.CompilationOptionsConverter")
.GetMethod("ConvertFrom");
[Theory]
[MemberData(nameof(CompilerOptionsData))]
public void ItConvertsFromITaskItemsCorrectly(ITaskItem taskItem, CompilationOptions expectedOptions)
{
CompilationOptions resultOptions = (CompilationOptions)s_convertFromMethod.Invoke(null, new object[] {taskItem});
resultOptions.Should().BeEquivalentTo(expectedOptions);
}
public static IEnumerable<object[]> CompilerOptionsData
{
get
{
yield return new object[] {
new MockTaskItem(
itemSpec: "CompilerOptions",
metadata: new Dictionary<string, string>
{
{ "DefineConstants", "RELEASE;NETCOREAPP1_0" },
{ "LangVersion", "6" },
{ "PlatformTarget", "x64" },
{ "AllowUnsafeBlocks", "true" },
{ "TreatWarningsAsErrors", "false" },
//{ "Optimize", "" }, Explicitly not setting Optimize
{ "AssemblyOriginatorKeyFile", "../keyfile.snk" },
{ "DelaySign", "" },
{ "PublicSign", "notFalseOrTrue" },
{ "DebugType", "portable" },
{ "OutputType", "Exe" },
{ "GenerateDocumentationFile", "true" },
}
),
new CompilationOptions(
defines: new[] { "RELEASE", "NETCOREAPP1_0" },
languageVersion: "6",
platform: "x64",
allowUnsafe: true,
warningsAsErrors: false,
optimize: null,
keyFile: "../keyfile.snk",
delaySign: null,
publicSign: null,
debugType: "portable",
emitEntryPoint: true,
generateXmlDocumentation: true)
};
yield return new object[] {
new MockTaskItem(
itemSpec: "CompilerOptions",
metadata: new Dictionary<string, string>
{
{ "DefineConstants", ";NETCOREAPP1_0" },
{ "LangVersion", "6" },
{ "PlatformTarget", "x64" },
{ "AllowUnsafeBlocks", "true" },
{ "TreatWarningsAsErrors", "false" },
//{ "Optimize", "" }, Explicitly not setting Optimize
{ "AssemblyOriginatorKeyFile", "../keyfile.snk" },
{ "DelaySign", "" },
{ "PublicSign", "notFalseOrTrue" },
{ "DebugType", "portable" },
{ "OutputType", "Exe" },
{ "GenerateDocumentationFile", "true" },
}
),
new CompilationOptions(
defines: new[] { "NETCOREAPP1_0" },
languageVersion: "6",
platform: "x64",
allowUnsafe: true,
warningsAsErrors: false,
optimize: null,
keyFile: "../keyfile.snk",
delaySign: null,
publicSign: null,
debugType: "portable",
emitEntryPoint: true,
generateXmlDocumentation: true)
};
yield return new object[]
{
null,
null
};
}
}
}
}