Skip to content

[fix-finder] Add unit tests for PrepareAbiItems MSBuild task #11370

@github-actions

Description

@github-actions

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:

  1. Each valid Mode value — Verify the correct base name is used for all 7 modes: typemaptypemaps, environmentenvironment, compressedcompressed_assemblies, jniremapjni_remap, marshal_methodsmarshal_methods, runtime_linkingpinvoke_preserve, jni_initjni_init_funcs
  2. Invalid Mode — Verify that an unknown mode logs an error and returns false
  3. Multiple ABIs — Verify output items are created for each ABI with correct paths and abi metadata
  4. Single ABI — Verify it works with just one ABI
  5. 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

  • New file PrepareAbiItemsTests.cs added in the Tasks test directory
  • All 7 valid modes tested (can use [TestCase] parameterization)
  • Invalid mode error case tested
  • Multiple ABI output verified (correct paths and metadata)
  • Case-insensitive mode matching tested
  • All existing tests still pass
  • No new warnings introduced

Generated by Nightly Fix Finder for issue #11352 · ● 4.9M ·

  • expires on May 22, 2026, 5:17 PM UTC

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions