Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent inlining to guarantee stack frames in test #3002

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System.Runtime.CompilerServices;
using Xunit;

namespace Microsoft.IdentityModel.Tokens.Tests
Expand All @@ -10,29 +11,33 @@ public class ValidationErrorTests
[Fact]
public void ExceptionCreatedFromValidationError_ContainsTheRightStackTrace()
{
var validationError = new ValidationErrorReturningClass().firstMethod();
var validationError = new ValidationErrorReturningClass().FirstMethod();
Assert.NotNull(validationError);
Assert.NotNull(validationError.StackFrames);
Assert.Equal(3, validationError.StackFrames.Count);
Assert.NotNull(validationError.GetException());
Assert.NotNull(validationError.GetException().StackTrace);
Assert.Equal("thirdMethod", validationError.StackFrames[0].GetMethod().Name);
Assert.Equal("secondMethod", validationError.StackFrames[1].GetMethod().Name);
Assert.Equal("firstMethod", validationError.StackFrames[2].GetMethod().Name);
Assert.Equal("ThirdMethod", validationError.StackFrames[0].GetMethod().Name);
Assert.Equal("SecondMethod", validationError.StackFrames[1].GetMethod().Name);
Assert.Equal("FirstMethod", validationError.StackFrames[2].GetMethod().Name);
}

class ValidationErrorReturningClass
{
public ValidationError firstMethod()
[MethodImpl(MethodImplOptions.NoInlining)]
public ValidationError FirstMethod()
{
return secondMethod().AddCurrentStackFrame();
return SecondMethod().AddCurrentStackFrame();
}

public ValidationError secondMethod()
[MethodImpl(MethodImplOptions.NoInlining)]
public ValidationError SecondMethod()
{
return thirdMethod().AddCurrentStackFrame();
return ThirdMethod().AddCurrentStackFrame();
}

public ValidationError thirdMethod()
[MethodImpl(MethodImplOptions.NoInlining)]
public ValidationError ThirdMethod()
{
return new ValidationError(
new MessageDetail("This is a test error"),
Expand Down
Loading