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

Bug: StackOverflowException when test calls recursive method in 3.7. #602

Closed
andrewimcclement opened this issue Sep 26, 2023 · 3 comments · Fixed by #604
Closed

Bug: StackOverflowException when test calls recursive method in 3.7. #602

andrewimcclement opened this issue Sep 26, 2023 · 3 comments · Fixed by #604
Assignees

Comments

@andrewimcclement
Copy link
Contributor

Using .NET Framework 4.8.
This builds fine using NUnit.Analyzers 3.5.0 but fails in 3.7.0 (and 3.8.0):

using System;
using System.Collections.Generic;

using NUnit.Framework;

namespace Namespace
{
    internal class Fixture
    {
        private Dictionary<string, bool> _values = new Dictionary<string, bool>();

        [Test]
        public void MinimalRepro()
        {
            Recurse("help");
        }

        private void Recurse(string one, bool keepGoing=true)
        {
            _values[one] = keepGoing;
            if (keepGoing)
            {
                Recurse(one, false);
            }
        }
    }
}

Error looks like
image
I don't have time to actually debug the analyser right now but I hope this repro is small enough to make it easy.

@manfred-brands
Copy link
Member

@andrewimcclement Thanks for reporting.

I think I know where the issue is, I just didn't think of recursion when implementing this.

@manfred-brands
Copy link
Member

@andrewimcclement There are a few possible workarounds for you:

  1. Disable NUnit1032 in the class with the recursive method(s) using: #pragma warning disable NUnit1032
  2. Disable NUnit1032 for the whole project using: dotnet_diagnostic.NUnit1032.severity = none
  3. Move the recursive method to a local function or nested class as the analyzer only checks methods in the same class.
  4. Use the NuGet package created from the PR build artifacts

@andrewimcclement
Copy link
Contributor Author

Thanks for the workarounds. I think I'll probably go with number 2 until a new version is out with the fix, as if it appears elsewhere, it is non-obvious what the fix is for other people in my team. Many thanks for the speedy investigation.

@mikkelbu mikkelbu added this to the Release 3.9 / 2.9 milestone Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants