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

NRE in AnalyzePositionalArgumentsAndParameters #11

Closed
mikkelbu opened this issue Dec 5, 2017 · 1 comment · Fixed by #60
Closed

NRE in AnalyzePositionalArgumentsAndParameters #11

mikkelbu opened this issue Dec 5, 2017 · 1 comment · Fixed by #60
Assignees
Labels
Milestone

Comments

@mikkelbu
Copy link
Member

mikkelbu commented Dec 5, 2017

In the method TestCaseUsageAnalyzer.AnalyzePositionalArgumentsAndParameters there is the assumption that all expressions in the attribute has type LiteralExpressionSyntax. This is not always the case. The assumption fails in e.g. nunit.nunit\src\NUnitFramework\tests\Constraints\MsgUtilTests.cs, where we have the constant s52 which hence has type IdentifierNameSyntax.

        private const string s52 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

        [TestCase(s52, 52, 0, s52, TestName="NoClippingNeeded")]
        [TestCase(s52, 29, 0, "abcdefghijklmnopqrstuvwxyz...", TestName="ClipAtEnd")]
        [TestCase(s52, 29, 26, "...ABCDEFGHIJKLMNOPQRSTUVWXYZ", TestName="ClipAtStart")]
        [TestCase(s52, 28, 26, "...ABCDEFGHIJKLMNOPQRSTUV...", TestName="ClipAtStartAndEnd")]
        public static void TestClipString(string input, int max, int start, string result)
        {
            System.Console.WriteLine("input=  \"{0}\"", input);
            System.Console.WriteLine("result= \"{0}\"", result);
            Assert.That(MsgUtils.ClipString(input, max, start), Is.EqualTo(result));
        }
@mikkelbu mikkelbu added the bug label Jan 17, 2018
@mikkelbu
Copy link
Member Author

mikkelbu commented Jun 13, 2018

It also fails in the following cases:

  • When the argument is a negative number -4 => PrefixUnaryExpressionSyntax.
  • When the argument is a cast => CastExpressionSyntax.

mikkelbu added a commit to mikkelbu/nunit.analyzers that referenced this issue Jun 13, 2018
The value was not used and only worked for literal expressions.

Fixes nunit#11
@mikkelbu mikkelbu self-assigned this Jun 13, 2018
@mikkelbu mikkelbu added this to the Release 0.2 milestone Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant