提交 4be251ed 编写于 作者: A AlekseyTs

Merge pull request #9728 from AlekseyTs/Issue6077

Address flakiness of EmitSequenceOfBinaryExpressions_03 unit-test
......@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis.CSharp.UnitTests.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using System.Collections.Immutable;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
......@@ -4754,13 +4755,21 @@ public static double Calculate(long[] f)
var result = CompileAndVerify(source, options: TestOptions.ReleaseExe, expectedOutput: "11461640193");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/6077")]
[Fact]
[WorkItem(6077, "https://github.com/dotnet/roslyn/issues/6077")]
[WorkItem(5395, "https://github.com/dotnet/roslyn/issues/5395")]
public void EmitSequenceOfBinaryExpressions_03()
{
var diagnostics = ImmutableArray<Diagnostic>.Empty;
const int start = 8192;
const int step = 4096;
const int limit = start * 4;
for (int count = start; count <= limit && diagnostics.IsEmpty; count += step)
{
var source =
@"
@"
class Test
{
static void Main()
......@@ -4769,24 +4778,27 @@ static void Main()
public static bool Calculate(bool[] a, bool[] f)
{
" + $" return { BuildSequenceOfBinaryExpressions_03() };" + @"
" + $" return { BuildSequenceOfBinaryExpressions_03(count) };" + @"
}
}
";
var compilation = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseExe);
compilation.VerifyEmitDiagnostics(
diagnostics = compilation.GetEmitDiagnostics();
}
diagnostics.Verify(
// (10,16): error CS8078: An expression is too long or complex to compile
// return a[0] && f[0] || a[1] && f[1] || a[2] && f[2] || ...
Diagnostic(ErrorCode.ERR_InsufficientStack, "a").WithLocation(10, 16)
);
}
private static string BuildSequenceOfBinaryExpressions_03()
private static string BuildSequenceOfBinaryExpressions_03(int count = 8192)
{
var builder = new System.Text.StringBuilder();
int i;
for (i = 0; i < 8192; i++)
for (i = 0; i < count; i++)
{
builder.Append("a[");
builder.Append(i);
......
' 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.Collections.Immutable
Imports System.Reflection
Imports System.Xml.Linq
Imports Microsoft.CodeAnalysis
......@@ -13247,10 +13248,18 @@ End Class
CompileAndVerify(compilation, expectedOutput:="11461640193")
End Sub
<Fact(Skip:="https://github.com/dotnet/roslyn/issues/6077")>
<Fact>
<WorkItem(6077, "https://github.com/dotnet/roslyn/issues/6077")>
<WorkItem(5395, "https://github.com/dotnet/roslyn/issues/5395")>
Public Sub EmitSequenceOfBinaryExpressions_03()
Dim diagnostics = ImmutableArray(Of Diagnostic).Empty
Const start = 8192
Const [step] = 4096
Const limit = start * 4
For count As Integer = start To limit Step [step]
Dim source =
$"
Class Test
......@@ -13258,22 +13267,28 @@ Class Test
End Sub
Shared Function Calculate(a As Boolean(), f As Boolean()) As Boolean
Return {BuildSequenceOfBinaryExpressions_03()}
Return {BuildSequenceOfBinaryExpressions_03(count)}
End Function
End Class
"
Dim compilation = CreateCompilationWithMscorlib({source}, options:=TestOptions.ReleaseExe.WithOverflowChecks(True))
diagnostics = compilation.GetEmitDiagnostics()
compilation.VerifyEmitDiagnostics(
If Not diagnostics.IsEmpty Then
Exit For
End If
Next
diagnostics.Verify(
Diagnostic(ERRID.ERR_TooLongOrComplexExpression, "a").WithLocation(7, 16)
)
End Sub
Private Shared Function BuildSequenceOfBinaryExpressions_03() As String
Private Shared Function BuildSequenceOfBinaryExpressions_03(Optional count As Integer = 8192) As String
Dim builder = New System.Text.StringBuilder()
Dim i As Integer
For i = 0 To 8192 - 1
For i = 0 To count - 1
builder.Append("a(")
builder.Append(i)
builder.Append(")")
......
......@@ -235,22 +235,36 @@ public static bool IsDiagnosticAnalyzerSuppressed(this DiagnosticAnalyzer analyz
public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, EmitOptions options, params DiagnosticDescription[] expected)
where TCompilation : Compilation
{
var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream();
c.Emit(new MemoryStream(), pdbStream: pdbStream, options: options).Diagnostics.Verify(expected);
c.GetEmitDiagnostics(options: options).Verify(expected);
return c;
}
public static ImmutableArray<Diagnostic> GetEmitDiagnostics<TCompilation>(
this TCompilation c,
EmitOptions options = null,
IEnumerable<ResourceDescription> manifestResources = null)
where TCompilation : Compilation
{
var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream();
return c.Emit(new MemoryStream(), pdbStream: pdbStream, options: options, manifestResources: manifestResources).Diagnostics;
}
public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, params DiagnosticDescription[] expected)
where TCompilation : Compilation
{
return VerifyEmitDiagnostics(c, EmitOptions.Default, expected);
}
public static ImmutableArray<Diagnostic> GetEmitDiagnostics<TCompilation>(this TCompilation c)
where TCompilation : Compilation
{
return GetEmitDiagnostics(c, EmitOptions.Default);
}
public static TCompilation VerifyEmitDiagnostics<TCompilation>(this TCompilation c, IEnumerable<ResourceDescription> manifestResources, params DiagnosticDescription[] expected)
where TCompilation : Compilation
{
var pdbStream = MonoHelpers.IsRunningOnMono() ? null : new MemoryStream();
c.Emit(new MemoryStream(), pdbStream: pdbStream, manifestResources: manifestResources).Diagnostics.Verify(expected);
c.GetEmitDiagnostics(manifestResources: manifestResources).Verify(expected);
return c;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册