未验证 提交 739b8055 编写于 作者: F filipw

added some extra tests for PDB via the Create(Stream) path

上级 f47a9b2e
......@@ -713,7 +713,7 @@ public async Task LoadedFileWithVoidReturn()
}
[Fact]
public async Task Pdb_CodeFromFile_WithEmitDebugInformation_WithoutFileEncoding_CompilationErrorException()
public async Task Pdb_CreateFromString_CodeFromFile_WithEmitDebugInformation_WithoutFileEncoding_CompilationErrorException()
{
try
{
......@@ -727,108 +727,80 @@ public async Task Pdb_CodeFromFile_WithEmitDebugInformation_WithoutFileEncoding_
}
[Fact]
public async Task Pdb_CodeFromFile_WithEmitDebugInformation_WithFileEncoding_ResultInPdbEmitted()
public Task Pdb_CreateFromString_CodeFromFile_WithEmitDebugInformation_WithFileEncoding_ResultInPdbEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFilePath("debug.csx").WithFileEncoding(Encoding.UTF8);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.EndsWith("debug.csx:line 1", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFilePath("debug.csx").WithFileEncoding(Encoding.UTF8);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "debug.csx:line 1");
}
[Fact]
public async Task Pdb_CodeFromFile_WithoutEmitDebugInformation_WithoutFileEncoding_ResultInPdbNotEmitted()
public Task Pdb_CreateFromString_CodeFromFile_WithoutEmitDebugInformation_WithoutFileEncoding_ResultInPdbNotEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFilePath("debug.csx").WithFileEncoding(null);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.Equal("at Submission#0.<<Initialize>>d__0.MoveNext()", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFilePath(null).WithFileEncoding(null);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "at Submission#0.<<Initialize>>d__0.MoveNext()");
}
[Fact]
public async Task Pdb_CodeFromFile_WithoutEmitDebugInformation_WithFileEncoding_ResultInPdbNotEmitted()
public Task Pdb_CreateFromString_CodeFromFile_WithoutEmitDebugInformation_WithFileEncoding_ResultInPdbNotEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFilePath("debug.csx").WithFileEncoding(Encoding.UTF8);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.Equal("at Submission#0.<<Initialize>>d__0.MoveNext()", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFilePath("debug.csx").WithFileEncoding(Encoding.UTF8);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "at Submission#0.<<Initialize>>d__0.MoveNext()");
}
[Fact]
public async Task Pdb_InlineCode_WithEmitDebugInformation_WithoutFileEncoding_ResultInPdbEmitted()
public Task Pdb_CreateFromStream_CodeFromFile_WithEmitDebugInformation_ResultInPdbEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFileEncoding(null);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.Equal("at Submission#0.<<Initialize>>d__0.MoveNext() in :line 1", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFilePath("debug.csx");
return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), "debug.csx:line 1");
}
[Fact]
public async Task Pdb_InlineCode_WithEmitDebugInformation_WithFileEncoding_ResultInPdbEmitted()
public Task Pdb_CreateFromStream_CodeFromFile_WithoutEmitDebugInformation_ResultInPdbNotEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFileEncoding(Encoding.UTF8);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.Equal("at Submission#0.<<Initialize>>d__0.MoveNext() in :line 1", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFilePath("debug.csx");
return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), "at Submission#0.<<Initialize>>d__0.MoveNext()");
}
[Fact]
public async Task Pdb_InlineCode_WithoutEmitDebugInformation_WithoutFileEncoding_ResultInPdbNotEmitted()
public Task Pdb_CreateFromString_InlineCode_WithEmitDebugInformation_WithoutFileEncoding_ResultInPdbEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFileEncoding(null);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.Equal("at Submission#0.<<Initialize>>d__0.MoveNext()", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFileEncoding(null);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "at Submission#0.<<Initialize>>d__0.MoveNext() in :line 1");
}
[Fact]
public async Task Pdb_InlineCode_WithoutEmitDebugInformation_WithFileEncoding_ResultInPdbNotEmitted()
public Task Pdb_CreateFromString_InlineCode_WithEmitDebugInformation_WithFileEncoding_ResultInPdbEmitted()
{
try
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFileEncoding(Encoding.UTF8);
var script = await CSharpScript.RunAsync("throw new System.Exception();", opts);
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.Equal("at Submission#0.<<Initialize>>d__0.MoveNext()", GetStackTraceLine(ex, 0));
}
var opts = ScriptOptions.Default.WithEmitDebugInformation(true).WithFileEncoding(Encoding.UTF8);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "at Submission#0.<<Initialize>>d__0.MoveNext() in :line 1");
}
[Fact]
public Task Pdb_CreateFromString_InlineCode_WithoutEmitDebugInformation_WithoutFileEncoding_ResultInPdbNotEmitted()
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFileEncoding(null);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "at Submission#0.<<Initialize>>d__0.MoveNext()");
}
[Fact]
public Task Pdb_CreateFromString_InlineCode_WithoutEmitDebugInformation_WithFileEncoding_ResultInPdbNotEmitted()
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false).WithFileEncoding(Encoding.UTF8);
return VerifyStackTraceAsync(() => CSharpScript.Create("throw new System.Exception();", opts), "at Submission#0.<<Initialize>>d__0.MoveNext()");
}
[Fact]
public Task Pdb_CreateFromStream_InlineCode_WithEmitDebugInformation_ResultInPdbEmitted()
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(true);
return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), "at Submission#0.<<Initialize>>d__0.MoveNext() in :line 1");
}
[Fact]
public Task Pdb_CreateFromStream_InlineCode_WithoutEmitDebugInformation_ResultInPdbNotEmitted()
{
var opts = ScriptOptions.Default.WithEmitDebugInformation(false);
return VerifyStackTraceAsync(() => CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("throw new System.Exception();")), opts), "at Submission#0.<<Initialize>>d__0.MoveNext()");
}
[WorkItem(12348, "https://github.com/dotnet/roslyn/issues/12348")]
......@@ -896,5 +868,19 @@ private string GetStackTraceLine(Exception ex, int index)
return null;
}
private async Task VerifyStackTraceAsync(Func<Script<object>> scriptProvider, string expectedFirstLineEnding)
{
try
{
var script = scriptProvider();
await script.RunAsync();
}
catch (Exception ex)
{
// line information is only available when PDBs have been emitted
Assert.EndsWith(expectedFirstLineEnding, GetStackTraceLine(ex, 0));
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册