Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Last active October 6, 2025 18:42
Show Gist options
  • Save jonpryor/d388773a0c117f97f41930772004a4ef to your computer and use it in GitHub Desktop.
Save jonpryor/d388773a0c117f97f41930772004a4ef to your computer and use it in GitHub Desktop.
diff --git a/Src/AwesomeAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs b/Src/AwesomeAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs
index 5622fb62..2c1edd81 100644
--- a/Src/AwesomeAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs
+++ b/Src/AwesomeAssertions/Equivalency/Steps/GenericEnumerableEquivalencyStep.cs
@@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
+using System.Text;
using AwesomeAssertions.Common;
using AwesomeAssertions.Execution;
@@ -52,6 +53,12 @@ public class GenericEnumerableEquivalencyStep : IEquivalencyStep
HandleMethod.MakeGenericMethod(typeOfEnumeration)
.Invoke(null, [validator, subjectAsArray, comparands.Expectation]);
}
+ catch (NotSupportedException)
+ {
+ Console.WriteLine($"# jonp: in AOT, NotSupportedException; subject={PrintValue(subjectAsArray)}");
+ Console.WriteLine($"# jonp: comparands.Expectation={PrintValue(comparands.Expectation)}");
+ HandleImpl<object>(validator, subjectAsArray, EnumerableEquivalencyStep.ToArray(comparands.Expectation));
+ }
catch (TargetInvocationException e)
{
e.Unwrap().Throw();
@@ -61,6 +68,36 @@ public class GenericEnumerableEquivalencyStep : IEquivalencyStep
return EquivalencyResult.EquivalencyProven;
}
+ private static string PrintValue(object value)
+ {
+ if (value is object[] array)
+ {
+ return $"{value.GetType().FullName}{{ {string.Join(", ", array.Select(a => PrintValue(a)))} }}";
+ }
+
+ if (value is IEnumerable e)
+ {
+ var sb = new StringBuilder();
+ sb.Append("IEnumerable{");
+ bool first = true;
+ foreach (var v in e)
+ {
+ if (!first)
+ {
+ sb.Append(", ");
+ }
+
+ first = false;
+ sb.Append(PrintValue(v));
+ }
+
+ sb.Append('}');
+ return sb.ToString();
+ }
+
+ return $"{value?.ToString() ?? "null"} as {value?.GetType().FullName ?? "null"}";
+ }
+
private static void HandleImpl<T>(EnumerableEquivalencyValidator validator, object[] subject, IEnumerable<T> expectation) =>
validator.Execute(subject, ToArray(expectation));
diff --git a/Tests/NativeAOT/NativeAOT.csproj b/Tests/NativeAOT/NativeAOT.csproj
new file mode 100644
index 00000000..6239f085
--- /dev/null
+++ b/Tests/NativeAOT/NativeAOT.csproj
@@ -0,0 +1,16 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net9.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ <PublishAot Condition=" '$(AwesomePublishAot)' != '' ">$(AwesomePublishAot)</PublishAot>
+ <!-- Ignore linker warnings for now -->
+ <NoWarn>IL2026;IL2060;IL2065;IL2070;IL2072;IL2075;IL2080;IL3050;IL3054</NoWarn>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\Src\AwesomeAssertions\AwesomeAssertions.csproj" />
+ </ItemGroup>
+</Project>
diff --git a/Tests/NativeAOT/Program.cs b/Tests/NativeAOT/Program.cs
new file mode 100644
index 00000000..c5af1630
--- /dev/null
+++ b/Tests/NativeAOT/Program.cs
@@ -0,0 +1,7 @@
+using AwesomeAssertions;
+
+var c = new[] { 1, 2 };
+
+c.Should().BeEquivalentTo([1, 2]);
+
+Console.WriteLine("Complete.");
#!/bin/sh
dotnet publish -c Release -p:AwesomePublishAot=true -r osx-x64 Tests/NativeAOT/*.csproj && \
Tests/NativeAOT/bin/Release/net9.0/osx-x64/publish/NativeAOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment