-
Notifications
You must be signed in to change notification settings - Fork 748
Fixes #2970 InvalidCastException @ NUnit.Framework.TestFixtureSourceAttribute.BuildFrom #2971
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
Conversation
Thanks for taking the time! Getting @nunit/framework-team's attention since there isn't a discussion issue.
Perhaps we should link this from the readme: https://github.com/nunit/nunit/blob/master/BUILDING.md#build-script |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides the typo.
} | ||
|
||
[TestFixtureSource(typeof(GenericFixtureWithTypeAndConstructorArgsSource), "Source")] | ||
public class GenerixFixtureSourceWithTypeAndConstructorArgs<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo Generix
@BrunoJuchli I noticed that this test is failing :
For suggestions on how to run tests locally other than BUILDING.md, see #2973. :D |
Isn't the (discussion) issue #2970 (or am I overlooking something)? @BrunoJuchli I've edited your message to mention #2970, so that the issue and PR will be linked (and also such that the PR will auto close the issue when merged). Mentioning it in the titel will not work as far as I know. |
@@ -109,7 +108,7 @@ public IEnumerable<TestSuite> BuildFrom(Type type) | |||
{ | |||
Type sourceType = SourceType ?? type; | |||
|
|||
foreach (TestFixtureParameters parms in GetParametersFor(sourceType)) | |||
foreach (ITestFixtureData parms in GetParametersFor(sourceType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also remove the same unnecessary cast below? (https://github.com/nunit/nunit/pull/2971/files#diff-a7991f3c3308d3394ecebfc7b72ba252R128)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikkelbu
I guess that's why the test is failing. Will have a look.
Thanks!
} | ||
} | ||
|
||
[TestFixtureSource(typeof(GenericFixtureWithTypeAndConstructorArgsSource), "Source")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about "Source"
=> nameof(GenericFixtureWithTypeAndConstructorArgsSource.Source)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mikkelbu
I implemented it like that at first but then I wasn't sure whether that would be supported by the compiler c# level and what the project's preference is.
All other examples in the same file use constant strings instead of the nameof(...)
operator.
If nameof
is fine I'll create a separate pull request to modify all string references - across the whole project - to types/members to use nameof(...)
- that would make sense, right?
I guess a passing build + passing tests should be conclusive about whether nameof(...)
is supported? Or does it need to be compiled on other platforms, too? (I've got windows + net)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The projects are all set to C# 6.0, so if you don't get a error squiggle, you're fine.
In typeof(...), nameof(...)
cases like this with so much repetition, I'm not totally happy with any of our options :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jnm2 thanks!
I'd be happy to provide a PR to change string-constants to nameof(..)
, only adjust the newly introduced usages, or open a new issue to discuss the topic.
However, I'm not in a position to decide which is the right way to go so I'll refrain from doing anything regarding this topic until I get instructions ;-)
}; | ||
} | ||
|
||
[TestFixtureSource(typeof(GenericFixtureWithConstructorArgsSource), "Source")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above
Thanks @mikkelbu, the issue had escaped my notice. |
@jnm2 @mikkelbu Regarding a) leave it as it is I personally would favor b) for improved refactor-safety. But I'll leave the decision to you guys, of course. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
With respect to nameof(...)
then I would also say option b), but to begin with just in the test-project. @nunit/framework-team What do you think?
Yep, I agree |
We've already done some work towards a I think we're all on board with going further. My viewpoint has been that |
Hi @nunit/framework-team can one of you do a second review, so that we can merge this in, as it is closing an issue which is part of the 3.11 milestone. Then we can always create a subsequent task wrt. |
@@ -126,7 +122,7 @@ public IEnumerable<TestSuite> BuildFrom(Type type, IPreFilter filter) | |||
{ | |||
Type sourceType = SourceType ?? type; | |||
|
|||
foreach (TestFixtureParameters parms in GetParametersFor(sourceType)) | |||
foreach (ITestFixtureData parms in GetParametersFor(sourceType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for doing this! This has bugged me for a while. I thought it was due to having to use the type name instead of var
which silently introduces a possible invalid cast exception when the method return type is changed.
Fixes #2970
I've done three things:
Question: how can / should I run the tests included in the nunit solution locally? I've not found any documentation on this.