Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public bool Equals (PlatformAvailability other)
var obsoleteComparer = new DictionaryComparer<Version, (string?, string?)> ();
var unsupportedComparer = new DictionaryComparer<Version, string?> ();

var x = Equals (SupportedVersion, other.SupportedVersion);
return Platform == other.Platform &&
Equals (SupportedVersion, other.SupportedVersion) &&
unsupportedComparer.Equals (unsupported, other.unsupported) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Macios.Generator.Availability;
/// Readonly structure that describes the availability of a symbol in the supported platforms of the SDK.
/// </summary>
readonly partial struct SymbolAvailability : IEquatable<SymbolAvailability> {
static readonly HashSet<ApplePlatform> supportedPlatforms =
public static readonly HashSet<ApplePlatform> SupportedPlatforms =
[ApplePlatform.iOS, ApplePlatform.TVOS, ApplePlatform.MacOSX, ApplePlatform.MacCatalyst];

readonly SortedDictionary<ApplePlatform, PlatformAvailability?> availabilities = new ();
Expand Down Expand Up @@ -122,7 +122,7 @@ public SymbolAvailability MergeWithParent (SymbolAvailability? parent)

// create the key value pairs for the supported platforms
var merged = new List<KeyValuePair<ApplePlatform, PlatformAvailability?>> ();
foreach (var platform in supportedPlatforms) {
foreach (var platform in SupportedPlatforms) {
merged.Add (new (platform, Merge (this [platform], parent.Value [platform])));
}

Expand All @@ -134,7 +134,7 @@ public bool Equals (SymbolAvailability other)
{
// loop over the supported platforms and ensure that the availabilities are the
// same
foreach (var platform in supportedPlatforms) {
foreach (var platform in SupportedPlatforms) {
if (this [platform] != other [platform]) {
return false;
}
Expand All @@ -153,7 +153,7 @@ public override bool Equals (object? obj)
public override int GetHashCode ()
{
var hashCode = new HashCode ();
foreach (var platform in supportedPlatforms) {
foreach (var platform in SupportedPlatforms) {
hashCode.Add (this [platform]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ PlatformAvailability.Builder GetBuilder (ApplePlatform platform)
/// <param name="url">Optional documentation url.</param>
internal void AddObsoletedVersion (ApplePlatform platform, Version version, string? message, string? url)
{
if (!supportedPlatforms.Contains (platform))
if (!SupportedPlatforms.Contains (platform))
return;

var builder = GetBuilder (platform);
Expand All @@ -72,7 +72,7 @@ internal void AddObsoletedVersion (ApplePlatform platform, Version version, stri
/// <param name="obsoletedOsPlatform">The data of a ObsoleteOSPlatformAttribute.</param>
public void Add (ObsoletedOSPlatformData obsoletedOsPlatform)
{
if (!supportedPlatforms.Contains (obsoletedOsPlatform.Platform))
if (!SupportedPlatforms.Contains (obsoletedOsPlatform.Platform))
return;

var builder = GetBuilder (obsoletedOsPlatform.Platform);
Expand All @@ -87,7 +87,7 @@ public void Add (ObsoletedOSPlatformData obsoletedOsPlatform)
/// <param name="version">The supported versions to add.</param>
internal void AddSupportedVersion (ApplePlatform platform, Version version)
{
if (!supportedPlatforms.Contains (platform))
if (!SupportedPlatforms.Contains (platform))
return;
var builder = GetBuilder (platform);
builder.AddSupportedVersion (new (version, SupportKind.Explicit));
Expand All @@ -99,7 +99,7 @@ internal void AddSupportedVersion (ApplePlatform platform, Version version)
/// <param name="supportedPlatform">The data of a SupportedOSPlatformAttribute.</param>
public void Add (SupportedOSPlatformData supportedPlatform)
{
if (!supportedPlatforms.Contains (supportedPlatform.Platform))
if (!SupportedPlatforms.Contains (supportedPlatform.Platform))
return;

var builder = GetBuilder (supportedPlatform.Platform);
Expand All @@ -114,7 +114,7 @@ public void Add (SupportedOSPlatformData supportedPlatform)
/// <param name="message">The optional message of the unsupported version.</param>
internal void AddUnsupportedVersion (ApplePlatform platform, Version version, string? message)
{
if (!supportedPlatforms.Contains (platform))
if (!SupportedPlatforms.Contains (platform))
return;

var builder = GetBuilder (platform);
Expand All @@ -127,7 +127,7 @@ internal void AddUnsupportedVersion (ApplePlatform platform, Version version, st
/// <param name="unsupportedPlatform">The data of a UnsupportedOSPlatformAttribute.</param>
public void Add (UnsupportedOSPlatformData unsupportedPlatform)
{
if (!supportedPlatforms.Contains (unsupportedPlatform.Platform))
if (!SupportedPlatforms.Contains (unsupportedPlatform.Platform))
return;

var builder = GetBuilder (unsupportedPlatform.Platform);
Expand All @@ -146,7 +146,7 @@ public void Add (UnsupportedOSPlatformData unsupportedPlatform)
public SymbolAvailability ToImmutable ()
{
var dict = new Dictionary<ApplePlatform, PlatformAvailability?> ();
foreach (var platform in supportedPlatforms) {
foreach (var platform in SupportedPlatforms) {
dict [platform] = platforms.ContainsKey (platform)
? platforms [platform].ToImmutable ()
: null;
Expand Down
6 changes: 3 additions & 3 deletions src/rgen/Microsoft.Macios.Generator/DictionaryComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace Microsoft.Macios.Generator;

public class DictionaryComparer<TKey, TValue> (IEqualityComparer<TValue>? valueComparer = null)
: EqualityComparer<IDictionary<TKey, TValue>>
: EqualityComparer<IReadOnlyDictionary<TKey, TValue>>
where TKey : notnull {
readonly IEqualityComparer<TValue> valueComparer = valueComparer ?? EqualityComparer<TValue>.Default;

/// <inheritdoc/>
public override bool Equals (IDictionary<TKey, TValue>? x, IDictionary<TKey, TValue>? y)
public override bool Equals (IReadOnlyDictionary<TKey, TValue>? x, IReadOnlyDictionary<TKey, TValue>? y)
{
if (x is null && y is null)
return true;
Expand All @@ -28,7 +28,7 @@ public override bool Equals (IDictionary<TKey, TValue>? x, IDictionary<TKey, TVa
}

/// <inheritdoc/>
public override int GetHashCode (IDictionary<TKey, TValue> obj)
public override int GetHashCode (IReadOnlyDictionary<TKey, TValue> obj)
{
var hash = new HashCode ();
foreach (var (key, value) in obj) {
Expand Down
3 changes: 3 additions & 0 deletions src/rsp/dotnet/ios-defines-dotnet.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-d:HAS_AVROUTING
-d:HAS_BACKGROUNDASSETS
-d:HAS_BACKGROUNDTASKS
-d:HAS_BROWSERENGINECORE
-d:HAS_BROWSERENGINEKIT
-d:HAS_BUSINESSCHAT
-d:HAS_CALLKIT
Expand Down Expand Up @@ -64,6 +65,7 @@
-d:HAS_GAMECONTROLLER
-d:HAS_GAMEKIT
-d:HAS_GAMEPLAYKIT
-d:HAS_GAMESAVE
-d:HAS_GLKIT
-d:HAS_HEALTHKIT
-d:HAS_HEALTHKITUI
Expand Down Expand Up @@ -132,6 +134,7 @@
-d:HAS_SYMBOLS
-d:HAS_SYSTEMCONFIGURATION
-d:HAS_THREADNETWORK
-d:HAS_TOUCHCONTROLLER
-d:HAS_TWITTER
-d:HAS_UIKIT
-d:HAS_UNIFORMTYPEIDENTIFIERS
Expand Down
1 change: 1 addition & 0 deletions src/rsp/dotnet/maccatalyst-defines-dotnet.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
-d:HAS_GAMECONTROLLER
-d:HAS_GAMEKIT
-d:HAS_GAMEPLAYKIT
-d:HAS_GAMESAVE
-d:HAS_HEALTHKIT
-d:HAS_HEALTHKITUI
-d:HAS_HOMEKIT
Expand Down
1 change: 1 addition & 0 deletions src/rsp/dotnet/macos-defines-dotnet.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
-d:HAS_GAMECONTROLLER
-d:HAS_GAMEKIT
-d:HAS_GAMEPLAYKIT
-d:HAS_GAMESAVE
-d:HAS_GLKIT
-d:HAS_HEALTHKIT
-d:HAS_IMAGECAPTURECORE
Expand Down
119 changes: 96 additions & 23 deletions tests/common/ConfigurationXUnit.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading.Tasks;
using Xamarin.Utils;
using Xunit;
using Xunit.Internal;
using Xunit.Sdk;
using Xunit.v3;

namespace Xamarin.Tests {

[AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
[AttributeUsage (AttributeTargets.Method, AllowMultiple = true)]
public sealed class PlatformInlineDataAttribute : DataAttribute {
readonly object [] dataValues;
readonly object [] data;
public PlatformInlineDataAttribute (ApplePlatform platform, params object [] parameters)
{
// data values are the join of the platform and all other values passed to the attr
dataValues = parameters.Prepend (platform).ToArray ();
data = parameters.Prepend (platform).ToArray ();
// based on the passed platform and the configuration, decide if we skip the test
switch (platform) {
case ApplePlatform.iOS:
Expand All @@ -37,17 +44,32 @@ public PlatformInlineDataAttribute (ApplePlatform platform, params object [] par
}
}

public object [] DataValues {
get { return dataValues; }
public override bool SupportsDiscoveryEnumeration () => true;

public object [] Data {
get { return data; }
}

public override IEnumerable<object []> GetData (MethodInfo testMethod)
public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData (MethodInfo testMethod, DisposalTracker disposalTracker)
{
yield return dataValues;
var traits = new Dictionary<string, HashSet<string>> (StringComparer.OrdinalIgnoreCase);
TestIntrospectionHelper.MergeTraitsInto (traits, Traits);
return new ([
new TheoryDataRow (Data) {
Explicit = ExplicitAsNullable,
Label = Label,
Skip = Skip,
TestDisplayName = TestDisplayName,
Timeout = TimeoutAsNullable,
Traits = traits,
}
]);

}

}

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

readonly object [] dataValues;
Expand All @@ -57,15 +79,24 @@ public AllSupportedPlatformsAttribute (params object [] parameters)
dataValues = parameters;
}

public override IEnumerable<object []> GetData (MethodInfo testMethod)
public override bool SupportsDiscoveryEnumeration () => true;

public override ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData (
MethodInfo testMethod,
DisposalTracker disposalTracker)
{
return Configuration.
GetIncludedPlatforms ().
Select (platform => dataValues.Prepend (platform).ToArray ());
var result = new List<ITheoryDataRow> ();

foreach (var platform in Configuration.GetIncludedPlatforms ()) {
var row = dataValues.Prepend (platform).ToArray ();
result.Add (ConvertDataRow (row));
}

return ValueTask.FromResult (result.CastOrToReadOnlyCollection ());
}
}

[AttributeUsage (AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
[AttributeUsage (AttributeTargets.Method, AllowMultiple = true)]
public sealed class AllSupportedPlatformsClassDataAttribute<T> : DataAttribute where T : IEnumerable<object []> {
readonly Type dataAttributeType;

Expand All @@ -74,22 +105,64 @@ public AllSupportedPlatformsClassDataAttribute ()
dataAttributeType = typeof (T);
}

public override IEnumerable<object []> GetData (MethodInfo testMethod)
public override bool SupportsDiscoveryEnumeration () =>
!typeof (IDisposable).IsAssignableFrom (dataAttributeType) && !typeof (IAsyncDisposable).IsAssignableFrom (dataAttributeType);

/// <inheritdoc/>
protected override ITheoryDataRow ConvertDataRow (object dataRow)
{
// we are going to get the instance of the IEnumerable, loop through it and yield the parameters
// per platform
var enumerable = Activator.CreateInstance (dataAttributeType) as IEnumerable<object []>;
if (enumerable is null)
yield break;
foreach (var platform in Configuration.GetIncludedPlatforms ()) {
foreach (var parameters in enumerable) {
yield return parameters.Prepend (platform).ToArray ();
Guard.ArgumentNotNull (dataRow);

try {
return base.ConvertDataRow (dataRow);
} catch (ArgumentException) {
throw new ArgumentException (
string.Format (
CultureInfo.CurrentCulture,
"Class '{0}' yielded an item of type '{1}' which is not an 'object?[]', 'Xunit.ITheoryDataRow' or 'System.Runtime.CompilerServices.ITuple'",
dataAttributeType.FullName,
dataRow?.GetType ().SafeName ()
),
nameof (dataRow)
);
}
}

public override async ValueTask<IReadOnlyCollection<ITheoryDataRow>> GetData (
MethodInfo testMethod,
DisposalTracker disposalTracker)
{
var classInstance = Activator.CreateInstance (dataAttributeType);
Copy link
Member

Choose a reason for hiding this comment

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

This would be more AOT-friendly, unless I'm missing why it wouldn't work:

Suggested change
var classInstance = Activator.CreateInstance (dataAttributeType);
var classInstance = new T ();

disposalTracker.Add (classInstance);

if (classInstance is IAsyncLifetime classLifetime)
await classLifetime.InitializeAsync ();

if (classInstance is IEnumerable<object []> dataItems) {
var result = new List<ITheoryDataRow> ();

foreach (var platform in Configuration.GetIncludedPlatforms ()) {
foreach (var row in dataItems) {

var platformRow = row.Prepend (platform).ToArray ();
result.Add (ConvertDataRow (platformRow));
}
}

return result.CastOrToReadOnlyCollection ();
}

throw new ArgumentException (
string.Format (
CultureInfo.CurrentCulture,
"'{0}' must implement one of the following interfaces to be used as ClassData:{1}- IEnumerable<object[]>{1}",
dataAttributeType.FullName,
Environment.NewLine
)
);
}
}


public partial class Configuration {
static string TestAssemblyDirectory {
get {
Expand Down
21 changes: 21 additions & 0 deletions tests/rgen/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project>

<!-- Common package versions -->
<PropertyGroup>
<Version_Microsoft_NET_Test_Sdk>17.13.0</Version_Microsoft_NET_Test_Sdk>
<Version_xunit_runner_visualstudio>3.1.1</Version_xunit_runner_visualstudio>
<Version_xunit_analyzers>1.23.0-pre.3</Version_xunit_analyzers>
<Version_xunit_v3>3.0.0-pre.25</Version_xunit_v3>
</PropertyGroup>

<PropertyGroup>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>

<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.3-beta1.24352.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="$(Version_xunit_v3)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(Version_xunit_runner_visualstudio)" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.3-beta1.24352.1"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.3-beta1.24352.1"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2"/>
<PackageReference Include="xunit" Version="2.4.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.v3" Version="$(Version_xunit_v3)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(Version_xunit_runner_visualstudio)" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading