-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adapt monotouch-test to work with NativeAOT #17774
Comments
Can you try just calling this overload instead? So here: do this instead: return AddSuite ((TestSuite) runner.Load (assembly.Location, CreateSettings (settings))); |
Next attempt: try calling this method using reflection (since it's private): NUnit's code flow is rather annoying, because the only reason it seems to want location/codebase is to figure out the assembly name, and then it also reloads the assembly when it's already been given the assembly. Calling that method might skip over that logic, and go straight to the actual important bits. If that doesn't work, maybe we'll have to implement a custom ITestAssemblyBuilder.
I guess one way would be to just try to make NUnit work with NativeAOT, and get it fixed in NUnit instead... |
According to your suggestion of using a different overload, would it make sense to do this instead of using reflection? public bool Load (Assembly assembly, IDictionary<string, object> settings = null)
{
var runner = new NUnitTestAssemblyRunner (builder);
runners.Add (runner);
+#if NATIVEAOT
+ return AddSuite ((TestSuite) runner.Load (assembly.GetName().Name, CreateSettings (settings)));
+#else
return AddSuite ((TestSuite) runner.Load (assembly, CreateSettings (settings)));
+#endif
} I agree it is hacky, but seems to work as NUnit will recreate the FullName based on already available name... |
Won't that run into the same issue as you describe here: #17774 (comment)? In any case, I'm fine with this solution if it works (even better if the NATIVEAOT codepath works when !NATIVEAOT, then we can just use that always). |
The difference is that with the approach above:
|
Ah ok - well, if that works, then great :) |
Regarding this, I was wondering whether some test (or the infrastructure around it) cares about assembly name in the "Assembly.dll" format. |
There might be, but we can change those tests if need be. |
…name (#116) This PR adds a workaround to support NativeAOT runtime with Xamarin. ### Introduction The limitation comes from the unsupported or limited support for the following properties on `Assembly` type with NativeAOT - `CodeBase` - unsupported feature - throws with: https://github.com/dotnet/runtime/blob/588dcd7a29f109daae2d8c999322acd8e853a8c6/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs#L70-L78 - `Location` - somewhat supported - empty string: https://github.com/dotnet/runtime/blob/588dcd7a29f109daae2d8c999322acd8e853a8c6/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs#L66 Both properties do not seem to make sense with NativeAOT, as the assembly is not preserved in its original format. These limitations prevent using NUnitTestAssemblyRunner's Load overload which accepts `Assembly` object as parameter, which is discussed in the tracking issue: xamarin/xamarin-macios#17774 ### Changes The included change, changes the way the `TestSuite` is created by NUnit framework for all runtimes. This affects the created name of test suites in the following way e.g.,: - `monotouchtest.dll` -> `monotouchtest` - `EmbeddedResources.dll` -> `EmbeddedResources` - ...etc The change has been tested locally with monotouch-test running on iOS device using .NET7 mono runtime --- Fixes: xamarin/xamarin-macios#17774
PR with the Touch.Unit bump: #17819 |
Description
During the startup,
monotouch-test
app collects the assemblies which represent test suites and callsNUnitTestAssemblyRunner
to bundle each of them in a TestSuite object.This happens in
TouchRunner::GetViewController
throughLoadSync
method.The following code path is followed:
https://github.com/spouliot/Touch.Unit/blob/564433f35c8ab6b7bb0709f83e1b81a89c406956/NUnitLite/TouchRunner/TouchRunner.cs#L168-L170
https://github.com/spouliot/Touch.Unit/blob/564433f35c8ab6b7bb0709f83e1b81a89c406956/NUnitLite/TouchRunner/TouchRunner.cs#L608C4
https://github.com/nunit/nunit/blob/af8ca8bc779072b4fa5432e8620f06ca796d13a3/src/NUnitFramework/framework/Api/NUnitTestAssemblyRunner.cs#L170
https://github.com/nunit/nunit/blob/af8ca8bc779072b4fa5432e8620f06ca796d13a3/src/NUnitFramework/framework/Api/DefaultTestAssemblyBuilder.cs#L81
https://github.com/nunit/nunit/blob/af8ca8bc779072b4fa5432e8620f06ca796d13a3/src/NUnitFramework/framework/Internal/AssemblyHelper.cs#L48-L56
Finally, the final piece ends up calling
CodeBase
property onAssembly
type which is not supported with NativeAOT:https://github.com/dotnet/runtime/blob/588dcd7a29f109daae2d8c999322acd8e853a8c6/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/ThunkedApis.cs#L70-L78
Proposal
TestAssemblyBuilder
implementingITestAssemblyBuilder
which would instead fetchAssembly.GetName().FullName
for an assemblyNUnitLiteTestAssemblyBuilder
fromNUnitLite-1.0.0
: https://github.com/spouliot/Touch.Unit/blob/564433f35c8ab6b7bb0709f83e1b81a89c406956/NUnitLite/TouchRunner/TouchRunner.cs#L610-L622/cc: @rolfbjarne
The text was updated successfully, but these errors were encountered: