Skip to content

Add unit tests for PrepareAbiItems MSBuild task#11371

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/add-unit-tests-for-prepare-abi-items
Closed

Add unit tests for PrepareAbiItems MSBuild task#11371
Copilot wants to merge 2 commits into
mainfrom
copilot/add-unit-tests-for-prepare-abi-items

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

PrepareAbiItems has no test coverage for its mode-to-basename mapping and ABI-specific path construction logic.

Adds PrepareAbiItemsTests.cs with 18 tests covering:

  • All 7 valid modes via [TestCase] parameterization (typemaptypemaps, environmentenvironment, compressedcompressed_assemblies, jniremapjni_remap, marshal_methodsmarshal_methods, runtime_linkingpinvoke_preserve, jni_initjni_init_funcs)
  • Case-insensitive mode matching (TypeMap, TYPEMAP, COMPRESSED, etc.)
  • Invalid mode — verifies error is logged and Execute() returns false
  • Multiple ABIs — verifies correct item count, paths, and abi metadata for all 4 ABIs
  • Single ABI — basic smoke test
[TestCase ("typemap", "typemaps")]
[TestCase ("environment", "environment")]
// ...
public void ValidMode_ProducesCorrectBaseName (string mode, string expectedBase)
{
    var task = new PrepareAbiItems {
        BuildEngine = new MockBuildEngine (TestContext.Out),
        BuildTargetAbis = new [] { "arm64-v8a" },
        NativeSourcesDir = "/native/src",
        Mode = mode,
        Debug = false,
    };
    Assert.IsTrue (task.Execute ());
    Assert.AreEqual ($"/native/src/{expectedBase}.arm64-v8a.ll", task.AssemblySources [0].ItemSpec);
}

Agent-Logs-Url: https://github.com/dotnet/android/sessions/2ef0252b-37ea-41b8-bccc-d6d3598eaf98

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for PrepareAbiItems MSBuild task Add unit tests for PrepareAbiItems MSBuild task May 15, 2026
Copilot AI requested a review from jonathanpeppers May 15, 2026 17:45
@jonathanpeppers jonathanpeppers marked this pull request as ready for review May 15, 2026 18:49
Copilot AI review requested due to automatic review settings May 15, 2026 18:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds NUnit coverage for the PrepareAbiItems MSBuild task’s mode→basename mapping, case-insensitive mode handling, and ABI-specific output item construction. This helps prevent regressions in how the task computes .ll source paths and abi metadata.

Changes:

  • Introduces a new PrepareAbiItemsTests test fixture with parameterized cases for all supported Mode values.
  • Adds tests for case-insensitive Mode matching and invalid mode error behavior.
  • Adds tests validating output item count, ItemSpec path construction, and abi metadata across single/multiple ABIs.
Comments suppressed due to low confidence (3)

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs:56

  • Same issue here: the expected ItemSpec is built with a hard-coded '/'. Since the task uses Path.Combine, construct the expected path with Path.Combine and use a case-insensitive comparison appropriate for paths.
			Assert.IsTrue (task.Execute ());
			Assert.IsNotNull (task.AssemblySources);
			Assert.AreEqual (1, task.AssemblySources.Length);
			Assert.AreEqual ($"/native/src/{expectedBase}.x86_64.ll", task.AssemblySources [0].ItemSpec);
		}

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs:89

  • This test also assumes '/' separators in the produced ItemSpec. Use Path.Combine (NativeSourcesDir, $"typemaps.{abis[i]}.ll") (or similar) for expected values so the test passes cross-platform.
			Assert.IsNotNull (task.AssemblySources);
			Assert.AreEqual (abis.Length, task.AssemblySources.Length);
			for (int i = 0; i < abis.Length; i++) {
				Assert.AreEqual ($"/native/src/typemaps.{abis [i]}.ll", task.AssemblySources [i].ItemSpec);
				Assert.AreEqual (abis [i], task.AssemblySources [i].GetMetadata ("abi"));

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/PrepareAbiItemsTests.cs:107

  • Hard-coding the expected ItemSpec with '/' will be platform-dependent because PrepareAbiItems uses Path.Combine. Build the expected path with Path.Combine and compare using the same path comparison pattern used in other tests (e.g., StringAssert.AreEqualIgnoringCase).
			Assert.IsNotNull (task.AssemblySources);
			Assert.AreEqual (1, task.AssemblySources.Length);
			Assert.AreEqual ("/output/environment.x86.ll", task.AssemblySources [0].ItemSpec);
			Assert.AreEqual ("x86", task.AssemblySources [0].GetMetadata ("abi"));

Comment on lines +29 to +32
Assert.IsNotNull (task.AssemblySources);
Assert.AreEqual (1, task.AssemblySources.Length);
Assert.AreEqual ($"/native/src/{expectedBase}.arm64-v8a.ll", task.AssemblySources [0].ItemSpec);
Assert.AreEqual ("arm64-v8a", task.AssemblySources [0].GetMetadata ("abi"));
@@ -0,0 +1,110 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
Comment on lines +7 to +11
namespace Xamarin.Android.Build.Tests
{
[TestFixture]
public class PrepareAbiItemsTests : BaseTest
{
Debug = false,
};
Assert.IsFalse (task.Execute ());
Assert.AreEqual (1, errors.Count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants