Problem
The PrepareAbiItems MSBuild task has no unit tests. It contains a Mode-to-base-name mapping and ABI-specific path construction logic that should be covered by tests to prevent regressions.
Location
- File:
src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cs
- Test directory:
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/
Current Code
The task maps a Mode string to a base filename, then creates ITaskItem[] output entries for each ABI:
public override bool RunTask ()
{
// Maps Mode ("typemap", "environment", "compressed", "jniremap",
// "marshal_methods", "runtime_linking", "jni_init") to a base name
// Then creates TaskItems: "{NativeSourcesDir}/{baseName}.{abi}.ll"
// with "abi" metadata for each ABI in BuildTargetAbis
}
Suggested Fix
Create a new test file src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs with tests covering:
- Each valid Mode value — Verify the correct base name is used for all 7 modes:
typemap → typemaps, environment → environment, compressed → compressed_assemblies, jniremap → jni_remap, marshal_methods → marshal_methods, runtime_linking → pinvoke_preserve, jni_init → jni_init_funcs
- Invalid Mode — Verify that an unknown mode logs an error and returns
false
- Multiple ABIs — Verify output items are created for each ABI with correct paths and
abi metadata
- Single ABI — Verify it works with just one ABI
- Mode case insensitivity — Verify modes are matched case-insensitively (e.g.,
"TypeMap", "TYPEMAP")
Follow the existing test patterns in the repo. Example structure:
using NUnit.Framework;
using System.Linq;
using Xamarin.Android.Tasks;
namespace Xamarin.Android.Build.Tests
{
[TestFixture]
public class PrepareAbiItemsTests : BaseTest
{
[Test]
public void TypemapMode ()
{
var task = new PrepareAbiItems {
BuildEngine = new MockBuildEngine (TestContext.Out),
BuildTargetAbis = new [] { "arm64-v8a", "x86_64" },
NativeSourcesDir = "/native/src",
Mode = "typemap",
Debug = false,
};
Assert.IsTrue (task.Execute ());
Assert.IsNotNull (task.AssemblySources);
Assert.AreEqual (2, task.AssemblySources.Length);
Assert.AreEqual ("/native/src/typemaps.arm64-v8a.ll", task.AssemblySources [0].ItemSpec);
Assert.AreEqual ("arm64-v8a", task.AssemblySources [0].GetMetadata ("abi"));
}
[Test]
public void InvalidMode ()
{
var errors = new System.Collections.Generic.List<Microsoft.Build.Framework.BuildErrorEventArgs> ();
var task = new PrepareAbiItems {
BuildEngine = new MockBuildEngine (TestContext.Out, errors),
BuildTargetAbis = new [] { "arm64-v8a" },
NativeSourcesDir = "/native/src",
Mode = "invalid_mode",
Debug = false,
};
Assert.IsFalse (task.Execute ());
Assert.AreEqual (1, errors.Count);
}
}
}
Guidelines
- Follow existing test patterns in
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/ (e.g., GenerateLibraryResourcesTests.cs)
- Extend
BaseTest, use MockBuildEngine
- Use
[TestCase] parameterization for the 7 mode values to keep tests DRY
- Use tabs for indentation, space before
( and [ (Mono style)
- No
! (null-forgiving operator)
Acceptance Criteria
Generated by Nightly Fix Finder for issue #11352 · ● 4.9M · ◷
Problem
The
PrepareAbiItemsMSBuild task has no unit tests. It contains a Mode-to-base-name mapping and ABI-specific path construction logic that should be covered by tests to prevent regressions.Location
src/Xamarin.Android.Build.Tasks/Tasks/PrepareAbiItems.cssrc/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/Current Code
The task maps a
Modestring to a base filename, then createsITaskItem[]output entries for each ABI:Suggested Fix
Create a new test file
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cswith tests covering:typemap→typemaps,environment→environment,compressed→compressed_assemblies,jniremap→jni_remap,marshal_methods→marshal_methods,runtime_linking→pinvoke_preserve,jni_init→jni_init_funcsfalseabimetadata"TypeMap","TYPEMAP")Follow the existing test patterns in the repo. Example structure:
Guidelines
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/(e.g.,GenerateLibraryResourcesTests.cs)BaseTest, useMockBuildEngine[TestCase]parameterization for the 7 mode values to keep tests DRY(and[(Mono style)!(null-forgiving operator)Acceptance Criteria
PrepareAbiItemsTests.csadded in the Tasks test directory[TestCase]parameterization)