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

InlineData duplicate detection fails to detect duplicates between implicitly converted types #2957

Open
JakeYallop opened this issue Jun 22, 2024 · 1 comment

Comments

@JakeYallop
Copy link

Given the following code:

    public const int Const = 1;
    public const byte ConstByte = 1;

    [Theory]
    [InlineData(Const)]
    [InlineData(ConstByte)]
    public void Test(int a) { }

No diagnostics are raised by the analyzer despite both these inputs resulting in exactly the same test being run. Somewhat related to #1742, with the major difference being that these tests run just fine without any issues.

@JakeYallop JakeYallop changed the title InlineData duplicate detection fails to detect duplicates between implicitly widened types InlineData duplicate detection fails to detect duplicates between implicitly converted types Jun 23, 2024
@bradwilson
Copy link
Member

I'm a little torn on whether this should be raised or not, but I've tagged it to be fixed.

The original purpose of the analyzer is to identify when tests are going to end up having the same serialization and therefore only get run once in VSTest.

Here's what it looks like with your original code:

image

And here's what it looks like when using two ints:

image

So we do actually run it twice rather than once when the input values are different, even if they eventually get coerced into the same type on the other side.

The reason I'm willing to leave this open is that it's probably the case that the developer made a mistake here (even though in this unusual iteration, they'll both get run anyways). It goes beyond the scope of the original purpose of the analyzer (to help people who have questions about why their test ran once instead of twice), but it feels like a good expansion of value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants