Skip to content

Commit 10d57d7

Browse files
MarLoerolfbjarne
andauthored
[msbuild] Return the plist value instead of the type (#23721)
When reading the value from a propertylist, the value is of base type PValueObject. When returning value.ToString() we get the type and not the actual value. FIX: We check and cast to IPValueObject and return the actual value. --------- Co-authored-by: Rolf Bjarne Kvinge <[email protected]>
1 parent 004505d commit 10d57d7

File tree

5 files changed

+293
-4
lines changed

5 files changed

+293
-4
lines changed

msbuild/Xamarin.MacDev.Tasks/Tasks/GetPropertyListValue.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ public override bool Execute ()
8181
i++;
8282
} while (i < path.Length);
8383

84-
if (array is not null || dict is not null) {
84+
if (array is not null || dict is not null || value.Type is PObjectType.Data) {
8585
Log.LogError (MSBStrings.E0157, value.Type.ToString ().ToLowerInvariant ());
8686
return false;
8787
}
8888

89-
Value = value.ToString ();
89+
Value = value is IPValueObject pvalue ? pvalue.Value.ToString () : value.ToString ();
9090

9191
return !Log.HasLoggedErrors;
9292
}

tests/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@ test-msbuild run-tests-msbuild:
144144
$(MAKE) test-macdev-tests test-macdev-tasks
145145

146146
# Example TEST_FILTER:
147-
# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp"
147+
# TEST_FILTER="--filter:FullyQualifiedName~BuildMyCocoaApp"
148148
# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details
149149
test-macdev-tests: export MSBUILD_EXE_PATH=
150150
test-macdev-tests: verify-system-vsmac-xcode-match
151151
$(Q) $(DOTNET) test $(TOP)/tests/msbuild/Xamarin.MacDev.Tests/Xamarin.MacDev.Tests.csproj $(TEST_FILTER)
152152

153153
# Example TEST_FILTER:
154-
# TEST_FILTER="--filter FullyQualifiedName~BuildMyCocoaApp"
154+
# TEST_FILTER="--filter:FullyQualifiedName~BuildMyCocoaApp"
155155
# Docs: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details
156156
test-macdev-tasks: export MSBUILD_EXE_PATH=
157157
test-macdev-tasks: verify-system-vsmac-xcode-match
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>KeyNumberInt</key>
6+
<integer>1013</integer>
7+
<key>KeyNumberDouble</key>
8+
<string>10.13</string>
9+
<key>KeyString</key>
10+
<string>MarLoe</string>
11+
<key>KeyBooleanTrue</key>
12+
<true/>
13+
<key>KeyBooleanFalse</key>
14+
<false/>
15+
<key>KeyDate</key>
16+
<date>1974-11-19T10:20:30Z</date>
17+
<key>KeyData</key>
18+
<data>AQID</data>
19+
<key>KeyArray</key>
20+
<array>
21+
<string>Array Item 0</string>
22+
<string>Array Item 1</string>
23+
<string>Array Item 2</string>
24+
<array>
25+
<string>Array Array Item 3.0</string>
26+
<string>Array Array Item 3.1</string>
27+
<string>Array Array Item 3.2</string>
28+
</array>
29+
<dict>
30+
<key>Item0</key>
31+
<string>Array Dictionary Item 4.0</string>
32+
<key>Item1</key>
33+
<string>Array Dictionary Item 4.1</string>
34+
<key>Item2</key>
35+
<string>Array Dictionary Item 4.2</string>
36+
</dict>
37+
</array>
38+
<key>KeyDictionary</key>
39+
<dict>
40+
<key>Item0</key>
41+
<string>Dictionary Item 0</string>
42+
<key>Item1</key>
43+
<string>Dictionary Item 1</string>
44+
<key>Item2</key>
45+
<string>Dictionary Item 2</string>
46+
<key>Item3</key>
47+
<dict>
48+
<key>Item0</key>
49+
<string>Dictionary Dictionary Item 3.0</string>
50+
<key>Item1</key>
51+
<string>Dictionary Dictionary Item 3.1</string>
52+
<key>Item2</key>
53+
<string>Dictionary Dictionary Item 3.2</string>
54+
</dict>
55+
<key>Item4</key>
56+
<array>
57+
<string>Dictionary Array Item 4.0</string>
58+
<string>Dictionary Array Item 4.1</string>
59+
<string>Dictionary Array Item 4.2</string>
60+
</array>
61+
</dict>
62+
</dict>
63+
</plist>
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
using System;
2+
using System.IO;
3+
using NUnit.Framework;
4+
5+
using Xamarin.MacDev;
6+
using Xamarin.MacDev.Tasks;
7+
8+
namespace Xamarin.MacDev.Tasks {
9+
[TestFixture]
10+
public class GetPropertyListValueTaskTests : TestBase {
11+
12+
void TestExecuteTask (string property, string expected)
13+
{
14+
var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "PropertyList.plist");
15+
var task = CreateTask<GetPropertyListValue> ();
16+
task.PropertyListFile = path;
17+
task.Property = property;
18+
19+
if (expected is null) {
20+
Assert.IsFalse (task.Execute (), "Task was expected to fail.");
21+
return;
22+
}
23+
24+
Assert.IsTrue (task.Execute (), "Task was expected to execute successfully.");
25+
26+
Assert.AreEqual (expected, task.Value, "Task produced the incorrect plist output.");
27+
}
28+
29+
[Test]
30+
public void TestWithColonPrefix ()
31+
{
32+
const string property = "KeyString";
33+
const string expected = "MarLoe";
34+
35+
TestExecuteTask (":" + property, expected);
36+
}
37+
38+
39+
[Test]
40+
public void TestWithoutColonPrefix ()
41+
{
42+
const string property = "KeyString";
43+
const string expected = "MarLoe";
44+
45+
TestExecuteTask (property, expected);
46+
}
47+
48+
[Test]
49+
public void TestReturnArrayNotSupported ()
50+
{
51+
const string property = "KeyArray";
52+
53+
TestExecuteTask (property, null);
54+
}
55+
56+
[Test]
57+
public void TestReturnDictionaryNotSupported ()
58+
{
59+
const string property = "KeyDictionary";
60+
61+
TestExecuteTask (property, null);
62+
}
63+
64+
[Test]
65+
public void TestReturnDataNotSupported ()
66+
{
67+
const string property = "KeyData";
68+
69+
TestExecuteTask (property, null);
70+
}
71+
72+
[Test]
73+
public void TestKeyNotFound ()
74+
{
75+
const string property = "ThisKeyDoesNotExist";
76+
77+
TestExecuteTask (property, null);
78+
}
79+
80+
[Test]
81+
public void TestGetStringProperty ()
82+
{
83+
const string property = "KeyString";
84+
const string expected = "MarLoe";
85+
86+
TestExecuteTask (property, expected);
87+
}
88+
89+
[Test]
90+
public void TestGetIntegerProperty ()
91+
{
92+
const string property = "KeyNumberInt";
93+
const string expected = "1013";
94+
95+
TestExecuteTask (property, expected);
96+
}
97+
98+
[Test]
99+
public void TestGetDoubleProperty ()
100+
{
101+
const string property = "KeyNumberDouble";
102+
const string expected = "10.13";
103+
104+
TestExecuteTask (property, expected);
105+
}
106+
107+
[Test]
108+
public void TestGetBooleanTrueProperty ()
109+
{
110+
const string property = "KeyBooleanTrue";
111+
const string expected = "True";
112+
113+
TestExecuteTask (property, expected);
114+
}
115+
116+
[Test]
117+
public void TestGetBooleanFalseProperty ()
118+
{
119+
const string property = "KeyBooleanFalse";
120+
const string expected = "False";
121+
122+
TestExecuteTask (property, expected);
123+
}
124+
125+
[Test]
126+
public void TestGetDateProperty ()
127+
{
128+
const string property = "KeyDate";
129+
const string expected = "11/19/1974 10:20:30 AM";
130+
131+
TestExecuteTask (property, expected);
132+
}
133+
134+
[Test]
135+
public void TestGetArrayIndexOutOfBounds ()
136+
{
137+
var property = $"KeyArray:99";
138+
139+
TestExecuteTask (property, null);
140+
}
141+
142+
[Test]
143+
[TestCase (0)]
144+
[TestCase (1)]
145+
[TestCase (2)]
146+
public void TestGetArrayIndexProperty (int index)
147+
{
148+
var property = $"KeyArray:{index}";
149+
var expected = $"Array Item {index}";
150+
151+
TestExecuteTask (property, expected);
152+
}
153+
154+
[Test]
155+
[TestCase (0)]
156+
[TestCase (1)]
157+
[TestCase (2)]
158+
public void TestGetArrayArrayIndexProperty (int index)
159+
{
160+
var property = $"KeyArray:3:{index}";
161+
var expected = $"Array Array Item 3.{index}";
162+
163+
TestExecuteTask (property, expected);
164+
}
165+
166+
[Test]
167+
[TestCase (0)]
168+
[TestCase (1)]
169+
[TestCase (2)]
170+
public void TestGetArrayDictionaryKeyProperty (int index)
171+
{
172+
var property = $"KeyArray:4:Item{index}";
173+
var expected = $"Array Dictionary Item 4.{index}";
174+
175+
TestExecuteTask (property, expected);
176+
}
177+
178+
[Test]
179+
public void TestGetDictionaryKeyNotFound ()
180+
{
181+
var property = $"KeyDictionary:ItemKeyNotFound";
182+
183+
TestExecuteTask (property, null);
184+
}
185+
186+
[Test]
187+
[TestCase (0)]
188+
[TestCase (1)]
189+
[TestCase (2)]
190+
public void TestGetDictionaryKeyProperty (int index)
191+
{
192+
var property = $"KeyDictionary:Item{index}";
193+
var expected = $"Dictionary Item {index}";
194+
195+
TestExecuteTask (property, expected);
196+
}
197+
198+
[Test]
199+
[TestCase (0)]
200+
[TestCase (1)]
201+
[TestCase (2)]
202+
public void TestGetDictionaryDictionaryKeyProperty (int index)
203+
{
204+
var property = $"KeyDictionary:Item3:Item{index}";
205+
var expected = $"Dictionary Dictionary Item 3.{index}";
206+
207+
TestExecuteTask (property, expected);
208+
}
209+
210+
[Test]
211+
[TestCase (0)]
212+
[TestCase (1)]
213+
[TestCase (2)]
214+
public void TestGetDictionaryArrayKeyProperty (int index)
215+
{
216+
var property = $"KeyDictionary:Item4:{index}";
217+
var expected = $"Dictionary Array Item 4.{index}";
218+
219+
TestExecuteTask (property, expected);
220+
}
221+
222+
}
223+
}

tests/msbuild/Xamarin.MacDev.Tasks.Tests/Xamarin.MacDev.Tasks.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@
123123
</None>
124124
</ItemGroup>
125125
<ItemGroup>
126+
<None Update="Resources\PropertyList.plist">
127+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
128+
</None>
126129
<None Update="Resources\xcf-xcode12.2.plist">
127130
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
128131
</None>

0 commit comments

Comments
 (0)