提交 584854e2 编写于 作者: A Artur Spychaj

Add tests for #r compilation

上级 d3da6e81
......@@ -21,6 +21,20 @@ Public Class ParseDirectives
]]>)
End Sub
<Fact>
Public Sub ParseReferenceDirective()
ParseAndVerify(<![CDATA[
#r "reference"
]]>, TestOptions.Script)
ParseAndVerify(<![CDATA[
#r "reference"
]]>,
<errors>
<error id="36964" message="#R is only allowed in scripts" start="14" end="15"/>
</errors>)
End Sub
<Fact>
Public Sub FloatsAndUnaryNot()
ParseAndVerify(<![CDATA[
......
// 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 Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.VisualBasic;
namespace Microsoft.CodeAnalysis.Scripting
{
......@@ -12,16 +13,25 @@ internal static Compilation CreateCompilationWithMscorlib(string source, string
{
return CSharpCompilation.Create(
assemblyName,
new[] { SyntaxFactory.ParseSyntaxTree(source) },
new[] { CSharp.SyntaxFactory.ParseSyntaxTree(source) },
new[] { TestReferences.NetFx.v4_0_30319.mscorlib },
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
}
internal static Compilation CreateVisualBasicCompilationWithMscorlib(string source, string assemblyName)
{
return VisualBasicCompilation.Create(
assemblyName,
new[] { VisualBasic.SyntaxFactory.ParseSyntaxTree(source) },
new[] { TestReferences.NetFx.v4_0_30319.mscorlib },
new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
}
internal static Compilation CreateCompilation(string source, MetadataReference[] references, string assemblyName, CSharpCompilationOptions options = null)
{
return CSharpCompilation.Create(
assemblyName,
new[] { SyntaxFactory.ParseSyntaxTree(source) },
new[] { CSharp.SyntaxFactory.ParseSyntaxTree(source) },
references,
options ?? new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
}
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Reflection
Imports Microsoft.CodeAnalysis.Scripting
Imports Microsoft.CodeAnalysis.Scripting.Hosting
Imports Microsoft.CodeAnalysis.Scripting.Test
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.CodeAnalysis.VisualBasic.Scripting.Hosting
Imports Roslyn.Test.Utilities
Imports Roslyn.Utilities
......@@ -57,7 +59,7 @@ Type ""#help"" for more information.
End Sub
<Fact()>
Public Sub TestReference()
Public Sub TestImportArgument()
Dim runner = CreateRunner(args:={"/Imports:<xmlns:xmlNamespacePrefix='xmlNamespaceName'>"})
runner.RunInteractive()
......@@ -67,6 +69,30 @@ Type ""#help"" for more information.
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
>", runner.Console.Out.ToString())
End Sub
<Fact()>
Public Sub TestReferenceDirective()
Dim file1 = Temp.CreateFile("1.dll").WriteAllBytes(TestCompilationFactory.CreateVisualBasicCompilationWithMscorlib("
public Class C1
Public Function Foo() As String
Return ""Bar""
End Function
End Class", "1").EmitToArray())
Dim runner = CreateRunner(args:={}, input:="#r """ & file1.Path & """" & vbCrLf & "? New C1().Foo()")
runner.RunInteractive()
AssertEx.AssertEqualToleratingWhitespaceDifferences(
"Microsoft (R) Visual Basic Interactive Compiler version " + CompilerVersion + "
Copyright (C) Microsoft Corporation. All rights reserved.
Type ""#help"" for more information.
> #r """ & file1.Path & """
> ? New C1().Foo()
""Bar""
>", runner.Console.Out.ToString())
End Sub
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册