Skip to content

Commit c1c1e62

Browse files
author
kuiper
committed
v1.8
1 parent b8383e2 commit c1c1e62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1368
-300
lines changed

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
###############################################################################
44

55
INTERNAL/
6-
_PupWin/
7-
PupWin/
86

97
###############################################################################
108
# Hidden
@@ -19,13 +17,13 @@ PupWin/
1917
*.lock
2018
*.~lock
2119

22-
# Explicitly Allow
23-
!.gitignore
24-
2520
Thumbs.db
2621
Thumbs.db:encryptable
2722
desktop.ini
2823

24+
# Explicitly Allow
25+
!.gitignore
26+
2927
###############################################################################
3028
# Ignore Builds & Binaries
3129
###############################################################################

CHANGES

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
+ VERSION 1.8.0; 2024-03-18
2+
- Built with .NET8
3+
- Added -j,--project command line argument.
4+
- Now detects the $DOTNET_HOST_PATH environment variable and uses it if defined.
5+
- Updated documentation concerning NETSDK1194. #27
6+
- Updated default FlatpakPlatformVersion to latest 23.08 at time of writing.
7+
- Removed dependency on Yaap.
8+
- Bugfix: Added trailing ';' to Categories value of desktop file. #33
9+
- BugFix: Use of ';' between property values did not work. Should now use ',' with pupnet.
10+
11+
112
+ VERSION 1.7.1; 2023-10-26
213
- Bugfix: Fix upgrade-conf bug introduced in 1.7.0.
314

PupNet.Test/AppImageBuilderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -----------------------------------------------------------------------------
22
// PROJECT : PupNet
3-
// COPYRIGHT : Andy Thomas (C) 2022-23
3+
// COPYRIGHT : Andy Thomas (C) 2022-24
44
// LICENSE : GPL-3.0-or-later
55
// HOMEPAGE : https://github.com/kuiperzone/PupNet
66
//

PupNet.Test/AppStreamTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// -----------------------------------------------------------------------------
22
// PROJECT : PupNet
3-
// COPYRIGHT : Andy Thomas (C) 2022-23
3+
// COPYRIGHT : Andy Thomas (C) 2022-24
44
// LICENSE : GPL-3.0-or-later
55
// HOMEPAGE : https://github.com/kuiperzone/PupNet
66
//

PupNet.Test/ArgumentParserTest.cs

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,316 @@
1+
// -----------------------------------------------------------------------------
2+
// PROJECT : Avant Garde
3+
// COPYRIGHT : Andy Thomas (C) 2022-24
4+
// LICENSE : GPL-3.0-or-later
5+
// HOMEPAGE : https://github.com/kuiperzone/AvantGarde
6+
//
7+
// Avant Garde is free software: you can redistribute it and/or modify it under
8+
// the terms of the GNU General Public License as published by the Free Software
9+
// Foundation, either version 3 of the License, or (at your option) any later version.
10+
//
11+
// Avant Garde is distributed in the hope that it will be useful, but WITHOUT
12+
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13+
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU General Public License along
16+
// with Avant Garde. If not, see <https://www.gnu.org/licenses/>.
17+
// -----------------------------------------------------------------------------
18+
19+
using Xunit;
20+
21+
namespace KuiperZone.PupNet.Test;
22+
23+
public class ArgumentParserTest
24+
{
25+
[Fact]
26+
public void Constructor_String_LinuxStyle_IndexerGivesExpected()
27+
{
28+
// All systems
29+
var str = "FloatValue1 FloatValue2 -a A -b=B -c:C -xyz --Hello \"Hello World\" -u";
30+
var ap = new ArgumentParser(str);
31+
32+
Assert.Equal("FloatValue1", ap.Values[0]);
33+
Assert.Equal("FloatValue2", ap.Values[1]);
34+
35+
Assert.Equal("A", ap["a"]);
36+
Assert.Equal("B", ap["b"]);
37+
Assert.Equal("C", ap["c"]);
38+
39+
Assert.Equal("true", ap["x"]);
40+
Assert.Equal("true", ap["y"]);
41+
Assert.Equal("true", ap["z"]);
42+
43+
Assert.Equal("Hello World", ap["Hello"]);
44+
Assert.Equal("true", ap["u"]);
45+
46+
Assert.Null(ap["None"]);
47+
48+
// Verbatim string
49+
Assert.Equal(str, ap.ToString());
50+
}
51+
52+
[Fact]
53+
public void Constructor_String_WindowsStyle_IndexerGivesExpected()
54+
{
55+
// Windows style
56+
if (ArgumentParser.AcceptWinStyle)
57+
{
58+
var str = "FloatValue1 FloatValue2 /a A /b=B /c:C /xyz /Hello:\"Hello World\" /u";
59+
var ap = new ArgumentParser(str);
60+
61+
Assert.Equal("FloatValue1", ap.Values[0]);
62+
Assert.Equal("FloatValue2", ap.Values[1]);
63+
64+
Assert.Equal("A", ap["a"]);
65+
Assert.Equal("B", ap["b"]);
66+
Assert.Equal("C", ap["c"]);
67+
68+
Assert.Equal("true", ap["xyz"]);
69+
70+
Assert.Equal("Hello World", ap["Hello"]);
71+
Assert.Equal("true", ap["u"]);
72+
73+
Assert.Null(ap["None"]);
74+
}
75+
}
76+
77+
[Fact]
78+
public void Constructor_Array_IndexerGivesExpected()
79+
{
80+
// Explicit Linux style
81+
var arr = new string[] { "FloatValue1", "FloatValue2", "-a", "A", "-b=B", "-c:C", "-xyz", "--Hello", "\"Hello World\"", "-u" };
82+
var ap = new ArgumentParser(arr);
83+
84+
Assert.Equal("FloatValue1", ap.Values[0]);
85+
Assert.Equal("FloatValue2", ap.Values[1]);
86+
87+
Assert.Equal("A", ap["a"]);
88+
Assert.Equal("B", ap["b"]);
89+
Assert.Equal("C", ap["c"]);
90+
91+
Assert.Equal("true", ap["x"]);
92+
Assert.Equal("true", ap["y"]);
93+
Assert.Equal("true", ap["z"]);
94+
95+
Assert.Equal("Hello World", ap["Hello"]);
96+
97+
Assert.Equal("true", ap["u"]);
98+
99+
Assert.Null(ap["None"]);
100+
}
101+
102+
[Fact]
103+
public void Constructor_MultipleSeparators_IndexerGivesExpected()
104+
{
105+
// Known use case - where ' ', '=' and ':' - finds first.
106+
var str = "-p DefineConstants=FLAG";
107+
var ap = new ArgumentParser(str);
108+
Assert.Equal("DefineConstants=FLAG", ap["p"]);
109+
110+
str = "-p:DefineConstants=FLAG";
111+
ap = new ArgumentParser(str);
112+
Assert.Equal("DefineConstants=FLAG", ap["p"]);
113+
114+
str = "-p=DefineConstants=FLAG";
115+
ap = new ArgumentParser(str);
116+
Assert.Equal("DefineConstants=FLAG", ap["p"]);
117+
118+
str = "-p : DefineConstants=FLAG";
119+
ap = new ArgumentParser(str);
120+
Assert.Equal("DefineConstants=FLAG", ap["p"]);
121+
122+
str = "-p = DefineConstants=FLAG";
123+
ap = new ArgumentParser(str);
124+
Assert.Equal("DefineConstants=FLAG", ap["p"]);
125+
}
126+
127+
[Fact]
128+
public void Constructor_ThrowsWithRepeatedKey()
129+
{
130+
var str = "FloatValue -a=A -b=B -a=C";
131+
Assert.Throws<ArgumentException>(() => new ArgumentParser(str));
132+
133+
str = "FloatValue -a=A -b=B -a";
134+
Assert.Throws<ArgumentException>(() => new ArgumentParser(str));
135+
136+
str = "FloatValue -a=A -a -b=B";
137+
Assert.Throws<ArgumentException>(() => new ArgumentParser(str));
138+
}
139+
140+
[Fact]
141+
public void Constructor_ThrowsWithErroneousValues()
142+
{
143+
var str = "FloatValue -a=A Value2 -b=B";
144+
Assert.Throws<ArgumentException>(() => new ArgumentParser(str));
145+
146+
str = "FloatValue Value2 -a=A -b=B Value2";
147+
Assert.Throws<ArgumentException>(() => new ArgumentParser(str));
148+
}
149+
150+
[Fact]
151+
public void Constructor_String_SentenceWithApostropieOK()
152+
{
153+
var ap = new ArgumentParser("--input=\"Wayne's world's\"");
154+
Assert.Equal("Wayne's world's", ap["input"]);
155+
}
156+
157+
[Fact]
158+
public void GetOrThrow_ThrowsIfNotExist()
159+
{
160+
var str = "FloatValue -a=A -b=B";
161+
var ap = new ArgumentParser(str);
162+
163+
// OK
164+
Assert.Equal("A", ap.GetOrThrow("a"));
165+
Assert.Equal("A", ap.GetOrThrow('a', "Alpha"));
166+
167+
// Not OK
168+
Assert.Throws<ArgumentException>(() => ap.GetOrThrow("K"));
169+
Assert.Throws<ArgumentException>(() => ap.GetOrThrow('K', "kay"));
170+
}
171+
172+
[Fact]
173+
public void GetOrThrow_Generic_ConvertsValue()
174+
{
175+
var str = "FloatValue --double=3.142 --enum Value2 --int=-3 --bool1 False --bool2 Yes --bool3 NO";
176+
var ap = new ArgumentParser(str);
177+
178+
// OK
179+
Assert.Equal(3.142, ap.GetOrThrow<double>("double"));
180+
Assert.Equal(TestType.Value2, ap.GetOrThrow<TestType>("enum"));
181+
182+
// Must use equal as separator for minus (above)
183+
Assert.Equal(-3, ap.GetOrThrow<int>("int"));
184+
185+
Assert.False(ap.GetOrThrow<bool>("bool1"));
186+
Assert.True(ap.GetOrThrow<bool>("bool2"));
187+
Assert.False(ap.GetOrThrow<bool>("bool3"));
188+
189+
// Overload - two keys
190+
Assert.False(ap.GetOrThrow<bool>('b', "bool1"));
191+
Assert.True(ap.GetOrThrow<bool>('b', "bool2"));
192+
Assert.False(ap.GetOrThrow<bool>('b', "bool3"));
193+
}
194+
195+
[Fact]
196+
public void GetOrThrow_Generic_ThrowsOnInvalid()
197+
{
198+
var str = "FloatValue --double=3.142 --enum Value2 --int=-3 --bool1 False --bool2 Yes --bool3 NO";
199+
var ap = new ArgumentParser(str);
200+
201+
Assert.Throws<FormatException>(() => ap.GetOrThrow<double>("enum"));
202+
Assert.Throws<FormatException>(() => ap.GetOrThrow<TestType>("double"));
203+
Assert.Throws<FormatException>(() => ap.GetOrThrow<bool>("int"));
204+
}
205+
206+
[Fact]
207+
public void GetOrDefault_GivesDefaultIfNotExist()
208+
{
209+
var str = "FloatValue -a=A -b=B";
210+
var ap = new ArgumentParser(str);
211+
212+
// OK
213+
Assert.Equal("A", ap.GetOrDefault("a", "X"));
214+
Assert.Equal("A", ap.GetOrDefault('a', "Alpha", "X"));
215+
216+
// Defaults
217+
Assert.Equal("X", ap.GetOrDefault("K", "X"));
218+
Assert.Equal("X", ap.GetOrDefault('K', "Kay", "X"));
219+
}
220+
221+
[Fact]
222+
public void GetOrDefault_Generic_ConvertsValue()
223+
{
224+
var str = "FloatValue --double=3.142 --enum Value2 --int=-3 --bool1 False --bool2 Yes --bool3 NO";
225+
var ap = new ArgumentParser(str);
226+
227+
// OK
228+
Assert.Equal(3.142, ap.GetOrDefault("double", 99.8));
229+
Assert.Equal(TestType.Value2, ap.GetOrDefault("enum", TestType.None));
230+
231+
// Must use equal as separator for minus (above)
232+
Assert.Equal(-3, ap.GetOrDefault("int", 88));
233+
234+
Assert.False(ap.GetOrDefault("bool1", true));
235+
Assert.True(ap.GetOrDefault("bool2", false));
236+
Assert.False(ap.GetOrDefault("bool3", true));
237+
238+
// Overload - two keys
239+
Assert.False(ap.GetOrDefault('b', "bool1", true));
240+
Assert.True(ap.GetOrDefault('b', "bool2", false));
241+
Assert.False(ap.GetOrDefault('b', "bool3", true));
242+
243+
}
244+
245+
[Fact]
246+
public void GetOrDefault_Generic_ThrowsOnInvalid()
247+
{
248+
var str = "FloatValue --double=3.142 --enum Value2 --int=-3 --bool1 False --bool2 Yes --bool3 NO";
249+
var ap = new ArgumentParser(str);
250+
251+
Assert.Throws<FormatException>(() => ap.GetOrDefault("enum", 44.3));
252+
Assert.Throws<FormatException>(() => ap.GetOrDefault("double", TestType.None));
253+
Assert.Throws<FormatException>(() => ap.GetOrDefault("int", false));
254+
}
255+
256+
[Fact]
257+
public void Clone_StripsValueAndKeys()
258+
{
259+
var str = "FloatValue -a A -b=B -c:C -xyz --Hello \"Hello World\" -u";
260+
var ap1 = new ArgumentParser(str);
261+
262+
var ap2 = ap1.Clone(true, "a", "y", "c");
263+
264+
Assert.Empty(ap2.Values);
265+
Assert.Null(ap2["a"]);
266+
Assert.NotNull(ap2["b"]);
267+
Assert.Equal("-b=B -x=true -z=true --Hello=\"Hello World\" -u=true", ap2.ToString());
268+
}
269+
270+
[Fact]
271+
public void Clone_ClonesVerbatim()
272+
{
273+
var str = "FloatValue -a A -b=B -c:C -xyz --Hello \"Hello World\" -u";
274+
var ap1 = new ArgumentParser(str);
275+
276+
var ap2 = ap1.Clone();
277+
278+
Assert.Equal("FloatValue", ap2.Values[0]);
279+
Assert.Equal(str, ap2.ToString());
280+
}
281+
282+
[Fact]
283+
public void ToString_ReturnsExpected()
284+
{
285+
// Verbatim string
286+
var str = "FloatValue -a A -b=B -c:C -xyz --Hello \"Hello World\" -u";
287+
var ap = new ArgumentParser(str);
288+
Assert.Equal(str, ap.ToString());
289+
290+
// String will be built - not verbatim
291+
var arr = new string[] { "FloatValue", "-a", "A", "-b=B", "-c:C", "-xyz", "--Hello", "\"Hello World\"", "-u" };
292+
var exp = "FloatValue -a=A -b=B -c=C -x=true -y=true -z=true --Hello=\"Hello World\" -u=true";
293+
ap = new ArgumentParser(arr);
294+
Assert.Equal(exp, ap.ToString());
295+
}
296+
297+
[Fact]
298+
public void RegressionTest()
299+
{
300+
// We use this as regression with commands we may use
301+
var ap = new ArgumentParser("mongod --port 27018 --directoryperdb --dbpath /home/kuiper/Scratch/MONGODB");
302+
Assert.Equal("mongod", ap.Values[0]);
303+
Assert.Equal("27018", ap["port"]);
304+
Assert.Equal("true", ap["directoryperdb"]);
305+
Assert.Equal("/home/kuiper/Scratch/MONGODB", ap["dbpath"]);
306+
307+
Assert.Equal("--port=27018 --directoryperdb=true --dbpath=/home/kuiper/Scratch/MONGODB", ap.Clone(true).ToString());
308+
}
309+
310+
private enum TestType
311+
{
312+
None,
313+
Value1,
314+
Value2,
315+
}
316+
}

0 commit comments

Comments
 (0)