Update for new frameworks

This commit is contained in:
Ben Adams 2021-01-03 15:51:28 +00:00
parent a5ae4e6391
commit 6d7a54cd84
5 changed files with 60 additions and 8 deletions

View File

@ -663,8 +663,13 @@ namespace System.Diagnostics
{
return false;
}
if (type == typeof(Task))
if (type == typeof(Task) || type.DeclaringType == typeof(Task))
{
if (method.Name.Contains(".cctor"))
{
return false;
}
switch (method.Name)
{
case "ExecuteWithThreadLocal":
@ -672,15 +677,24 @@ namespace System.Diagnostics
case "ExecutionContextCallback":
case "ExecuteEntry":
case "InnerInvoke":
case "ExecuteEntryUnsafe":
case "ExecuteFromThreadPool":
case "s_ecCallback":
return false;
}
}
if (type == typeof(ExecutionContext))
{
if (method.Name.Contains(".cctor"))
{
return false;
}
switch (method.Name)
{
case "RunInternal":
case "Run":
case "RunFromThreadPoolDispatchLoop":
return false;
}
}

View File

@ -60,9 +60,8 @@ namespace System.Diagnostics
}
var genericPartIndex = type.Name.IndexOf('`');
Debug.Assert(genericPartIndex >= 0);
return type.Name.Substring(0, genericPartIndex);
return (genericPartIndex >= 0) ? type.Name.Substring(0, genericPartIndex) : type.Name;
}
private static void ProcessType(StringBuilder builder, Type type, DisplayNameOptions options)

View File

@ -37,14 +37,28 @@ namespace Ben.Demystifier.Test
var trace = string.Join("", stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
// Remove items that vary between test runners
.Where(s =>
s != " at Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()+() => { }" &&
!s.Contains("System.Threading.Tasks.Task.WaitAll")
(s != " at Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()+() => { }" &&
!s.Contains("System.Threading.Tasks.Task.WaitAll"))
)
.Skip(1)
.ToArray())
// Remove Full framework back arrow
.Replace("<---", "");
#if NET5_0 || NETCOREAPP3_1
var expected = string.Join("", new[] {
" ---> System.ArgumentException: Value does not fall within the expected range.",
" at async Task Ben.Demystifier.Test.AggregateException.Throw1()",
" at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }",
" --- End of inner exception stack trace ---",
" at void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()",
" ---> (Inner Exception #1) System.NullReferenceException: Object reference not set to an instance of an object.",
" at async Task Ben.Demystifier.Test.AggregateException.Throw2()",
" at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }",
" ---> (Inner Exception #2) System.InvalidOperationException: Operation is not valid due to the current state of the object.",
" at async Task Ben.Demystifier.Test.AggregateException.Throw3()",
" at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }"
});
#else
var expected = string.Join("", new[] {
" at async Task Ben.Demystifier.Test.AggregateException.Throw1()",
" at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }",
@ -59,7 +73,7 @@ namespace Ben.Demystifier.Test
"---> (Inner Exception #2) System.InvalidOperationException: Operation is not valid due to the current state of the object.",
" at async Task Ben.Demystifier.Test.AggregateException.Throw3()",
" at async void Ben.Demystifier.Test.AggregateException.DemystifiesAggregateExceptions()+(?) => { }"});
#endif
Assert.Equal(expected, trace);
}

View File

@ -44,6 +44,7 @@ namespace Ben.Demystifier.Test
s != " at void System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, object state)" &&
s != " at Task Ben.Demystifier.Test.DynamicCompilation.DoesNotPreventStackTrace()+() => { }"
)
.Select(s => Regex.Replace(s, "lambda_method[0-9]+\\(", "lambda_method("))
.ToArray();
Assert.Equal(

View File

@ -31,13 +31,24 @@ namespace Ben.Demystifier.Test
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
var trace = stackTrace.Split(new[]{Environment.NewLine}, StringSplitOptions.None);
#if NETCOREAPP3_1 || NET5_0
Assert.Equal(
new[] {
"System.Exception: Exception of type 'System.Exception' was thrown. ---> System.Exception: Exception of type 'System.Exception' was thrown.",
"System.Exception: Exception of type 'System.Exception' was thrown.",
" ---> System.Exception: Exception of type 'System.Exception' was thrown.",
" at Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()+() => { }",
" at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()",
" --- End of inner exception stack trace ---"},
trace);
#else
Assert.Equal(
new[] {
"System.Exception: Exception of type 'System.Exception' was thrown. ---> System.Exception: Exception of type 'System.Exception' was thrown.",
" at Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()+() => { }",
" at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()",
" --- End of inner exception stack trace ---"},
trace);
#endif
// Act
try
@ -54,6 +65,18 @@ namespace Ben.Demystifier.Test
stackTrace = LineEndingsHelper.RemoveLineEndings(stackTrace);
trace = stackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
#if NETCOREAPP3_1 || NET5_0
Assert.Equal(
new[] {
"System.Exception: Exception of type 'System.Exception' was thrown.",
" ---> System.Exception: Exception of type 'System.Exception' was thrown.",
" at Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()+() => { }",
" at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()",
" --- End of inner exception stack trace ---",
" at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()"
},
trace);
#else
Assert.Equal(
new[] {
"System.Exception: Exception of type 'System.Exception' was thrown. ---> System.Exception: Exception of type 'System.Exception' was thrown.",
@ -63,6 +86,7 @@ namespace Ben.Demystifier.Test
" at async Task Ben.Demystifier.Test.NonThrownException.DoesNotPreventThrowStackTrace()"
},
trace);
#endif
}
[Fact]