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

Update Microsoft.CodeAnalysis.Workspaces.UnitTests to target netcoreapp3.1 #45813

Merged
merged 8 commits into from
Sep 23, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ internal static class ExceptionUtilities
internal static Exception UnexpectedValue(object? o)
{
string output = string.Format("Unexpected value '{0}' of type '{1}'", o, (o != null) ? o.GetType().FullName : "<unknown>");
Debug.Assert(false, output);
#if DEBUG
if (Debugger.IsAttached)
{
Debug.Assert(false, output);
}
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

@tmat This is causing a problem because we expect the ThrowingTraceListener to be active, but it's not taking effect in .NET Core scenarios so we failfast instead.

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem like the right solution. We have Debug.Assert in many places.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any suggestions for how to proceed here?

Copy link
Member

Choose a reason for hiding this comment

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

Do we know why it doesn't work on Core? For now, perhaps we can skip fail-fast on Core.

Copy link
Member Author

@sharwell sharwell Jul 10, 2020

Choose a reason for hiding this comment

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

Do we know why it doesn't work on Core?

Debug.Assert doesn't use trace listeners on .NET Core.

For now, perhaps we can skip fail-fast on Core.

I have not found a way to change this behavior without private reflection, and even if we go that route I'm not sure how to do it from a single location in the xunit startup process. Perhaps a custom MemberData property so it runs during discovery?

Copy link
Member Author

Choose a reason for hiding this comment

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

I discussed this with @stephentoub , and it looks like we can still use ThrowingTraceListener, but we have to add it explicitly:

Trace.Listeners.Clear();
Trace.Listeners.Add(new ThrowingTraceListener());

Copy link
Member

Choose a reason for hiding this comment

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

K. That pattern + module initailizers on .NET Core would seem to essentially cover this issue for us then.

Copy link
Member Author

Choose a reason for hiding this comment

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

What release is the first to support module initializers? Are we already able to add one for the test helper assembly?

Copy link
Member

Choose a reason for hiding this comment

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

The feature has been available in the runtime since 1.0 I believe. The language support will come in C# 9.0. The feature branch should get merged into the main branch sometime next week.

Copy link
Member Author

Choose a reason for hiding this comment

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

This has been updated to use a module initializer to install the trace listener. There are two resulting impacts:

  1. Visual Basic test projects targeting .NET Core cannot use Debug.Assert in any location where assertion might fail. Doing so will cause a FailFast. Workaround: if/when this occurs, make the test class extend TestBase to force module initialization via inheritance.
  2. This PR is now blocked on using the preview language version (Enable usage of preview language features #44485).


// We do not throw from here because we don't want all Watson reports to be bucketed to this call.
return new InvalidOperationException(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.CSharp.UnitTests</RootNamespace>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
Expand All @@ -26,17 +26,6 @@
<ProjectReference Include="..\..\Test\PdbUtilities\Roslyn.Test.PdbUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" Version="$(MicrosoftVisualStudioCodingConventionsVersion)" />
</ItemGroup>
</Project>
4 changes: 0 additions & 4 deletions src/Workspaces/CoreTest/BatchFixAllProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,7 @@ public override Task RegisterCodeFixesAsync(CodeFixContext context)

if (_nested)
{
#if NETCOREAPP2_0 || NET472
fixes = new List<CodeAction> { CodeAction.Create("Container", fixes.ToImmutableArray(), isInlinable: false) };
#else
throw new NotSupportedException("Nested code actions are not supported on this framework.");
#endif
}

foreach (var fix in fixes)
Expand Down
126 changes: 66 additions & 60 deletions src/Workspaces/CoreTest/CodeCleanup/ReduceTokenTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
<UseWpf>true</UseWpf>
<RootNamespace>Microsoft.CodeAnalysis.UnitTests</RootNamespace>
</PropertyGroup>
Expand All @@ -27,10 +27,10 @@
<ProjectReference Include="..\..\Test\PdbUtilities\Roslyn.Test.PdbUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" Version="$(MicrosoftVisualStudioCodingConventionsVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(SystemThreadingTasksDataflowVersion)" />
<PackageReference Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void ExpiredValueNotEqualToNull()
{
var strongNull = ReferenceHolder<object?>.Strong(null);
var weakNull = ReferenceHolder<object?>.Weak(null);
var expired = ReferenceHolder<object?>.TestAccessor.ReleasedWeak(hashCode: EqualityComparer<object?>.Default.GetHashCode(null));
var expired = ReferenceHolder<object?>.TestAccessor.ReleasedWeak(hashCode: EqualityComparer<object?>.Default.GetHashCode(null!));

Assert.Equal(strongNull.GetHashCode(), expired.GetHashCode());
VerifyNotEqual(strongNull, expired);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
<ProjectReference Include="..\..\Core\Portable\Microsoft.CodeAnalysis.Workspaces.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<PackageReference Include="System.Composition" Version="$(SystemCompositionVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" Version="$(MicrosoftVisualStudioCodingConventionsVersion)" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<OptionStrict>Off</OptionStrict>
<VBRuntime>Default</VBRuntime>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net472</TargetFrameworks>
<RootNamespace></RootNamespace>
</PropertyGroup>
<ItemGroup Label="Project References">
Expand All @@ -28,19 +27,10 @@
<ProjectReference Include="..\..\Test\PdbUtilities\Roslyn.Test.PdbUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<PackageReference Include="Microsoft.VisualStudio.CodingConventions" Version="$(MicrosoftVisualStudioCodingConventionsVersion)" />
</ItemGroup>
<ItemGroup>
<Import Include="System.Xml.Linq" />
<Import Include="System.Threading.Tasks" />
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>