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

Adopt Microsoft.DotNet.XunitAssert fork #86193

Closed
wants to merge 1 commit into from

Conversation

agocke
Copy link
Member

@agocke agocke commented May 12, 2023

Start using Microsoft.DotNet.XUnitAssert instead of assert.xunit.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 12, 2023
@ghost ghost assigned agocke May 12, 2023
agocke added a commit to agocke/arcade that referenced this pull request May 13, 2023
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did these change?

Copy link
Member Author

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:

  1. Make the change above
  2. Revert the xunit source to an older version which doesn't have this change
  3. Raise the change as an issue in the xunit.assert repo as a potential breaking change.

Do you have any preferences?

Copy link
Member

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.
Copy link
Member

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.

Copy link
Member

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?)

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.
Copy link
Member

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?

Comment on lines 14 to 16
<!-- 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'" />
Copy link
Member

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.

Comment on lines 110 to 112
<!-- 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'"/>
Copy link
Member

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

Comment on lines 142 to 146
<ItemGroup>
<!-- Fixup arcade test references by removing xunit" -->
<PackageReference Remove="xunit" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<PackageReference Remove="xunit.assert" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 21 to 23
<!-- 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'" />
Copy link
Member

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)" />
Copy link
Member

@ViktorHofer ViktorHofer May 15, 2023

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?

Copy link
Member Author

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.

agocke added a commit to dotnet/arcade that referenced this pull request May 18, 2023
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.
@danmoseley danmoseley added area-Infrastructure and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 1, 2023
@ghost
Copy link

ghost commented Jun 1, 2023

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Issue Details

Start using Microsoft.DotNet.XUnitAssert instead of assert.xunit.

Author: agocke
Assignees: agocke
Labels:

area-Infrastructure

Milestone: -

@ghost
Copy link

ghost commented Jul 27, 2023

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@ghost ghost locked as resolved and limited conversation to collaborators Aug 27, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants