Skip to content

Commit

Permalink
Use live reference pack for IntrinsicsInSystemPrivatecorelibAnalyzer.…
Browse files Browse the repository at this point in the history
…Tests (dotnet#93721)

This avoids an issue where the analyzer test tries to restore reference assemblies from nuget.org during the test. We already have helpers in place to use the live reference pack instead.

Fixes dotnet#90951
Fixes dotnet#93103
  • Loading branch information
akoeplinger authored Oct 20, 2023
1 parent 0151c46 commit 7d471fa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace IntrinsicsInSystemPrivateCoreLib.Test
Expand All @@ -11,6 +12,11 @@ public class Test : CSharpAnalyzerTest<TAnalyzer, XUnitVerifier>
{
public Test()
{
// Clear out the default reference assemblies. We explicitly add references from the live ref pack,
// so we don't want the Roslyn test infrastructure to resolve/add any default reference assemblies
ReferenceAssemblies = new ReferenceAssemblies(string.Empty);
TestState.AdditionalReferences.AddRange(SourceGenerators.Tests.LiveReferencePack.GetMetadataReferences());

SolutionTransforms.Add((solution, projectId) =>
{
var compilationOptions = solution.GetProject(projectId).CompilationOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TestRunRequiresLiveRefPack>true</TestRunRequiresLiveRefPack>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,6 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\..\gen\System.Private.CoreLib.Generators.csproj" />
<Compile Include="$(CommonTestPath)SourceGenerators\LiveReferencePack.cs" Link="Common\SourceGenerators\LiveReferencePack.cs" />
<Compile Include="IntrinsicsInSystemPrivateCoreLibUnitTests.cs" />
<Compile Include="CSharpAnalyzerVerifier`1.cs" />
<Compile Include="CSharpAnalyzerVerifier`1+Test.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace IntrinsicsInSystemPrivateCoreLib.Test
{
[SkipOnPlatform(TestPlatforms.Browser, "Do not try to run analyzer tests in the browser")]
public class IntrinsicsInSystemPrivateCoreLibUnitTest
{
string BoilerPlate = @"
Expand Down Expand Up @@ -90,7 +89,6 @@ class PackedSimd
";
[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedUse()
{
var test = BoilerPlate + @"
Expand All @@ -110,7 +108,6 @@ static void FuncBad()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedUseWithIntrinsicsHelperAttribute()
{
var test = BoilerPlate + @"
Expand All @@ -131,7 +128,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedUseWithIntrinsicsHelperAttributeComplex()
{
var test = BoilerPlate + @"
Expand All @@ -157,7 +153,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedUseInLocalFunctionWithIntrinsicsHelperAttributeNotOnLocalFunction()
{
var test = BoilerPlate + @"
Expand All @@ -183,7 +178,6 @@ static void LocalFunc()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedUseInLambdaWithIntrinsicsHelperAttributeOnOuterFunction()
{
var test = BoilerPlate + @"
Expand All @@ -209,7 +203,6 @@ static void FuncBad()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedUseInLocalFunctionWithIntrinsicsHelperAttributeOnLocalFunction()
{
var test = BoilerPlate + @"
Expand All @@ -235,7 +228,6 @@ static void LocalFunc()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUnprotectedNestedTypeUse()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -275,7 +267,6 @@ static void FuncGood()


[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithIfStatementButWithInadequateHelperMethodAttribute()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -317,7 +308,6 @@ static void FuncBad()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithIfStatementWithNestedAndBaseTypeLookupRequired()
{
var test = BoilerPlate + @"
Expand All @@ -337,7 +327,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithTernaryOperator()
{
var test = BoilerPlate + @"
Expand All @@ -356,7 +345,6 @@ static bool FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithIfStatementWithOrOperationCase()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -386,7 +374,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithIfStatementWithOrOperationCaseWithImplicationProcessingRequired()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -416,7 +403,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithIfStatementAroundLocalFunctionDefinition()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -446,7 +432,6 @@ void LocalFunction()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodWithIfStatementAroundLambdaFunctionDefinition()
{
var test = BoilerPlate + @"
Expand All @@ -473,7 +458,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestHelperMethodsCanOnlyBeCalledWithAppropriateIsSupportedChecksError()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -524,7 +508,6 @@ static void FuncBad()
await VerifyCS.VerifyAnalyzerAsync(test, expected, expected2, expected3, expected4, expected5);
}
[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestHelperMethodsCanOnlyBeCalledWithAppropriateIsSupportedChecksSuccess()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -565,7 +548,6 @@ static void FuncGood()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestHelperMethodsUnrelatedPropertyDoesntHelp()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -596,7 +578,6 @@ static void FuncBad()
}

[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestHelperMethodsWithHelperProperty()
{
var test = BoilerPlate + @"
Expand Down Expand Up @@ -627,7 +608,6 @@ static void FuncGood()


[Fact]
[SkipOnPlatform(TestPlatforms.LinuxBionic, "https://github.com/dotnet/runtime/issues/93103")]
public async Task TestMethodUseOfIntrinsicsFromWithinOtherMethodOnIntrinsicType()
{
var test = @"
Expand Down
10 changes: 5 additions & 5 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetsMobile)' == 'true' or '$(TargetsLinuxBionic)' == 'true' or '$(TargetArchitecture)' == 'ARMv6'">
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\LibraryImportGenerator.Tests\LibraryImportGenerator.Tests.csproj" />
<!-- don't run source generator or roslyn analyzer tests on mobile -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\ComInterfaceGenerator.Tests\ComInterfaceGenerator.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\LibraryImportGenerator.UnitTests\LibraryImportGenerator.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\ComInterfaceGenerator.Unit.Tests\ComInterfaceGenerator.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\LibraryImportGenerator.Tests\LibraryImportGenerator.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\LibraryImportGenerator.UnitTests\LibraryImportGenerator.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices.JavaScript\tests\JSImportGenerator.UnitTest\JSImportGenerator.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Private.CoreLib\tests\IntrinsicsInSystemPrivatecoreLibAnalyzer.Tests\IntrinsicsInSystemPrivateCoreLib.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'arm'">
Expand Down Expand Up @@ -330,19 +333,16 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.SourceGeneration.Unit.Tests\System.Text.Json.SourceGeneration.Roslyn3.11.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.Json\tests\System.Text.Json.SourceGeneration.Unit.Tests\System.Text.Json.SourceGeneration.Roslyn4.4.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Text.RegularExpressions\tests\FunctionalTests\System.Text.RegularExpressions.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices.JavaScript\tests\JSImportGenerator.UnitTest\JSImportGenerator.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Configuration.Binder\tests\SourceGenerationTests\Microsoft.Extensions.Configuration.Binder.SourceGeneration.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Options.ConfigurationExtensions\tests\SourceGenerationTests\Microsoft.Extensions.Options.ConfigurationExtensions.SourceGeneration.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Options/tests/SourceGenerationTests/Microsoft.Extensions.Options.SourceGeneration.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Microsoft.Extensions.Options.SourceGeneration.Unit.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Private.CoreLib/tests/IntrinsicsInSystemPrivatecoreLibAnalyzer.Tests/IntrinsicsInSystemPrivateCoreLib.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'browser' and '$(RunDisabledWasmTests)' != 'true' and '$(RunAOTCompilation)' != 'true'">
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'browser' and '$(RunDisabledWasmTests)' != 'true'">
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices.JavaScript\tests\JSImportGenerator.UnitTest\JSImportGenerator.Unit.Tests.csproj" />

<!-- This test is disabled via an assembly-level attribute in source. We exclude it here to avoid queuing/running a work item entirely.
https://github.com/dotnet/runtime/issues/35970 -->
Expand Down

0 comments on commit 7d471fa

Please sign in to comment.