Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/PropertyListEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bool Add (PObject plist)

bool Clear (ref PObject plist)
{
if (Type is not null) {
if (!string.IsNullOrEmpty (Type)) {
switch (Type.ToLowerInvariant ()) {
case "string": plist = new PString (string.Empty); break;
case "array": plist = new PArray (); break;
Expand Down Expand Up @@ -391,7 +391,7 @@ bool Merge (PObject plist, PObject value)

bool Merge (PObject plist)
{
if (Entry is not null) {
if (!string.IsNullOrEmpty (Entry)) {
var path = GetPropertyPath ();
PObject? current = plist;
PDictionary? dict;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;

using Xamarin.MacDev;
Expand Down Expand Up @@ -28,6 +29,10 @@ static void CheckDictionary (PDictionary dict, PDictionary expected)

CheckValue (value, kvp.Value);
}

var expectedKeys = expected.Select (v => v.Key);
var actualKeys = dict.Select (v => v.Key);
Assert.That (expectedKeys, Is.EquivalentTo (actualKeys), "Keys");
}

static void CheckValue (PObject value, PObject expected)
Expand Down Expand Up @@ -61,14 +66,20 @@ static void CheckValue (PObject value, PObject expected)
}

void TestExecuteTask (PDictionary input, PropertyListEditorAction action, string entry, string type, string value, PObject expected)
{
var propertyList = Path.Combine (Cache.CreateTemporaryDirectory (), "propertyList.plist");
input.Save (propertyList);
TestExecuteTask (propertyList, action, entry, type, value, expected);
}

void TestExecuteTask (string propertyList, PropertyListEditorAction action, string entry, string type, string value, PObject expected)
{
var task = CreateTask<PropertyListEditor> ();
task.PropertyList = Path.Combine (Cache.CreateTemporaryDirectory (), "propertyList.plist");
task.PropertyList = propertyList;
task.Action = action.ToString ();
task.Entry = entry;
task.Type = type;
task.Value = value;
input.Save (task.PropertyList);

if (expected is null) {
Assert.IsFalse (task.Execute (), "Task was expected to fail.");
Expand Down Expand Up @@ -345,5 +356,58 @@ public void TestMergeArrays ()

TestExecuteTask (plist, PropertyListEditorAction.Merge, ":CFArrayItems", null, tmp, expected);
}

[Test]
public void TestMergeTwoFiles ()
{
var tmp = Cache.CreateTemporaryDirectory ();
var f1 = Path.Combine (tmp, "A.plist");
var f2 = Path.Combine (tmp, "B.plist");
File.WriteAllText (f1,
"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
""");
File.WriteAllText (f2,
"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.xamarin.monotouch-test</string>
</array>
</dict>
</plist>
""");

var expected = PObject.FromString (
"""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
<key>keychain-access-groups</key>
<array>
<string>$(AppIdentifierPrefix)com.xamarin.monotouch-test</string>
</array>
</dict>
</plist>
""");
TestExecuteTask (f1, PropertyListEditorAction.Merge, "", "", f2, expected);
}
}
}
Loading