-
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
Allow CollectionAttribute to reference a definition class directly #2878
Conversation
…not needed as a separate step
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.
I haven't really looked at the tests yet, as I wanted to see the impact on the production code first, and a few more things popped out to me as I did that. Thoughts?
I'm going to add tests for the |
Awesome! I'll look into making changes to the analyzer to compensate once this goes in. |
This is becoming...a large change to get this all working the way I want. I think I might end up doing it in the context of the |
Understood. |
This is the commit: 02175c7
Yeah. 😂 I'll get it merged and resolved, since I stepped on you a little bit, and see how everything is playing out after that. |
MotherOfGod.jpg |
I've got a flaky test situation going on. I'm going to push the merge but I'm still looking through things to see if I can figure out where the problem is. |
By any chance is the flaky test MessageBusTests.QueueReturnsFalseForFailIfStopOnFailTrue? |
It's definitely somehow related to caching, and I didn't just introduce it now, because running back a couple steps into your history was broken. I had to make some surgical changes because it wouldn't fail just run by itself (being cache related) so I updated _TestFailed to print its messages and tweaked the failing tests a little so I could see them, and this is what I'm seeing: There are three tests that I see that fail, and which one fails is a bit random because of the randomization of test runs. The classes under test look like this: [Collection(typeof(CollectionWithClassFixtureCounter))]
class ClassWithCountedFixture : IClassFixture<CountedFixture>
{
public ClassWithCountedFixture(CountedFixture fixture)
{
// 1 == test collection, 2 == test class
Assert.Equal(2, fixture.Identity);
}
[Fact]
public void TheTest() { }
}
I suspect it's because you copied the original test two times, but they're all sharing the same static state. Testing that theory now... |
Yep, that's it. I just need to move a copy of the CountedFixture up into each place where it's used so they each have their own static state and not one shared static state for all 3. :) |
Oof. Sorry. Thanks for catching that. That would explain why the tests were passing in isolation when I ran them. It's odd, I had no trouble getting this test to get picked up by the test runner, but I'm not able to get one to show up on a different change I'm making that's also blocked on .Net 7 or higher. I'll take a crack at an analyzer for this issue next once this gets merged. |
As an aside, I was able to use generic attributes in my tests for all of .NET Framework 4.7.2. and .NET 6. I don't think .NET 8 is necessary for those. All I needed to make sure was that I had access to C# 11. Example: |
Ooh, nice! The other item I was looking at is static interface virtual methods, which I think does require .Net 7 or higher sadly. |
Yeah, there's no need for me to roll back the .NET 8 test support, it'll eventually be needed. I just don't think we need the guards on these tests. |
Well, I ran into a problem. The tests for I'm super reluctant to diverge the code base of |
Oof. Yeah, that's a problem, and I don't have any immediate ideas either. |
One option is to keep |
At the very least, we could split the PR in two and check in the |
Does making |
Unfortunately that means unsealing I'll poke around with reflection in .NET Framework and see if I can understand what's going on, but I'm not super hopeful that I'm going to find a magic way out. |
Hmm, interesting. using System;
using Xunit;
namespace Empty;
class Attribute1<T> : Attribute { }
[Attribute1<TestClass>]
public class TestClass
{
[Fact]
public void TestMethod()
{
var attributes = typeof(TestClass).CustomAttributes;
Assert.Empty(attributes);
}
} Results in: .NET Framework:
.NET 6:
So it's there, but the type is mangled somehow. |
Reason number 420 why I'll be glad when Framework is finally put out to pasture, that's absolutely maddening. :-( |
This tends to imply that (a) runtime support was required to make generic attributes work, and (b) such runtime support was only added to .NET Core, and not .NET Framework. Not a solid confirmation, but pretty strongly suggestive. |
Oddly enough it works correctly if you use a builtin type (though that of course isn't helpful to us). .NET Framework: .NET 6: |
I'm going to see if I can make this work with reference assemblies. I might be able to multi-target the build of |
Local package creation and testing looked good. Intellisense and references looked correct; |
…TestCollectionFactory behave the same
… to the same collection
I think this is ready for your review if you'd like, @JamesTerwilliger. I'll merge if you're satisfied. |
@bradwilson I'm looking now, but it looks as if the PR builds are failing still (non-windows only?) |
Fixing the non-Windows issue right now. |
Found and fixed one spelling error, code itself looks good (well, good is relative given all of the ID mangling magic that needed to happen in a couple of places, but the logic looks sound) @bradwilson #ShipIt |
Once the packages are pushed to feedz.io I'll do one last test to ensure things are working as expected. Don't think I should see any surprises here but you never know. 😂 |
@bradwilson Nicely done, sir! |
Attempted fix for #2629
This PR allows CollectionAttribute some flexibility in referencing a collection definition/fixture. It gives two new options:
CollectionAttribute<TCollectionDefinition>
as a generic way to also reference the fixture classMore tests to come