提交 3b1e9095 编写于 作者: T Tomas Matousek

Remove dependency on mscorlib from portable C# script tests

上级 c257c2df
......@@ -229,7 +229,7 @@ public class TestAnalyzer : DiagnosticAnalyzer
new SyntaxTree[] { CSharp.SyntaxFactory.ParseSyntaxTree(analyzerSource) },
new MetadataReference[]
{
SystemRuntimeNetstandard13FacadeRef.Value,
TestReferences.NetStandard13.SystemRuntime,
MetadataReference.CreateFromFile(immutable.Path),
MetadataReference.CreateFromFile(analyzer.Path)
},
......
......@@ -577,16 +577,16 @@ public void ReferenceSearchPaths1()
");
var dir1 = Temp.CreateDirectory();
dir1.CreateFile("1.dll").WriteAllBytes(CreateCSharpCompilationWithMscorlib("public class C1 {}", "1").EmitToArray());
dir1.CreateFile("1.dll").WriteAllBytes(CreateCSharpCompilationWithCorlib("public class C1 {}", "1").EmitToArray());
var dir2 = Temp.CreateDirectory();
dir2.CreateFile("2.dll").WriteAllBytes(CreateCSharpCompilationWithMscorlib("public class C2 {}", "2").EmitToArray());
dir2.CreateFile("2.dll").WriteAllBytes(CreateCSharpCompilationWithCorlib("public class C2 {}", "2").EmitToArray());
var dir3 = Temp.CreateDirectory();
dir3.CreateFile("3.dll").WriteAllBytes(CreateCSharpCompilationWithMscorlib("public class C3 {}", "3").EmitToArray());
dir3.CreateFile("3.dll").WriteAllBytes(CreateCSharpCompilationWithCorlib("public class C3 {}", "3").EmitToArray());
var dir4 = Temp.CreateDirectory();
dir4.CreateFile("4.dll").WriteAllBytes(CreateCSharpCompilationWithMscorlib("public class C4 {}", "4").EmitToArray());
dir4.CreateFile("4.dll").WriteAllBytes(CreateCSharpCompilationWithCorlib("public class C4 {}", "4").EmitToArray());
var runner = CreateRunner(new[] { "/r:4.dll", $"/lib:{dir1.Path}", $"/libpath:{dir2.Path}", $"/libpaths:{dir3.Path};{dir4.Path}", main.Path });
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.VisualBasic;
......@@ -9,28 +10,28 @@ internal static class TestCompilationFactory
{
// TODO: we need to clean up and refactor CreateCompilationWithMscorlib in compiler tests
// so that it can be used in portable tests.
internal static Compilation CreateCSharpCompilationWithMscorlib(string source, string assemblyName)
internal static Compilation CreateCSharpCompilationWithCorlib(string source, string assemblyName = null)
{
return CSharpCompilation.Create(
assemblyName,
assemblyName ?? Guid.NewGuid().ToString(),
new[] { CSharp.SyntaxFactory.ParseSyntaxTree(source) },
new[] { TestReferences.NetFx.v4_0_30319.mscorlib },
new[] { TestReferences.NetStandard13.SystemRuntime },
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
}
internal static Compilation CreateVisualBasicCompilationWithMscorlib(string source, string assemblyName)
internal static Compilation CreateVisualBasicCompilationWithCorlib(string source, string assemblyName = null)
{
return VisualBasicCompilation.Create(
assemblyName,
assemblyName ?? Guid.NewGuid().ToString(),
new[] { VisualBasic.SyntaxFactory.ParseSyntaxTree(source) },
new[] { TestReferences.NetFx.v4_0_30319.mscorlib },
new[] { TestReferences.NetStandard13.SystemRuntime },
new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
}
internal static Compilation CreateCSharpCompilation(string source, MetadataReference[] references, string assemblyName, CSharpCompilationOptions options = null)
internal static Compilation CreateCSharpCompilation(string source, MetadataReference[] references, string assemblyName = null, CSharpCompilationOptions options = null)
{
return CSharpCompilation.Create(
assemblyName,
assemblyName ?? Guid.NewGuid().ToString(),
new[] { CSharp.SyntaxFactory.ParseSyntaxTree(source) },
references,
options ?? new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
......
......@@ -80,7 +80,7 @@ Type ""#help"" for more information.
<Fact()>
Public Sub TestReferenceDirective()
Dim file1 = Temp.CreateFile("1.dll").WriteAllBytes(TestCompilationFactory.CreateVisualBasicCompilationWithMscorlib("
Dim file1 = Temp.CreateFile("1.dll").WriteAllBytes(TestCompilationFactory.CreateVisualBasicCompilationWithCorlib("
public Class C1
Public Function Foo() As String
Return ""Bar""
......
......@@ -120,7 +120,7 @@ public class TestAnalyzer : DiagnosticAnalyzer
new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(analyzerSource) },
new MetadataReference[]
{
TestBase.SystemRuntimeNetstandard13FacadeRef.Value,
TestReferences.NetStandard13.SystemRuntime,
MetadataReference.CreateFromFile(immutable.Path),
MetadataReference.CreateFromFile(analyzer.Path)
},
......
......@@ -534,6 +534,23 @@ public static PortableExecutableReference mscorlib
}
}
public static class NetStandard13
{
private static PortableExecutableReference s_systemRuntime;
public static PortableExecutableReference SystemRuntime
{
get
{
if (s_systemRuntime == null)
{
s_systemRuntime = AssemblyMetadata.CreateFromImage(TestResources.NetFX.ReferenceAssemblies_netstandard1_3.System_Runtime).GetReference(display: @"System.Runtime.dll (netstandard13 ref)");
}
return s_systemRuntime;
}
}
}
public static class DiagnosticTests
{
public static class ErrTestLib01
......
......@@ -526,11 +526,6 @@ public static MetadataReference SystemRuntimePP7Ref
}
}
public static Lazy<MetadataReference> SystemRuntimeNetstandard13FacadeRef { get; } =
new Lazy<MetadataReference>(() => AssemblyMetadata.CreateFromImage(
TestResources.NetFX.ReferenceAssemblies_netstandard1_3.System_Runtime)
.GetReference(display: "System.Runtime.dll"));
private static MetadataReference s_FSharpTestLibraryRef;
public static MetadataReference FSharpTestLibraryRef
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册