Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
227985f5
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
227985f5
编写于
1月 29, 2016
作者:
T
Tomas Matousek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch most C# EE tests to helpers that excercise both Windows and Portable PDBs
上级
c1919d68
变更
17
展开全部
隐藏空白更改
内联
并排
Showing
17 changed file
with
5315 addition
and
5252 deletion
+5315
-5252
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/AccessibilityTests.cs
...ator/CSharp/Test/ExpressionCompiler/AccessibilityTests.cs
+9
-9
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DebuggerDisplayAttributeTests.cs
.../Test/ExpressionCompiler/DebuggerDisplayAttributeTests.cs
+125
-104
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DeclarationTests.cs
...luator/CSharp/Test/ExpressionCompiler/DeclarationTests.cs
+465
-512
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs
...nEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs
+417
-403
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTestBase.cs
...arp/Test/ExpressionCompiler/ExpressionCompilerTestBase.cs
+36
-0
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs
...CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs
+1211
-1295
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/HoistedStateMachineLocalTests.cs
.../Test/ExpressionCompiler/HoistedStateMachineLocalTests.cs
+535
-492
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/HoistedThisTests.cs
...luator/CSharp/Test/ExpressionCompiler/HoistedThisTests.cs
+110
-114
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs
...onEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs
+950
-931
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ManagedAddressOfTests.cs
...r/CSharp/Test/ExpressionCompiler/ManagedAddressOfTests.cs
+86
-87
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs
...or/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs
+347
-326
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/NoPIATests.cs
...ionEvaluator/CSharp/Test/ExpressionCompiler/NoPIATests.cs
+19
-19
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/PseudoVariableTests.cs
...tor/CSharp/Test/ExpressionCompiler/PseudoVariableTests.cs
+459
-456
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
.../CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
+134
-133
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ResultPropertiesTests.cs
...r/CSharp/Test/ExpressionCompiler/ResultPropertiesTests.cs
+118
-98
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/UsingDebugInfoTests.cs
...tor/CSharp/Test/ExpressionCompiler/UsingDebugInfoTests.cs
+175
-155
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
...ionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
+119
-118
未找到文件。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/AccessibilityTests.cs
浏览文件 @
227985f5
...
...
@@ -139,17 +139,16 @@ object M()
options
:
TestOptions
.
DebugDll
,
assemblyName
:
Guid
.
NewGuid
().
ToString
(
"D"
));
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.M(this.P)"
,
out
error
,
testData
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.M(this.P)"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 13 (0xd)
.maxstack 2
...
...
@@ -161,6 +160,7 @@ .locals init (object V_0)
IL_000c: ret
}
"
);
});
}
[
Fact
]
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DebuggerDisplayAttributeTests.cs
浏览文件 @
227985f5
...
...
@@ -29,47 +29,50 @@ class C
static int P { get { return 3; } }
object Q { get { return 4; } }
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
// Static field.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"F"
),
@"{
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
// Static field.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"F"
),
@"{
// Code size 6 (0x6)
.maxstack 1
IL_0000: ldsfld ""object C.F""
IL_0005: ret
}"
);
// Instance field.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"G"
),
@"{
// Instance field.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"G"
),
@"{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: ldfld ""int C.G""
IL_0006: ret
}"
);
// Static property.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"P"
),
@"{
// Static property.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"P"
),
@"{
// Code size 6 (0x6)
.maxstack 1
IL_0000: call ""int C.P.get""
IL_0005: ret
}"
);
// Instance property.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"Q"
),
@"{
// Instance property.
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"Q"
),
@"{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: callvirt ""object C.Q.get""
IL_0006: ret
}"
);
});
}
[
Fact
]
...
...
@@ -84,11 +87,12 @@ class C
const int G = 2;
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"F[G]"
),
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"F[G]"
),
@"{
// Code size 12 (0xc)
.maxstack 2
IL_0000: ldstr ""str""
...
...
@@ -96,6 +100,7 @@ .maxstack 2
IL_0006: call ""char string.this[int].get""
IL_000b: ret
}"
);
});
}
[
Fact
]
...
...
@@ -112,17 +117,19 @@ static object F(C c)
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"F(this)"
),
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"F(this)"
),
@"{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: call ""object C.F(C)""
IL_0006: ret
}"
);
});
}
[
Fact
]
...
...
@@ -146,17 +153,19 @@ class B : A
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"B"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"base.F()"
),
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"B"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
CompileExpression
(
context
,
"base.F()"
),
@"{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: call ""object A.F()""
IL_0006: ret
}"
);
});
}
[
Fact
]
...
...
@@ -176,15 +185,16 @@ internal class B<U>
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"A.B"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"F(default(T), default(U))"
,
out
error
,
testData
);
string
actualIL
=
testData
.
GetMethodData
(
"<>x<T, U>.<>m0"
).
GetMethodIL
();
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
actualIL
,
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"A.B"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"F(default(T), default(U))"
,
out
error
,
testData
);
string
actualIL
=
testData
.
GetMethodData
(
"<>x<T, U>.<>m0"
).
GetMethodIL
();
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
actualIL
,
@"{
// Code size 24 (0x18)
.maxstack 2
.locals init (T V_0,
...
...
@@ -198,15 +208,16 @@ .maxstack 2
IL_0012: call ""object A<T>.B<U>.F<T, U>(T, U)""
IL_0017: ret
}"
);
// Verify generated type is generic, but method is not.
using
(
var
metadata
=
ModuleMetadata
.
CreateFromImage
(
ImmutableArray
.
CreateRange
(
result
.
Assembly
)))
{
var
reader
=
metadata
.
MetadataReader
;
var
typeDef
=
reader
.
GetTypeDef
(
result
.
TypeName
);
reader
.
CheckTypeParameters
(
typeDef
.
GetGenericParameters
(),
"T"
,
"U"
);
var
methodDef
=
reader
.
GetMethodDef
(
typeDef
,
result
.
MethodName
);
reader
.
CheckTypeParameters
(
methodDef
.
GetGenericParameters
());
}
// Verify generated type is generic, but method is not.
using
(
var
metadata
=
ModuleMetadata
.
CreateFromImage
(
ImmutableArray
.
CreateRange
(
result
.
Assembly
)))
{
var
reader
=
metadata
.
MetadataReader
;
var
typeDef
=
reader
.
GetTypeDef
(
result
.
TypeName
);
reader
.
CheckTypeParameters
(
typeDef
.
GetGenericParameters
(),
"T"
,
"U"
);
var
methodDef
=
reader
.
GetMethodDef
(
typeDef
,
result
.
MethodName
);
reader
.
CheckTypeParameters
(
methodDef
.
GetGenericParameters
());
}
});
}
[
Fact
]
...
...
@@ -227,16 +238,17 @@ void M()
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"N.C"
);
string
error
;
var
testData
=
new
CompilationTestData
();
// Expression compilation should succeed without imports.
var
result
=
context
.
CompileExpression
(
"typeof(N.C) ?? typeof(C)"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
testData
.
GetMethodData
(
"<>x.<>m0"
).
GetMethodIL
(),
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"N.C"
);
string
error
;
var
testData
=
new
CompilationTestData
();
// Expression compilation should succeed without imports.
var
result
=
context
.
CompileExpression
(
"typeof(N.C) ?? typeof(C)"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
testData
.
GetMethodData
(
"<>x.<>m0"
).
GetMethodIL
(),
@"{
// Code size 25 (0x19)
.maxstack 2
IL_0000: ldtoken ""N.C""
...
...
@@ -248,14 +260,15 @@ .maxstack 2
IL_0013: call ""System.Type System.Type.GetTypeFromHandle(System.RuntimeTypeHandle)""
IL_0018: ret
}"
);
// Expression compilation should fail using imports since there are no symbols.
context
=
CreateTypeContext
(
runtime
,
"N.C"
);
testData
=
new
CompilationTestData
();
result
=
context
.
CompileExpression
(
"typeof(A.C) ?? typeof(B) ?? typeof(C)"
,
out
error
,
testData
);
Assert
.
Equal
(
error
,
"error CS0246: The type or namespace name 'A' could not be found (are you missing a using directive or an assembly reference?)"
);
testData
=
new
CompilationTestData
();
result
=
context
.
CompileExpression
(
"typeof(B) ?? typeof(C)"
,
out
error
,
testData
);
Assert
.
Equal
(
error
,
"error CS0246: The type or namespace name 'B' could not be found (are you missing a using directive or an assembly reference?)"
);
// Expression compilation should fail using imports since there are no symbols.
context
=
CreateTypeContext
(
runtime
,
"N.C"
);
testData
=
new
CompilationTestData
();
result
=
context
.
CompileExpression
(
"typeof(A.C) ?? typeof(B) ?? typeof(C)"
,
out
error
,
testData
);
Assert
.
Equal
(
error
,
"error CS0246: The type or namespace name 'A' could not be found (are you missing a using directive or an assembly reference?)"
);
testData
=
new
CompilationTestData
();
result
=
context
.
CompileExpression
(
"typeof(B) ?? typeof(C)"
,
out
error
,
testData
);
Assert
.
Equal
(
error
,
"error CS0246: The type or namespace name 'B' could not be found (are you missing a using directive or an assembly reference?)"
);
});
}
[
Fact
]
...
...
@@ -268,12 +281,14 @@ class C
{
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"$ReturnValue"
,
out
error
,
testData
);
Assert
.
Equal
(
error
,
"error CS0103: The name '$ReturnValue' does not exist in the current context"
);
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"$ReturnValue"
,
out
error
,
testData
);
Assert
.
Equal
(
error
,
"error CS0103: The name '$ReturnValue' does not exist in the current context"
);
});
}
[
Fact
]
...
...
@@ -289,10 +304,11 @@ static object F(System.Func<object> f)
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
@"{
// Code size 29 (0x1d)
.maxstack 3
IL_0000: newobj ""<>x.<>c__DisplayClass0_0..ctor()""
...
...
@@ -304,7 +320,8 @@ .maxstack 3
IL_0017: call ""object C.F(System.Func<object>)""
IL_001c: ret
}"
,
CompileExpression
(
context
,
"F(() => this.o)"
));
CompileExpression
(
context
,
"F(() => this.o)"
));
});
}
[
Fact
]
...
...
@@ -318,19 +335,21 @@ class C
object F = ""f"";
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
// No format specifiers.
string
error
;
var
result
=
context
.
CompileExpression
(
"F"
,
out
error
);
Assert
.
NotNull
(
result
.
Assembly
);
Assert
.
Null
(
result
.
FormatSpecifiers
);
// Format specifiers.
result
=
context
.
CompileExpression
(
"F, nq,ac"
,
out
error
);
Assert
.
NotNull
(
result
.
Assembly
);
Assert
.
Equal
(
result
.
FormatSpecifiers
.
Count
,
2
);
Assert
.
Equal
(
result
.
FormatSpecifiers
[
0
],
"nq"
);
Assert
.
Equal
(
result
.
FormatSpecifiers
[
1
],
"ac"
);
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"C"
);
// No format specifiers.
string
error
;
var
result
=
context
.
CompileExpression
(
"F"
,
out
error
);
Assert
.
NotNull
(
result
.
Assembly
);
Assert
.
Null
(
result
.
FormatSpecifiers
);
// Format specifiers.
result
=
context
.
CompileExpression
(
"F, nq,ac"
,
out
error
);
Assert
.
NotNull
(
result
.
Assembly
);
Assert
.
Equal
(
result
.
FormatSpecifiers
.
Count
,
2
);
Assert
.
Equal
(
result
.
FormatSpecifiers
[
0
],
"nq"
);
Assert
.
Equal
(
result
.
FormatSpecifiers
[
1
],
"ac"
);
});
}
[
Fact
]
...
...
@@ -357,22 +376,24 @@ protected override string GetDebuggerDisplay()
}
"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateTypeContext
(
runtime
,
"Derived"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"GetDebuggerDisplay()"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
actualIL
=
testData
.
GetMethodData
(
"<>x.<>m0"
).
GetMethodIL
();
var
expectedIL
=
@"{
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateTypeContext
(
runtime
,
"Derived"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"GetDebuggerDisplay()"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
actualIL
=
testData
.
GetMethodData
(
"<>x.<>m0"
).
GetMethodIL
();
var
expectedIL
=
@"{
// Code size 7 (0x7)
.maxstack 1
IL_0000: ldarg.0
IL_0001: callvirt ""string Derived.GetDebuggerDisplay()""
IL_0006: ret
}"
;
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
expectedIL
,
actualIL
);
AssertEx
.
AssertEqualToleratingWhitespaceDifferences
(
expectedIL
,
actualIL
);
});
}
private
static
string
CompileExpression
(
EvaluationContext
context
,
string
expr
)
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DeclarationTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/DynamicTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTestBase.cs
浏览文件 @
227985f5
...
...
@@ -47,6 +47,42 @@ public override void Dispose()
_runtimeInstances
.
Free
();
}
// TODO: remove -- workaround for bugs in Portable PDB handling in EE
internal
static
void
WithRuntimeInstancePortableBug
(
Compilation
compilation
,
Action
<
RuntimeInstance
>
validator
)
{
WithRuntimeInstancePortableBug
(
compilation
,
null
,
validator
);
}
// TODO: remove -- workaround for bugs in Portable PDB handling in EE
internal
static
void
WithRuntimeInstancePortableBug
(
Compilation
compilation
,
IEnumerable
<
MetadataReference
>
references
,
Action
<
RuntimeInstance
>
validator
)
{
using
(
var
instance
=
RuntimeInstance
.
Create
(
compilation
,
references
,
DebugInformationFormat
.
Pdb
,
true
))
{
validator
(
instance
);
}
}
internal
static
void
WithRuntimeInstance
(
Compilation
compilation
,
Action
<
RuntimeInstance
>
validator
)
{
WithRuntimeInstance
(
compilation
,
null
,
true
,
validator
);
}
internal
static
void
WithRuntimeInstance
(
Compilation
compilation
,
IEnumerable
<
MetadataReference
>
references
,
Action
<
RuntimeInstance
>
validator
)
{
WithRuntimeInstance
(
compilation
,
references
,
true
,
validator
);
}
internal
static
void
WithRuntimeInstance
(
Compilation
compilation
,
IEnumerable
<
MetadataReference
>
references
,
bool
includeLocalSignatures
,
Action
<
RuntimeInstance
>
validator
)
{
foreach
(
var
debugFormat
in
new
[]
{
DebugInformationFormat
.
Pdb
,
DebugInformationFormat
.
PortablePdb
})
{
using
(
var
instance
=
RuntimeInstance
.
Create
(
compilation
,
references
,
debugFormat
,
includeLocalSignatures
))
{
validator
(
instance
);
}
}
}
internal
RuntimeInstance
CreateRuntimeInstance
(
IEnumerable
<
ModuleInstance
>
modules
)
{
var
instance
=
RuntimeInstance
.
Create
(
modules
);
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ExpressionCompilerTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/HoistedStateMachineLocalTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/HoistedThisTests.cs
浏览文件 @
227985f5
...
...
@@ -10,7 +10,6 @@
using
Microsoft.CodeAnalysis.ExpressionEvaluator
;
using
Microsoft.CodeAnalysis.ExpressionEvaluator.UnitTests
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.PdbUtilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
...
...
@@ -850,24 +849,25 @@ .maxstack 1
}}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
dummyComp
=
CreateCompilationWithMscorlib
(
""
,
new
[]
{
comp
.
EmitToImageReference
()
},
options
:
TestOptions
.
DebugDll
.
WithMetadataImportOptions
(
MetadataImportOptions
.
All
));
var
typeC
=
dummyComp
.
GlobalNamespace
.
GetMember
<
NamedTypeSymbol
>(
"C"
);
var
displayClassTypes
=
typeC
.
GetMembers
().
OfType
<
NamedTypeSymbol
>();
Assert
.
True
(
displayClassTypes
.
Any
());
foreach
(
var
displayClassType
in
displayClassTypes
)
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
displayClassName
=
displayClassType
.
Name
;
Assert
.
Equal
(
GeneratedNameKind
.
LambdaDisplayClass
,
GeneratedNames
.
GetKind
(
displayClassName
));
foreach
(
var
displayClassMethod
in
displayClassType
.
GetMembers
().
OfType
<
MethodSymbol
>().
Where
(
m
=>
GeneratedNames
.
GetKind
(
m
.
Name
)
==
GeneratedNameKind
.
LambdaMethod
))
var
dummyComp
=
CreateCompilationWithMscorlib
(
""
,
new
[]
{
comp
.
EmitToImageReference
()
},
options
:
TestOptions
.
DebugDll
.
WithMetadataImportOptions
(
MetadataImportOptions
.
All
));
var
typeC
=
dummyComp
.
GlobalNamespace
.
GetMember
<
NamedTypeSymbol
>(
"C"
);
var
displayClassTypes
=
typeC
.
GetMembers
().
OfType
<
NamedTypeSymbol
>();
Assert
.
True
(
displayClassTypes
.
Any
());
foreach
(
var
displayClassType
in
displayClassTypes
)
{
var
lambdaMethodName
=
string
.
Format
(
"C.{0}.{1}"
,
displayClassName
,
displayClassMethod
.
Name
);
var
context
=
CreateMethodContext
(
runtime
,
lambdaMethodName
);
var
expectedIL
=
string
.
Format
(
expectedILTemplate
,
displayClassName
);
VerifyHasThis
(
context
,
"C"
,
expectedIL
);
var
displayClassName
=
displayClassType
.
Name
;
Assert
.
Equal
(
GeneratedNameKind
.
LambdaDisplayClass
,
GeneratedNames
.
GetKind
(
displayClassName
));
foreach
(
var
displayClassMethod
in
displayClassType
.
GetMembers
().
OfType
<
MethodSymbol
>().
Where
(
m
=>
GeneratedNames
.
GetKind
(
m
.
Name
)
==
GeneratedNameKind
.
LambdaMethod
))
{
var
lambdaMethodName
=
string
.
Format
(
"C.{0}.{1}"
,
displayClassName
,
displayClassMethod
.
Name
);
var
context
=
CreateMethodContext
(
runtime
,
lambdaMethodName
);
var
expectedIL
=
string
.
Format
(
expectedILTemplate
,
displayClassName
);
VerifyHasThis
(
context
,
"C"
,
expectedIL
);
}
}
}
}
);
}
[
Fact
]
...
...
@@ -912,52 +912,56 @@ static int P
"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
dummyComp
=
CreateCompilationWithMscorlib
(
""
,
new
[]
{
comp
.
EmitToImageReference
()
},
options
:
TestOptions
.
DebugDll
.
WithMetadataImportOptions
(
MetadataImportOptions
.
All
));
var
typeC
=
dummyComp
.
GlobalNamespace
.
GetMember
<
NamedTypeSymbol
>(
"C"
);
var
displayClassTypes
=
typeC
.
GetMembers
().
OfType
<
NamedTypeSymbol
>();
Assert
.
True
(
displayClassTypes
.
Any
());
foreach
(
var
displayClassType
in
displayClassTypes
)
WithRuntimeInstancePortableBug
(
comp
,
runtime
=>
{
var
displayClassName
=
displayClassType
.
Name
;
Assert
.
Equal
(
GeneratedNameKind
.
LambdaDisplayClass
,
GeneratedNames
.
GetKind
(
displayClassName
));
foreach
(
var
displayClassMethod
in
displayClassType
.
GetMembers
().
OfType
<
MethodSymbol
>().
Where
(
m
=>
GeneratedNames
.
GetKind
(
m
.
Name
)
==
GeneratedNameKind
.
LambdaMethod
))
var
dummyComp
=
CreateCompilationWithMscorlib
(
""
,
new
[]
{
comp
.
EmitToImageReference
()
},
options
:
TestOptions
.
DebugDll
.
WithMetadataImportOptions
(
MetadataImportOptions
.
All
));
var
typeC
=
dummyComp
.
GlobalNamespace
.
GetMember
<
NamedTypeSymbol
>(
"C"
);
var
displayClassTypes
=
typeC
.
GetMembers
().
OfType
<
NamedTypeSymbol
>();
Assert
.
True
(
displayClassTypes
.
Any
());
foreach
(
var
displayClassType
in
displayClassTypes
)
{
var
lambdaMethodName
=
string
.
Format
(
"C.{0}.{1}"
,
displayClassName
,
displayClassMethod
.
Name
);
var
context
=
CreateMethodContext
(
runtime
,
lambdaMethodName
);
VerifyNoThis
(
context
);
var
displayClassName
=
displayClassType
.
Name
;
Assert
.
Equal
(
GeneratedNameKind
.
LambdaDisplayClass
,
GeneratedNames
.
GetKind
(
displayClassName
));
foreach
(
var
displayClassMethod
in
displayClassType
.
GetMembers
().
OfType
<
MethodSymbol
>().
Where
(
m
=>
GeneratedNames
.
GetKind
(
m
.
Name
)
==
GeneratedNameKind
.
LambdaMethod
))
{
var
lambdaMethodName
=
string
.
Format
(
"C.{0}.{1}"
,
displayClassName
,
displayClassMethod
.
Name
);
var
context
=
CreateMethodContext
(
runtime
,
lambdaMethodName
);
VerifyNoThis
(
context
);
}
}
}
}
);
}
private
void
VerifyHasThis
(
string
source
,
string
methodName
,
string
expectedType
,
string
expectedIL
,
bool
thisCanBeElided
=
true
)
{
var
sourceCompilation
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
sourceCompilation
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
);
VerifyHasThis
(
context
,
expectedType
,
expectedIL
);
WithRuntimeInstancePortableBug
(
sourceCompilation
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
methodName
);
VerifyHasThis
(
context
,
expectedType
,
expectedIL
);
});
// Now recompile and test CompileExpression with optimized code.
sourceCompilation
=
sourceCompilation
.
WithOptions
(
sourceCompilation
.
Options
.
WithOptimizationLevel
(
OptimizationLevel
.
Release
));
runtime
=
CreateRuntimeInstance
(
sourceCompilation
);
context
=
CreateMethodContext
(
runtime
,
methodName
);
// In C#, "this" may be optimized away.
if
(
thisCanBeElided
)
{
VerifyNoThis
(
context
);
}
else
WithRuntimeInstancePortableBug
(
sourceCompilation
,
runtime
=>
{
VerifyHasThis
(
context
,
expectedType
,
expectedIL
:
null
);
}
// Verify that binding a trivial expression succeeds.
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"42"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
Assert
.
Equal
(
1
,
testData
.
Methods
.
Count
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
);
// In C#, "this" may be optimized away.
if
(
thisCanBeElided
)
{
VerifyNoThis
(
context
);
}
else
{
VerifyHasThis
(
context
,
expectedType
,
expectedIL
:
null
);
}
// Verify that binding a trivial expression succeeds.
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"42"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
Assert
.
Equal
(
1
,
testData
.
Methods
.
Count
);
});
}
private
static
void
VerifyHasThis
(
EvaluationContext
context
,
string
expectedType
,
string
expectedIL
)
...
...
@@ -995,10 +999,8 @@ private static void VerifyMethodData(CompilationTestData.MethodData methodData,
private
void
VerifyNoThis
(
string
source
,
string
methodName
)
{
var
comp
=
CreateCompilationWithMscorlib45
(
source
,
new
[]
{
SystemCoreRef
},
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
);
VerifyNoThis
(
context
);
var
comp
=
CreateCompilationWithMscorlib45
(
source
,
new
[]
{
SystemCoreRef
},
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstance
(
comp
,
runtime
=>
VerifyNoThis
(
CreateMethodContext
(
runtime
,
methodName
)));
}
private
static
void
VerifyNoThis
(
EvaluationContext
context
)
...
...
@@ -1042,16 +1044,14 @@ System.Collections.IEnumerable F()
yield return this.x;
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"C.<F>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstancePortableBug
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.<F>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 12 (0xc)
.maxstack 1
...
...
@@ -1061,6 +1061,7 @@ .locals init (int V_0)
IL_0006: ldfld ""object C.x""
IL_000b: ret
}"
);
});
}
[
WorkItem
(
1024137
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1024137"
)]
...
...
@@ -1079,16 +1080,14 @@ async Task F()
await Console.Out.WriteLineAsync(this.ToString());
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"C.<F>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
var
compilation0
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstancePortableBug
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.<F>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 12 (0xc)
.maxstack 1
...
...
@@ -1101,6 +1100,7 @@ .maxstack 1
IL_0006: ldfld ""object C.x""
IL_000b: ret
}"
);
});
}
[
WorkItem
(
1024137
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1024137"
)]
...
...
@@ -1117,16 +1117,14 @@ void F()
a();
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"C.<F>b__1_0"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstancePortableBug
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.<F>b__1_0"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 7 (0x7)
.maxstack 1
...
...
@@ -1134,6 +1132,7 @@ .maxstack 1
IL_0001: ldfld ""object C.x""
IL_0006: ret
}"
);
});
}
[
Fact
]
...
...
@@ -1154,16 +1153,14 @@ System.Collections.IEnumerable M()
yield return base.x;
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"Derived.<M>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"base.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstancePortableBug
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"Derived.<M>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"base.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 12 (0xc)
.maxstack 1
...
...
@@ -1173,6 +1170,7 @@ .locals init (int V_0)
IL_0006: ldfld ""int Base.x""
IL_000b: ret
}"
);
});
}
[
Fact
]
...
...
@@ -1196,16 +1194,14 @@ async Task M()
await Console.Out.WriteLineAsync(this.ToString());
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"Derived.<M>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"base.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
var
compilation0
=
CreateCompilationWithMscorlib45
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstancePortableBug
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"Derived.<M>d__1.MoveNext"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"base.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 12 (0xc)
.maxstack 1
...
...
@@ -1218,6 +1214,7 @@ .maxstack 1
IL_0006: ldfld ""int Base.x""
IL_000b: ret
}"
);
});
}
[
Fact
]
...
...
@@ -1239,16 +1236,14 @@ void F()
a();
}
}"
;
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"Derived.<F>b__1_0"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
WithRuntimeInstancePortableBug
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"Derived.<F>b__1_0"
);
string
error
;
var
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
"this.x"
,
out
error
,
testData
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"
{
// Code size 7 (0x7)
.maxstack 1
...
...
@@ -1256,6 +1251,7 @@ .maxstack 1
IL_0001: ldfld ""object Derived.x""
IL_0006: ret
}"
);
});
}
[
Fact
]
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ManagedAddressOfTests.cs
浏览文件 @
227985f5
...
...
@@ -22,18 +22,17 @@ void M(string s)
}
}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
testData
=
new
CompilationTestData
();
string
error
;
context
.
CompileExpression
(
"&s"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
AssertIsIntPtrPointer
(
methodData
.
Method
.
ReturnType
);
methodData
.
VerifyIL
(
@"
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
testData
=
new
CompilationTestData
();
string
error
;
context
.
CompileExpression
(
"&s"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
AssertIsIntPtrPointer
(
methodData
.
Method
.
ReturnType
);
methodData
.
VerifyIL
(
@"
{
// Code size 4 (0x4)
.maxstack 1
...
...
@@ -42,6 +41,7 @@ .maxstack 1
IL_0003: ret
}
"
);
});
}
[
Fact
]
...
...
@@ -56,18 +56,17 @@ void M()
}
}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
testData
=
new
CompilationTestData
();
string
error
;
context
.
CompileExpression
(
"&s"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
AssertIsIntPtrPointer
(
methodData
.
Method
.
ReturnType
);
methodData
.
VerifyIL
(
@"
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
testData
=
new
CompilationTestData
();
string
error
;
context
.
CompileExpression
(
"&s"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
AssertIsIntPtrPointer
(
methodData
.
Method
.
ReturnType
);
methodData
.
VerifyIL
(
@"
{
// Code size 4 (0x4)
.maxstack 1
...
...
@@ -77,6 +76,7 @@ .maxstack 1
IL_0003: ret
}
"
);
});
}
[
Fact
]
...
...
@@ -92,18 +92,17 @@ void M()
}
}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
testData
=
new
CompilationTestData
();
string
error
;
context
.
CompileExpression
(
"&s"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
AssertIsIntPtrPointer
(
methodData
.
Method
.
ReturnType
);
methodData
.
VerifyIL
(
@"
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
testData
=
new
CompilationTestData
();
string
error
;
context
.
CompileExpression
(
"&s"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
var
methodData
=
testData
.
GetMethodData
(
"<>x.<>m0"
);
AssertIsIntPtrPointer
(
methodData
.
Method
.
ReturnType
);
methodData
.
VerifyIL
(
@"
{
// Code size 8 (0x8)
.maxstack 1
...
...
@@ -113,6 +112,7 @@ .maxstack 1
IL_0007: ret
}
"
);
});
}
/// <remarks>
...
...
@@ -147,31 +147,30 @@ struct Generic<T>
}
"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
types
=
new
[]
{
"C"
,
// class
"D"
,
// delegate
"I"
,
// interface
"T"
,
// type parameter
"int[]"
,
"Generic<int>"
,
"dynamic"
,
};
foreach
(
var
type
in
types
)
WithRuntimeInstance
(
comp
,
runtime
=>
{
string
error
;
CompilationTestData
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
string
.
Format
(
"sizeof({0})"
,
type
),
out
error
,
testData
);
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
string
.
Format
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('{0}')"
,
type
),
error
);
}
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
types
=
new
[]
{
"C"
,
// class
"D"
,
// delegate
"I"
,
// interface
"T"
,
// type parameter
"int[]"
,
"Generic<int>"
,
"dynamic"
,
};
foreach
(
var
type
in
types
)
{
string
error
;
CompilationTestData
testData
=
new
CompilationTestData
();
context
.
CompileExpression
(
string
.
Format
(
"sizeof({0})"
,
type
),
out
error
,
testData
);
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
string
.
Format
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('{0}')"
,
type
),
error
);
}
});
}
[
Fact
]
...
...
@@ -186,15 +185,15 @@ void M()
}
}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
testData
=
new
CompilationTestData
()
;
string
error
;
context
.
CompileAssignment
(
"a"
,
"() => { var s = stackalloc string[1]; }"
,
out
error
,
testData
);
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('string')"
,
error
);
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
testData
=
new
CompilationTestData
(
);
string
error
;
context
.
CompileAssignment
(
"a"
,
"() => { var s = stackalloc string[1]; }"
,
out
error
,
testData
)
;
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('string')"
,
error
);
}
);
}
[
Fact
]
...
...
@@ -208,15 +207,15 @@ void M()
}
}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
testData
=
new
CompilationTestData
()
;
string
error
;
context
.
CompileExpression
(
"(string*)null"
,
out
error
,
testData
);
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('string')"
,
error
);
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
testData
=
new
CompilationTestData
(
);
string
error
;
context
.
CompileExpression
(
"(string*)null"
,
out
error
,
testData
)
;
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('string')"
,
error
);
}
);
}
/// <remarks>
...
...
@@ -234,15 +233,15 @@ void M(string[] args)
}
}"
;
var
comp
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
comp
);
var
context
=
CreateMethodContext
(
runtime
,
methodName
:
"C.M"
);
var
testData
=
new
CompilationTestData
()
;
string
error
;
context
.
CompileAssignment
(
"a"
,
"() => { fixed (void* p = args) { } }"
,
out
error
,
testData
);
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('string')"
,
error
);
WithRuntimeInstance
(
comp
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
var
testData
=
new
CompilationTestData
(
);
string
error
;
context
.
CompileAssignment
(
"a"
,
"() => { fixed (void* p = args) { } }"
,
out
error
,
testData
)
;
// CONSIDER: change error code to make text less confusing?
Assert
.
Equal
(
"error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('string')"
,
error
);
}
);
}
private
static
void
AssertIsIntPtrPointer
(
ITypeSymbol
returnType
)
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/MissingAssemblyTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/NoPIATests.cs
浏览文件 @
227985f5
...
...
@@ -40,17 +40,15 @@ static void Main()
(new C()).M();
}
}"
;
var
compilation0
=
CSharpTestBase
.
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugExe
,
assemblyName
:
ExpressionCompilerUtilities
.
GenerateUniqueName
());
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"this"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
options
:
TestOptions
.
DebugExe
);
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"this"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"{
// Code size 2 (0x2)
.maxstack 1
...
...
@@ -58,6 +56,7 @@ .maxstack 1
IL_0000: ldarg.0
IL_0001: ret
}"
);
});
}
[
WorkItem
(
1035310
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1035310"
)]
...
...
@@ -86,14 +85,14 @@ static void M()
var
referencePIA
=
compilationPIA
.
EmitToImageReference
(
embedInteropTypes
:
true
);
var
compilation0
=
CreateCompilationWithMscorlib
(
source
,
new
[]
{
referencePIA
},
TestOptions
.
DebugDll
);
var
runtime
=
CreateRuntimeInstance
(
compilation0
);
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"o"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
WithRuntimeInstance
(
compilation0
,
runtime
=>
{
var
context
=
CreateMethodContext
(
runtime
,
"C.M"
);
string
error
;
var
testData
=
new
CompilationTestData
();
var
result
=
context
.
CompileExpression
(
"o"
,
out
error
,
testData
);
Assert
.
Null
(
error
);
testData
.
GetMethodData
(
"<>x.<>m0"
).
VerifyIL
(
@"{
// Code size 2 (0x2)
.maxstack 1
...
...
@@ -101,6 +100,7 @@ .maxstack 1
IL_0000: ldloc.0
IL_0001: ret
}"
);
});
}
/// <summary>
...
...
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/PseudoVariableTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ReferencedModulesTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/ResultPropertiesTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/UsingDebugInfoTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/WinMdTests.cs
浏览文件 @
227985f5
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录