-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Adopt Microsoft.DotNet.XunitAssert fork #86193
Conversation
I found a few bugs in trying to enable dotnet/runtime#86193. One is that there's no way to flip Arcade to pull in the fork package instead of xunit.assert. The second is that when both are pulled in, because the fork has a different assembly name, the references are ambiguous and produce compile-time breaks. Matching names seems like it will get rid of that problem, and it also has the side-effect of letting the analyzer work properly against the fork.
@@ -316,7 +316,7 @@ public void DeserializeSortedSet() | |||
""3"" | |||
]"; | |||
|
|||
ImmutableSortedSet<string> data = JsonSerializer.Deserialize<ImmutableSortedSet<string>>(json); | |||
ISet<string> data = JsonSerializer.Deserialize<ImmutableSortedSet<string>>(json); |
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.
Why did these change?
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.
Ah, interesting case!
So, this is a breaking change, but not one caused by me. The latest source for Xunit.Assert contains an overload for both IReadOnlySet
and ISet
. That makes this overload ambiguous.
I'm not sure the best way to handle this. This was the easiest way I could think to make progress.
For options I think we could:
- Make the change above
- Revert the xunit source to an older version which doesn't have this change
- Raise the change as an issue in the xunit.assert repo as a potential breaking change.
Do you have any preferences?
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.
Seems reasonable to just accommodate the change.
@@ -0,0 +1,154 @@ | |||
// Licensed to the .NET Foundation under one or more agreements. |
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.
Can you put this file into Common somewhere? It's not specific to regex.
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.
(A comment in the file would also be helpful indicating what it is... it appears to be a copy of a file from the old testing package that was being used?)
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.
Might also be useful to include a link to the original source as a code comment.
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.
Yes, this is from the Roslyn SDK, and I just copied the source over. The Roslyn SDK contains a reference to xunit.assert, which was causing problems. However, my changes in dotnet/arcade#13510 may make this obsolete.
The problems come from xunit.assert and Microsoft.DotNet.XUnitAssert having different assembly names -- so when both are included, all references are ambiguous. The alternative approach I'm proposing in that PR is to share the assembly name. Aside from making the XUnit analyzers work (which I think is a big benefit), it will remove these kinds of conflicts because I will no longer have to remove all shared references, and can instead rely on the Dotnet XunitAssert winning because it is higher version.
I'm ambivalent about the assembly name change, but after trying to fix a ton of these one-off issues, I'm warming up to it.
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.
IMO the assembly name changes is fine - we did the same with the Microsoft.DotNet.XUnitConsoleRunner: https://github.com/dotnet/arcade/blob/2d8d59065b5e090584a8e90c4371fc06ed60bdc5/src/Microsoft.DotNet.XUnitConsoleRunner/src/Microsoft.DotNet.XUnitConsoleRunner.csproj#L6
Avoiding renaming the assembly name between the upstream and the fork should be less breaking.
@@ -0,0 +1,154 @@ | |||
// Licensed to the .NET Foundation under one or more agreements. | |||
// The .NET Foundation licenses this file to you under the MIT license. | |||
// See the LICENSE file in the project root for more information. |
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.
Most of our files use the two line license:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
Is there a specific reason this one needs to be different? Or is this the license from where the file was copied from?
eng/testing/xunit/xunit.props
Outdated
<!-- Use dotnet/runtime fork of assert.xunit if netcore, otherwise use xunit.assert package. --> | ||
<PackageReference Include="Microsoft.DotNet.XUnitAssert" Version="$(MicrosoftDotNetXUnitAssertVersion)" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'"/> | ||
<PackageReference Include="xunit.assert" Version="$(XUnitVersion)" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" /> |
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 Microsoft.DotNet.XUnitAssert package only works on .NETCoreApp. Therefore I would instead condition on TFI == .NETCoreApp and TFI != .NETCoreApp.
<!-- Use dotnet/runtime fork of assert.xunit if netcore, otherwise use xunit.assert package. --> | ||
<PackageReference Include="Microsoft.DotNet.XUnitAssert" Version="$(MicrosoftDotNetXUnitAssertVersion)" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'"/> | ||
<PackageReference Include="xunit.assert" Version="$(XUnitVersion)" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'"/> |
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 as above, change TFI condition to .NETCoreApp
<ItemGroup> | ||
<!-- Fixup arcade test references by removing xunit" --> | ||
<PackageReference Remove="xunit" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" /> | ||
<PackageReference Remove="xunit.assert" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" /> | ||
</ItemGroup> |
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.
Remove this. We don't use Arcade's test framework: https://github.com/dotnet/runtime/blob/80ffe5c713b87524aa87085cff81d09daf8c65b4/src/libraries/Directory.Build.props#LL3C3-L3C3
<!-- Use dotnet/runtime fork of assert.xunit if netcore, otherwise use xunit.assert package. --> | ||
<PackageReference Include="Microsoft.DotNet.XUnitAssert" Version="$(MicrosoftDotNetXUnitAssertVersion)" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'"/> | ||
<PackageReference Include="xunit.assert" Version="$(XUnitVersion)" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" /> |
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.
Microsoft.Extensions.DependencyInjection.Specification.Tests is a shipping package which must not rely on non-shipping packages (Microsoft.DotNet.XUnitAssert).
@@ -72,7 +73,7 @@ | |||
<Compile Include="$(CommonTestPath)System\Diagnostics\DebuggerAttributes.cs" Link="Common\System\Diagnostics\DebuggerAttributes.cs" /> | |||
|
|||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisVersion)" PrivateAssets="all" /> | |||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="$(CompilerPlatformTestingVersion)" /> | |||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="$(CompilerPlatformTestingVersion)" /> |
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 assume you changed this as the package brings xunit.assert in transitively? What if we would make sure that Microsoft.DotNet.XUnitAssert's assembly identity matches xunit.assert's one. Would we then be able to consume such packages by excluding their transitives?
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.
Yup, this is the approach I took in dotnet/arcade#13510. If that sounds good to you, I will take that change and then retry this PR on top of that. A whole lot of problems will go away.
I found a few bugs in trying to enable dotnet/runtime#86193. One is that there's no way to flip Arcade to pull in the fork package instead of xunit.assert. The second is that when both are pulled in, because the fork has a different assembly name, the references are ambiguous and produce compile-time breaks. Matching names seems like it will get rid of that problem, and it also has the side-effect of letting the analyzer work properly against the fork.
Tagging subscribers to this area: @dotnet/runtime-infrastructure Issue DetailsStart using Microsoft.DotNet.XUnitAssert instead of assert.xunit.
|
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
Start using Microsoft.DotNet.XUnitAssert instead of assert.xunit.