From 0844476e8acdc6f761384b283a28f6ec582170bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B8bger?= Date: Tue, 2 Sep 2025 08:02:55 +0200 Subject: [PATCH 1/6] Return the plist value instead of the type --- msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs index ef25b3af82a4..2fc908a0c8c3 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs @@ -86,7 +86,7 @@ public override bool Execute () return false; } - Value = value.ToString (); + Value = value is IPValueObject pvalue ? pvalue.Value.ToString () : value.ToString (); return !Log.HasLoggedErrors; } From 9455c0b41665a93ba2e86fecc98fc623a125a1e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B8bger?= Date: Thu, 4 Sep 2025 11:14:32 +0200 Subject: [PATCH 2/6] Type data is not supported to read from property list --- msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs index 2fc908a0c8c3..2710251abd02 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs @@ -81,7 +81,7 @@ public override bool Execute () i++; } while (i < path.Length); - if (array is not null || dict is not null) { + if (array is not null || dict is not null || value.Type is PObjectType.Data) { Log.LogError (MSBStrings.E0157, value.Type.ToString ().ToLowerInvariant ()); return false; } From 83b644adfca0bfb54ae1641bbebd0e869e1af543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B8bger?= Date: Thu, 4 Sep 2025 11:15:14 +0200 Subject: [PATCH 3/6] Add unit tests for GetPropertyListValue task --- .../Resources/PropertyList.plist | 63 ++++++ .../GetPropertyListValueTaskTests.cs | 208 ++++++++++++++++++ .../Xamarin.MacDev.Tasks.Tests.csproj | 3 + 3 files changed, 274 insertions(+) create mode 100644 tests/msbuild/Xamarin.MacDev.Tasks.Tests/Resources/PropertyList.plist create mode 100644 tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Resources/PropertyList.plist b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Resources/PropertyList.plist new file mode 100644 index 000000000000..450d83d1278b --- /dev/null +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Resources/PropertyList.plist @@ -0,0 +1,63 @@ + + + + + KeyNumberInt + 1013 + KeyNumberDouble + 10.13 + KeyString + MarLoe + KeyBooleanTrue + + KeyBooleanFalse + + KeyDate + 1974-11-19T10:20:30Z + KeyData + AQID + KeyArray + + Array Item 0 + Array Item 1 + Array Item 2 + + Array Array Item 3.0 + Array Array Item 3.1 + Array Array Item 3.2 + + + Item0 + Array Dictionary Item 4.0 + Item1 + Array Dictionary Item 4.1 + Item2 + Array Dictionary Item 4.2 + + + KeyDictionary + + Item0 + Dictionary Item 0 + Item1 + Dictionary Item 1 + Item2 + Dictionary Item 2 + Item3 + + Item0 + Dictionary Dictionary Item 3.0 + Item1 + Dictionary Dictionary Item 3.1 + Item2 + Dictionary Dictionary Item 3.2 + + Item4 + + Dictionary Array Item 4.0 + Dictionary Array Item 4.1 + Dictionary Array Item 4.2 + + + + diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs new file mode 100644 index 000000000000..b87984f10540 --- /dev/null +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs @@ -0,0 +1,208 @@ +using System; +using System.IO; +using NUnit.Framework; + +using Xamarin.MacDev; +using Xamarin.MacDev.Tasks; + +namespace Xamarin.MacDev.Tasks { + [TestFixture] + public class GetPropertyListValueTaskTests : TestBase + { + + void TestExecuteTask (string property, string expected) + { + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "PropertyList.plist"); + var task = CreateTask (); + task.PropertyListFile = path; + task.Property = property; + + if (expected is null) { + Assert.IsFalse (task.Execute (), "Task was expected to fail."); + return; + } + + Assert.IsTrue (task.Execute (), "Task was expected to execute successfully."); + + Assert.AreEqual (expected, task.Value, "Task produced the incorrect plist output."); + } + + [Test] + public void TestWithColonPrefix () + { + const string property = "KeyString"; + const string expected = "MarLoe"; + + TestExecuteTask (":" + property, expected); + } + + + [Test] + public void TestWithoutColonPrefix () + { + const string property = "KeyString"; + const string expected = "MarLoe"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestReturnArrayNotSupported () + { + const string property = "KeyArray"; + + TestExecuteTask (property, null); + } + + [Test] + public void TestReturnDictionaryNotSupported () + { + const string property = "KeyDictionary"; + + TestExecuteTask (property, null); + } + + [Test] + public void TestReturnDataNotSupported () + { + const string property = "KeyData"; + + TestExecuteTask (property, null); + } + + [Test] + public void TestKeyNotFound () + { + const string property = "ThisKeyDoesNotExist"; + + TestExecuteTask (property, null); + } + + [Test] + public void TestGetStringProperty () + { + const string property = "KeyString"; + const string expected = "MarLoe"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestGetIntegerProperty () + { + const string property = "KeyNumberInt"; + const string expected = "1013"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestGetDoubleProperty () + { + const string property = "KeyNumberDouble"; + const string expected = "10.13"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestGetBooleanTrueProperty () + { + const string property = "KeyBooleanTrue"; + const string expected = "True"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestGetBooleanFalseProperty () + { + const string property = "KeyBooleanFalse"; + const string expected = "False"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestGetDateProperty () + { + const string property = "KeyDate"; + const string expected = "11/19/1974 10:20:30 AM"; + + TestExecuteTask (property, expected); + } + + [Test] + public void TestGetArrayIndexProperty () + { + for (var index = 0; index < 3; index++) + { + var property = $"KeyArray:{index}"; + var expected = $"Array Item {index}"; + + TestExecuteTask (property, expected); + } + } + + [Test] + public void TestGetArrayArrayIndexProperty () + { + for (var index = 0; index < 3; index++) + { + var property = $"KeyArray:3:{index}"; + var expected = $"Array Array Item 3.{index}"; + + TestExecuteTask (property, expected); + } + } + + [Test] + public void TestGetArrayDictionaryKeyProperty () + { + for (var index = 0; index < 3; index++) + { + var property = $"KeyArray:4:Item{index}"; + var expected = $"Array Dictionary Item 4.{index}"; + + TestExecuteTask (property, expected); + } + } + + [Test] + public void TestGetDictionaryKeyProperty () + { + for (var index = 0; index < 3; index++) + { + var property = $"KeyDictionary:Item{index}"; + var expected = $"Dictionary Item {index}"; + + TestExecuteTask (property, expected); + } + } + + [Test] + public void TestGetDictionaryDictionaryKeyProperty () + { + for (var index = 0; index < 3; index++) + { + var property = $"KeyDictionary:Item3:Item{index}"; + var expected = $"Dictionary Dictionary Item 3.{index}"; + + TestExecuteTask (property, expected); + } + } + + [Test] + public void TestGetDictionaryArrayKeyProperty () + { + for (var index = 0; index < 3; index++) + { + var property = $"KeyDictionary:Item4:{index}"; + var expected = $"Dictionary Array Item 4.{index}"; + + TestExecuteTask (property, expected); + } + } + + } +} diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj index 41efdcd89704..e4084587043e 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj @@ -123,6 +123,9 @@ + + PreserveNewest + PreserveNewest From 34b8dff24d7c7177cf49d870c7a6f7e34dda130b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B8bger?= Date: Thu, 4 Sep 2025 12:32:18 +0200 Subject: [PATCH 4/6] Correction to unit test documentation --- tests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 1df2d318d341..d384662ef979 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -144,14 +144,14 @@ test-msbuild run-tests-msbuild: $(MAKE) test-macdev-tests test-macdev-tasks # Example TEST_FILTER: -# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" +# TEST_FILTER="--filter:FullyQualifiedName~BuildMyCocoaApp" # Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tests: export MSBUILD_EXE_PATH= test-macdev-tests: verify-system-vsmac-xcode-match $(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj $(TEST_FILTER) # Example TEST_FILTER: -# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp" +# TEST_FILTER="--filter:FullyQualifiedName~BuildMyCocoaApp" # Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details test-macdev-tasks: export MSBUILD_EXE_PATH= test-macdev-tasks: verify-system-vsmac-xcode-match From 954dbd5fcdf48f3d1dd012e71de71e38fc5b7bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20L=C3=B8bger?= Date: Thu, 4 Sep 2025 14:12:33 +0200 Subject: [PATCH 5/6] Adding and improving GetPropertyListValueTaskTests tests --- .../GetPropertyListValueTaskTests.cs | 103 ++++++++++-------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs index b87984f10540..93734b27bbfc 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs @@ -7,8 +7,7 @@ namespace Xamarin.MacDev.Tasks { [TestFixture] - public class GetPropertyListValueTaskTests : TestBase - { + public class GetPropertyListValueTaskTests : TestBase { void TestExecuteTask (string property, string expected) { @@ -133,75 +132,91 @@ public void TestGetDateProperty () } [Test] - public void TestGetArrayIndexProperty () + public void TestGetArrayIndexOutOfBounds () { - for (var index = 0; index < 3; index++) - { - var property = $"KeyArray:{index}"; - var expected = $"Array Item {index}"; + var property = $"KeyArray:99"; - TestExecuteTask (property, expected); - } + TestExecuteTask(property, null); } [Test] - public void TestGetArrayArrayIndexProperty () + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void TestGetArrayIndexProperty (int index) { - for (var index = 0; index < 3; index++) - { - var property = $"KeyArray:3:{index}"; - var expected = $"Array Array Item 3.{index}"; + var property = $"KeyArray:{index}"; + var expected = $"Array Item {index}"; - TestExecuteTask (property, expected); - } + TestExecuteTask(property, expected); } [Test] - public void TestGetArrayDictionaryKeyProperty () + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void TestGetArrayArrayIndexProperty (int index) { - for (var index = 0; index < 3; index++) - { - var property = $"KeyArray:4:Item{index}"; - var expected = $"Array Dictionary Item 4.{index}"; + var property = $"KeyArray:3:{index}"; + var expected = $"Array Array Item 3.{index}"; - TestExecuteTask (property, expected); - } + TestExecuteTask (property, expected); } [Test] - public void TestGetDictionaryKeyProperty () + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void TestGetArrayDictionaryKeyProperty (int index) { - for (var index = 0; index < 3; index++) - { - var property = $"KeyDictionary:Item{index}"; - var expected = $"Dictionary Item {index}"; + var property = $"KeyArray:4:Item{index}"; + var expected = $"Array Dictionary Item 4.{index}"; - TestExecuteTask (property, expected); - } + TestExecuteTask (property, expected); } [Test] - public void TestGetDictionaryDictionaryKeyProperty () + public void TestGetDictionaryKeyNotFound () { - for (var index = 0; index < 3; index++) - { - var property = $"KeyDictionary:Item3:Item{index}"; - var expected = $"Dictionary Dictionary Item 3.{index}"; + var property = $"KeyDictionary:ItemKeyNotFound"; - TestExecuteTask (property, expected); - } + TestExecuteTask (property, null); } [Test] - public void TestGetDictionaryArrayKeyProperty () + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void TestGetDictionaryKeyProperty (int index) { - for (var index = 0; index < 3; index++) - { - var property = $"KeyDictionary:Item4:{index}"; - var expected = $"Dictionary Array Item 4.{index}"; + var property = $"KeyDictionary:Item{index}"; + var expected = $"Dictionary Item {index}"; - TestExecuteTask (property, expected); - } + TestExecuteTask (property, expected); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void TestGetDictionaryDictionaryKeyProperty (int index) + { + var property = $"KeyDictionary:Item3:Item{index}"; + var expected = $"Dictionary Dictionary Item 3.{index}"; + + TestExecuteTask (property, expected); + } + + [Test] + [TestCase(0)] + [TestCase(1)] + [TestCase(2)] + public void TestGetDictionaryArrayKeyProperty (int index) + { + var property = $"KeyDictionary:Item4:{index}"; + var expected = $"Dictionary Array Item 4.{index}"; + + TestExecuteTask (property, expected); } } From 5a7bbcb62c15c8db09c571946f16140ce1f796e4 Mon Sep 17 00:00:00 2001 From: GitHub Actions Autoformatter Date: Tue, 9 Sep 2025 20:06:04 +0000 Subject: [PATCH 6/6] Auto-format source code --- .../GetPropertyListValueTaskTests.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs index 93734b27bbfc..986423990551 100644 --- a/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs +++ b/tests/msbuild/Xamarin.MacDev.Tasks.Tests/TaskTests/GetPropertyListValueTaskTests.cs @@ -136,25 +136,25 @@ public void TestGetArrayIndexOutOfBounds () { var property = $"KeyArray:99"; - TestExecuteTask(property, null); + TestExecuteTask (property, null); } [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] + [TestCase (0)] + [TestCase (1)] + [TestCase (2)] public void TestGetArrayIndexProperty (int index) { var property = $"KeyArray:{index}"; var expected = $"Array Item {index}"; - TestExecuteTask(property, expected); + TestExecuteTask (property, expected); } [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] + [TestCase (0)] + [TestCase (1)] + [TestCase (2)] public void TestGetArrayArrayIndexProperty (int index) { var property = $"KeyArray:3:{index}"; @@ -164,9 +164,9 @@ public void TestGetArrayArrayIndexProperty (int index) } [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] + [TestCase (0)] + [TestCase (1)] + [TestCase (2)] public void TestGetArrayDictionaryKeyProperty (int index) { var property = $"KeyArray:4:Item{index}"; @@ -184,9 +184,9 @@ public void TestGetDictionaryKeyNotFound () } [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] + [TestCase (0)] + [TestCase (1)] + [TestCase (2)] public void TestGetDictionaryKeyProperty (int index) { var property = $"KeyDictionary:Item{index}"; @@ -196,9 +196,9 @@ public void TestGetDictionaryKeyProperty (int index) } [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] + [TestCase (0)] + [TestCase (1)] + [TestCase (2)] public void TestGetDictionaryDictionaryKeyProperty (int index) { var property = $"KeyDictionary:Item3:Item{index}"; @@ -208,9 +208,9 @@ public void TestGetDictionaryDictionaryKeyProperty (int index) } [Test] - [TestCase(0)] - [TestCase(1)] - [TestCase(2)] + [TestCase (0)] + [TestCase (1)] + [TestCase (2)] public void TestGetDictionaryArrayKeyProperty (int index) { var property = $"KeyDictionary:Item4:{index}";