TUnit
TUnit copied to clipboard
Invalid attribute arguments break the generator and cause multiple Roslyn service crashes in VS
The generator completely crashes when an invalid argument is provided in any of the generator-driven attributes. In my example, just a bad nameof panics the entire flow, with the following error dump on any of the internal error warnings in VS.
StreamJsonRpc.RemoteInvocationException: Index was outside the bounds of the array.
at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__20`1.MoveNext()
RPC server exception:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.MethodDataSourceRetriever.<>c__DisplayClass0_0.<ParseMethodData>b__0(IMethodSymbol x)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.MethodDataSourceRetriever.ParseMethodData(GeneratorAttributeSyntaxContext context, ImmutableArray`1 parameterOrPropertyTypes, INamedTypeSymbol namedTypeSymbol, AttributeData methodDataAttribute, ArgumentsType argumentsType, Int32 index)
at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.ArgumentsRetriever.GetArguments(GeneratorAttributeSyntaxContext context, ImmutableArray`1 parameters, IPropertySymbol property, ImmutableArray`1 parameterOrPropertyTypes, ImmutableArray`1 dataAttributes, INamedTypeSymbol testClass, IMethodSymbol testMethod, ArgumentsType argumentsType, String propertyName)+MoveNext()
at TUnit.Core.SourceGenerator.CodeGenerators.Helpers.TestSourceDataModelRetriever.ParseTestDatas(IMethodSymbol methodSymbol, GeneratorAttributeSyntaxContext context, INamedTypeSymbol namedTypeSymbol)+MoveNext()
[... manually truncated]
A quick example of a break:
[Test]
[MethodDataSource(nameof())]
public async Task TestDocumentCharacterCount(
DocumentCharacterCountTestCase testCase)
{
}
Does an empty nameof compile?
No, but it only yields an error without causing service crashes. When this is applied to any of the analyzed attributes, multiple Roslyn service crash warnings popup, text fizzles, and it seems impossible to recover without restarting VS.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue was closed because it has been stalled for 5 days with no activity.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.