Skip to content

Commit

Permalink
[Rgen] Simplify the way we execute tests on all platforms. (#21547)
Browse files Browse the repository at this point in the history
There is no need to write a line per platform when we can use an
attribvute for that.

---------

Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
  • Loading branch information
mandel-macaque and rolfbjarne authored Oct 30, 2024
1 parent cf03595 commit 524279f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 40 deletions.
27 changes: 27 additions & 0 deletions tests/common/ConfigurationXUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,38 @@ public override IEnumerable<object []> GetData (MethodInfo testMethod)
}
}

[AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public sealed class AllSupportedPlatformsAttribute : DataAttribute {

readonly object [] dataValues;

public AllSupportedPlatformsAttribute (params object [] parameters)
{
dataValues = parameters;
}

public override IEnumerable<object []> GetData (MethodInfo testMethod)
{
return Configuration.
GetIncludedPlatforms (true).
Select (platform => dataValues.Prepend (platform).ToArray ());
}
}

public partial class Configuration {
static string TestAssemblyDirectory {
get {
return Assembly.GetExecutingAssembly ().Location;
}
}

public static bool IsEnabled (ApplePlatform platform)
=> platform switch {
ApplePlatform.iOS => include_ios,
ApplePlatform.TVOS => include_tvos,
ApplePlatform.MacCatalyst => include_maccatalyst,
ApplePlatform.MacOSX => include_mac,
_ => false
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public partial class AVAudioPcmBuffer
";

[Theory]
[PlatformInlineData (ApplePlatform.iOS, usingImportInput, usingImportOutput)]
[PlatformInlineData (ApplePlatform.TVOS, usingImportInput, usingImportOutput)]
[PlatformInlineData (ApplePlatform.MacOSX, usingImportInput, usingImportOutput)]
[PlatformInlineData (ApplePlatform.MacCatalyst, usingImportInput, usingImportOutput)]
[AllSupportedPlatforms (usingImportInput, usingImportOutput)]
public void CorrectUsingImports (ApplePlatform platform, string input, string expectedOutput)
{
// We need to create a compilation with the required source code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ T GetDeclaration<T> (ApplePlatform platform, string inputText) where T : BaseTyp
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[AllSupportedPlatforms]
public void GetFullyQualifiedIdentifierFileScopedNamespace (ApplePlatform platform)
{
const string inputText = @"
Expand All @@ -40,10 +37,7 @@ public class Foo {
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[AllSupportedPlatforms]
public void GetFullyQualifiedIdentifierFileScopedNamespaceNestedClass (ApplePlatform platform)
{
const string inputText = @"
Expand All @@ -58,10 +52,7 @@ public enum Bar {
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[AllSupportedPlatforms]
public void GetFullyQualifiedIdentifierNamespaceDeclaration (ApplePlatform platform)
{
const string inputText = @"
Expand All @@ -75,10 +66,7 @@ public class Foo {
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[AllSupportedPlatforms]
public void GetFullyQualifiedIdentifierMultipleNamespaceDeclaration (ApplePlatform platform)
{
const string inputText = @"
Expand All @@ -94,10 +82,7 @@ public class Bar {}
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[AllSupportedPlatforms]
public void GetFullyQualifiedIdentifierNestedNamespaceDeclaration (ApplePlatform platform)
{
const string inputText = @"
Expand All @@ -112,10 +97,7 @@ public class Test {}
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[AllSupportedPlatforms]
public void GetFullyQualifiedIdentifierNamespaceDeclarationNestedClass (ApplePlatform platform)
{
const string inputText = @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ namespace Microsoft.Macios.Generator.Tests.Extensions;

public class MemberDeclarationSyntaxExtensionsTests : BaseGeneratorTestClass {
[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[AllSupportedPlatforms]
public void GetAttributeCodeChanges (ApplePlatform platform)
{
var attrsText = @"
Expand Down Expand Up @@ -99,10 +96,7 @@ public interface IInterface {
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[AllSupportedPlatforms]
public void GetAttributeCodeChangesSameAttrDiffText (ApplePlatform platform)
{
const string inputText = @"
Expand Down Expand Up @@ -144,10 +138,7 @@ public void SayGoodbye () {
}

[Theory]
[PlatformInlineData (ApplePlatform.iOS)]
[PlatformInlineData (ApplePlatform.TVOS)]
[PlatformInlineData (ApplePlatform.MacOSX)]
[PlatformInlineData (ApplePlatform.MacCatalyst)]
[AllSupportedPlatforms]
public void GetAttributeCodeChangesTypeOf (ApplePlatform platform)
{

Expand Down

6 comments on commit 524279f

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.