Skip to content

Commit

Permalink
[DllImportGenerator] Skip unit tests that hit exceptions due to rosly…
Browse files Browse the repository at this point in the history
…n-sdk#590 (#60848)
  • Loading branch information
elinor-fung authored Oct 26, 2021
1 parent bf885a3 commit d2ca8e1
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace DllImportGenerator.UnitTests
{
public class AdditionalAttributesOnStub
{
[Fact]
[ConditionalFact]
public async Task SkipLocalsInitAdded()
{
string source = @"
Expand Down Expand Up @@ -45,7 +43,7 @@ public Native(S s) { }
Assert.Contains(stubMethod.GetAttributes(), attr => attr.AttributeClass!.ToDisplayString() == typeof(SkipLocalsInitAttribute).FullName);
}

[Fact]
[ConditionalFact]
public async Task SkipLocalsInitNotAddedOnForwardingStub()
{
string source = @"
Expand All @@ -72,7 +70,7 @@ public static IEnumerable<object[]> GetDownlevelTargetFrameworks()
yield return new object[] { ReferenceAssemblies.NetFramework.Net48.Default, false };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(GetDownlevelTargetFrameworks))]
public async Task SkipLocalsInitOnDownlevelTargetFrameworks(ReferenceAssemblies referenceAssemblies, bool expectSkipLocalsInit)
{
Expand Down Expand Up @@ -122,7 +120,7 @@ public Native(S s) { }
}
}

[Fact]
[ConditionalFact]
public async Task SkipLocalsInitNotAddedWhenDefinedAtModuleLevel()
{
string source = @"
Expand Down Expand Up @@ -154,7 +152,7 @@ public Native(S s) { }
Assert.DoesNotContain(stubMethod.GetAttributes(), attr => attr.AttributeClass!.ToDisplayString() == typeof(SkipLocalsInitAttribute).FullName);
}

[Fact]
[ConditionalFact]
public async Task SkipLocalsInitNotAddedWhenDefinedAtClassLevel()
{
string source = @"
Expand Down Expand Up @@ -186,7 +184,7 @@ public Native(S s) { }
Assert.DoesNotContain(stubMethod.GetAttributes(), attr => attr.AttributeClass!.ToDisplayString() == typeof(SkipLocalsInitAttribute).FullName);
}

[Fact]
[ConditionalFact]
public async Task SkipLocalsInitNotAddedWhenDefinedOnMethodByUser()
{
string source = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DllImportGenerator.UnitTests
{
public class AttributeForwarding
{
[Theory]
[ConditionalTheory]
[InlineData("SuppressGCTransition", "System.Runtime.InteropServices.SuppressGCTransitionAttribute")]
[InlineData("UnmanagedCallConv", "System.Runtime.InteropServices.UnmanagedCallConvAttribute")]
public async Task KnownParameterlessAttribute(string attributeSourceName, string attributeMetadataName)
Expand Down Expand Up @@ -54,7 +54,7 @@ public Native(S s) {{ }}
attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, attributeType));
}

[Fact]
[ConditionalFact]
public async Task UnmanagedCallConvAttribute_EmptyCallConvArray()
{
string source = @"
Expand Down Expand Up @@ -96,7 +96,7 @@ public Native(S s) { }
&& attr.NamedArguments[0].Value.Values.Length == 0);
}

[Fact]
[ConditionalFact]
public async Task UnmanagedCallConvAttribute_SingleCallConvType()
{
string source = @"
Expand Down Expand Up @@ -142,7 +142,7 @@ public Native(S s) { }
callConvType));
}

[Fact]
[ConditionalFact]
public async Task UnmanagedCallConvAttribute_MultipleCallConvTypes()
{
string source = @"
Expand Down Expand Up @@ -192,7 +192,7 @@ public Native(S s) { }
callConvType2));
}

[Fact]
[ConditionalFact]
public async Task OtherAttributeType()
{
string source = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompile()
yield return new object[] { CodeSnippets.MutuallyRecursiveSizeParamIndexOnParameter, 4, 0 };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(CodeSnippetsToCompile))]
public async Task ValidateSnippets(string source, int expectedGeneratorErrors, int expectedCompilerErrors)
{
Expand All @@ -150,7 +150,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompile_InvalidCode()
yield return new object[] { CodeSnippets.MutuallyRecursiveImplicitlyBlittableStruct, 5, 2 };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(CodeSnippetsToCompile_InvalidCode))]
public async Task ValidateSnippets_InvalidCodeGracefulFailure(string source, int expectedGeneratorErrors, int expectedCompilerErrors)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompile()
yield return new[] { CodeSnippets.CollectionsOfCollectionsStress };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(CodeSnippetsToCompile))]
public async Task ValidateSnippets(string source)
{
Expand All @@ -295,7 +295,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompileWithPreprocessorSymbols
yield return new object[] { CodeSnippets.PreprocessorIfAfterAttributeAroundFunctionAdditionalFunctionAfter("Foo"), Array.Empty<string>() };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(CodeSnippetsToCompileWithPreprocessorSymbols))]
public async Task ValidateSnippetsWithPreprocessorDefintions(string source, IEnumerable<string> preprocessorSymbols)
{
Expand All @@ -320,7 +320,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompileWithForwarder()
yield return new[] { CodeSnippets.BasicParametersAndModifiers<string>() };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(CodeSnippetsToCompileWithForwarder))]
public async Task ValidateSnippetsWithForwarder(string source)
{
Expand All @@ -338,7 +338,7 @@ public async Task ValidateSnippetsWithForwarder(string source)
var newCompDiags = newComp.GetDiagnostics();
Assert.Empty(newCompDiags);

// Verify that the forwarder generates the method as a DllImport.
// Verify that the forwarder generates the method as a DllImport.
SyntaxTree generatedCode = newComp.SyntaxTrees.Last();
SemanticModel model = newComp.GetSemanticModel(generatedCode);
var methods = generatedCode.GetRoot()
Expand All @@ -357,7 +357,7 @@ public static IEnumerable<object[]> FullyBlittableSnippetsToCompile()
yield return new[] { CodeSnippets.BasicParameterByValue("int") };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(FullyBlittableSnippetsToCompile))]
public async Task ValidateSnippetsWithBlittableAutoForwarding(string source)
{
Expand All @@ -374,7 +374,7 @@ public async Task ValidateSnippetsWithBlittableAutoForwarding(string source)
var newCompDiags = newComp.GetDiagnostics();
Assert.Empty(newCompDiags);

// Verify that the forwarder generates the method as a DllImport.
// Verify that the forwarder generates the method as a DllImport.
SyntaxTree generatedCode = newComp.SyntaxTrees.Last();
SemanticModel model = newComp.GetSemanticModel(generatedCode);
var methods = generatedCode.GetRoot()
Expand All @@ -391,7 +391,7 @@ public static IEnumerable<object[]> SnippetsWithBlittableTypesButNonBlittableDat
yield return new[] { CodeSnippets.PreserveSigFalse<int>() };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(SnippetsWithBlittableTypesButNonBlittableDataToCompile))]
public async Task ValidateSnippetsWithBlittableTypesButNonBlittableMetadataDoNotAutoForward(string source)
{
Expand Down Expand Up @@ -429,7 +429,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompileWithMarshalType()
#pragma warning disable xUnit1004 // Test methods should not be skipped.
// If we have any new experimental APIs that we are implementing that have not been approved,
// we will add new scenarios for this test.
[Theory(Skip = "No current scenarios to test.")]
[ConditionalTheory(Skip = "No current scenarios to test.")]
#pragma warning restore
[MemberData(nameof(CodeSnippetsToCompileWithMarshalType))]
public async Task ValidateSnippetsWithMarshalType(string source)
Expand Down Expand Up @@ -461,7 +461,7 @@ public static IEnumerable<object[]> CodeSnippetsToCompileMultipleSources()
yield return new object[] { new[] { CodeSnippets.BasicParameterByValue("int[]"), CodeSnippets.BasicParameterWithByRefModifier("ref", "int") } };
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(CodeSnippetsToCompileMultipleSources))]
public async Task ValidateSnippetsWithMultipleSources(string[] sources)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static IEnumerable<object[]> NoMarshallingRequiredTypes() => new[]
new object[] { typeof(ConsoleKey) }, // enum
};

[Theory]
[ConditionalTheory]
[MemberData(nameof(MarshallingRequiredTypes))]
[MemberData(nameof(NoMarshallingRequiredTypes))]
public async Task TypeRequiresMarshalling_ReportsDiagnostic(Type type)
Expand All @@ -53,7 +53,7 @@ await VerifyCS.VerifyAnalyzerAsync(
.WithArguments("Method_Return"));
}

[Theory]
[ConditionalTheory]
[MemberData(nameof(MarshallingRequiredTypes))]
[MemberData(nameof(NoMarshallingRequiredTypes))]
public async Task ByRef_ReportsDiagnostic(Type type)
Expand Down Expand Up @@ -86,7 +86,7 @@ await VerifyCS.VerifyAnalyzerAsync(
.WithArguments("Method_Ref"));
}

[Fact]
[ConditionalFact]
public async Task PreserveSigFalse_ReportsDiagnostic()
{
string source = @$"
Expand All @@ -110,7 +110,7 @@ await VerifyCS.VerifyAnalyzerAsync(
.WithArguments("Method2"));
}

[Fact]
[ConditionalFact]
public async Task SetLastErrorTrue_ReportsDiagnostic()
{
string source = @$"
Expand All @@ -134,7 +134,7 @@ await VerifyCS.VerifyAnalyzerAsync(
.WithArguments("Method2"));
}

[Fact]
[ConditionalFact]
public async Task NotDllImport_NoDiagnostic()
{
string source = @$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace DllImportGenerator.UnitTests
[ActiveIssue("https://github.com/dotnet/runtime/issues/60650", TestRuntimes.Mono)]
public class ConvertToGeneratedDllImportFixerTests
{
[Theory]
[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task Basic(bool usePreprocessorDefines)
Expand Down Expand Up @@ -56,7 +56,7 @@ await VerifyCS.VerifyCodeFixAsync(
usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
}

[Theory]
[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task Comments(bool usePreprocessorDefines)
Expand Down Expand Up @@ -119,7 +119,7 @@ await VerifyCS.VerifyCodeFixAsync(
usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
}

[Theory]
[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task MultipleAttributes(bool usePreprocessorDefines)
Expand Down Expand Up @@ -180,7 +180,7 @@ await VerifyCS.VerifyCodeFixAsync(
usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
}

[Theory]
[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task NamedArguments(bool usePreprocessorDefines)
Expand Down Expand Up @@ -232,7 +232,7 @@ await VerifyCS.VerifyCodeFixAsync(
usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
}

[Theory]
[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task RemoveableNamedArguments(bool usePreprocessorDefines)
Expand Down Expand Up @@ -284,7 +284,7 @@ await VerifyCS.VerifyCodeFixAsync(
usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
}

[Theory]
[ConditionalTheory]
[InlineData(true)]
[InlineData(false)]
public async Task ReplaceableExplicitPlatformDefaultCallingConvention(bool usePreprocessorDefines)
Expand Down Expand Up @@ -322,7 +322,7 @@ await VerifyCS.VerifyCodeFixAsync(
usePreprocessorDefines ? WithPreprocessorDefinesKey : NoPreprocessorDefinesKey);
}

[Theory]
[ConditionalTheory]
[InlineData(CallingConvention.Cdecl, typeof(CallConvCdecl), true)]
[InlineData(CallingConvention.Cdecl, typeof(CallConvCdecl), false)]
[InlineData(CallingConvention.StdCall, typeof(CallConvStdcall), true)]
Expand Down
Loading

0 comments on commit d2ca8e1

Please sign in to comment.