-
Notifications
You must be signed in to change notification settings - Fork 758
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
xUnit1010 is triggered for strings which are convertible to decimal / int #2354
Comments
Probably analyzer should be updated in a similar fashion to xunit/xunit.analyzers#97 . |
In this specific example, the test runner would be using Convert.ChangeType. Since the argument to InlineData is a string, which implements IConvertable, shouldn't the analyzer just check if the source argument's type implements IConvertable and the corresponding method parameter is one of the 15 standard types supported by the CLR, using matrix defined at https://github.com/microsoft/referencesource/blob/master/mscorlib/system/convert.cs You already have the 3 char special cases in the numerical conversion, so any fall should defer to runtime cast failures, yes ? Therefore I don't think a version check should be required |
I've played with checking IConvertable support... there are a lot of cases that previously would be reported as a failure that would now be allowed. Numerics <-> bool If you ignore the error (via pragma), all the above cases will work in practice. But doesn't mean the system should condone it. Maybe convert to a warning ? |
Also Enum -> string |
But not the reverse |
The problem is that // The ToXXX methods convert the value of the underlying object to the
// given type. If a particular conversion is not supported, the
// implementation must throw an InvalidCastException. If the value of the
// underlying object is not within the range of the target type, the
// implementation must throw an OverflowException. The
// IFormatProvider will be used to get a NumberFormatInfo or similar
// appropriate service object, and may safely be null. There are several exceptional situations that it makes sense to wait until runtime to discover, but the "always fails with I think the better logic here would be to stick to things which are known to convert, though even there I'm concerned about how that logic table gets updated over time. Maybe it's overthinking it, as the list of built-in types doesn't really grow often. But that's the way I would lean is to basically just copy the support table into code and do a lookup against that. |
The test above works fine, as string value is converted to decimal internally. Still, xUnit1010 is produced (with Error priority by default).
The text was updated successfully, but these errors were encountered: