forked from dn-vm/dnvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineTests.cs
More file actions
465 lines (387 loc) · 12.8 KB
/
CommandLineTests.cs
File metadata and controls
465 lines (387 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
using Serde;
using Serde.CmdLine;
using Spectre.Console.Testing;
using Xunit;
namespace Dnvm.Test;
public sealed class CommandLineTests
{
private static readonly string ExpectedHelpText = """
usage: dnvm [--enable-dnvm-previews] [-h | --help] <command>
Install and manage .NET SDKs.
Options:
--enable-dnvm-previews Enable dnvm previews.
-h, --help Show help information.
Commands:
install Install an SDK.
track Start tracking a new channel.
selfinstall Install dnvm to the local machine.
update Update the installed SDKs or dnvm itself.
list List installed SDKs.
select Select the active SDK directory.
untrack Remove a channel from the list of tracked channels.
uninstall Uninstall an SDK.
prune Remove all SDKs with older patch versions.
restore Restore the SDK listed in the global.json file.
""".NormalizeLineEndings();
[Fact]
public void NoCommand()
{
var console = new TestConsole();
var options = CommandLineArguments.ParseRaw(console, []);
Assert.NotNull(options);
Assert.Null(options.SubCommand);
Assert.Equal(ExpectedHelpText, console.Output);
}
[Fact]
public void Restore()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"restore"
]);
Assert.True(options!.SubCommand is DnvmSubCommand.RestoreArgs);
}
[Fact]
public void List()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"list"
]);
Assert.True(options!.SubCommand is DnvmSubCommand.ListArgs);
}
[Fact]
public void SelectWithDir()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"select",
"preview"
]);
Assert.True(options!.SubCommand is DnvmSubCommand.SelectArgs {
SdkDirName: "preview"
});
}
[Fact]
public void TrackMissingChannel()
{
Assert.Throws<ArgumentSyntaxException>(() => CommandLineArguments.ParseRaw(new TestConsole(), [
"track"
]));
}
[Fact]
public void TrackMajorMinor()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"track",
"99.99"
]);
Assert.True(options!.SubCommand is DnvmSubCommand.TrackArgs {
Channel: Channel.VersionedMajorMinor { Major: 99, Minor: 99 }
});
}
[Fact]
public void TrackFeature()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"track",
"99.99.9xx"
]);
Assert.True(options!.SubCommand is DnvmSubCommand.TrackArgs {
Channel: Channel.VersionedFeature { Major: 99, Minor: 99, FeatureLevel: 9 }
});
}
[Theory]
[InlineData("badchannel")]
[InlineData("99.99.9x")]
[InlineData("99.99.9xxx")]
[InlineData("99.99.900")]
[InlineData("99.99.axx")]
public void TrackBadChannel(string channel)
{
var ex = Assert.Throws<ArgumentSyntaxException>(() => CommandLineArguments.ParseRaw(new TestConsole(), [
"track",
channel
]));
var tab = "\t";
Assert.Equal($"""
Channel must be one of:
{tab}- Latest
{tab}- Preview
{tab}- LTS
{tab}- STS
""", ex.Message);
}
[Fact]
public void Install()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"install",
MockServer.DefaultLtsVersion.ToString(),
]);
Assert.True(options!.SubCommand is DnvmSubCommand.InstallArgs {
SdkVersion: var sdkVersion
} && sdkVersion == MockServer.DefaultLtsVersion);
}
[Fact]
public void InstallOptions()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"install",
"-f",
"--sdk-dir", "test",
"-v",
MockServer.DefaultLtsVersion.ToString(),
]);
Assert.True(options!.SubCommand is DnvmSubCommand.InstallArgs {
SdkVersion: var sdkVersion,
Force: true,
SdkDir: {} sdkDir,
Verbose: true
} && sdkVersion == MockServer.DefaultLtsVersion && sdkDir.Name == "test");
}
[Fact]
public void InstallBadVersion()
{
Assert.Throws<ArgumentSyntaxException>(() => CommandLineArguments.ParseRaw(new TestConsole(), [
"install",
"badversion"
]));
}
[Fact]
public void TrackMixedCase()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"track",
"lTs"
]);
Assert.True(options!.SubCommand is DnvmSubCommand.TrackArgs {
Channel: Channel.Lts
});
}
[Fact]
public void EnableDnvmPreviews()
{
var options = CommandLineArguments.ParseRaw(new TestConsole(), [
"--enable-dnvm-previews",
]);
Assert.True(options!.EnableDnvmPreviews);
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void RunHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(console, [ param ]));
Assert.Equal(ExpectedHelpText, console.Output);
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void ListHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "list", param ]));
Assert.Equal("""
usage: dnvm list [-h | --help]
List installed SDKs.
Options:
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output);
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void SelectHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "select", param ]));
Assert.Equal("""
usage: dnvm select [-h | --help] <sdkDirName>
Select the active SDK directory, meaning the directory that will be used when
running `dotnet` commands. This is the same directory passed to the `-s` option
for `dnvm install`.
Note: This command does not change between SDK versions installed in the same
directory. For that, use the built-in dotnet global.json file. Information about
global.json can be found at
https://learn.microsoft.com/en-us/dotnet/core/tools/global-json.
Arguments:
<sdkDirName> The name of the SDK directory to select.
Options:
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void InstallHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "install", param ]));
Assert.Equal("""
usage: dnvm install [-f | --force] [-s | --sdk-dir <sdkDir>] [-v | --verbose]
[-h | --help] <version>
Install an SDK.
Arguments:
<version> The version of the SDK to install.
Options:
-f, --force Force install the given SDK, even if already installed
-s, --sdk-dir <sdkDir> Install the SDK into a separate directory with the
given name.
-v, --verbose Print debugging messages to the console.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void TrackHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "track", param ]));
Assert.Equal("""
usage: dnvm track [--feed-url <feedUrl>] [-v | --verbose] [-f | --force] [-y]
[--prereqs] [-s | --sdk-dir <sdkDir>] [-h | --help] <channel>
Start tracking a new channel.
Arguments:
<channel> Track the channel specified.
Options:
--feed-url <feedUrl> Set the feed URL to download the SDK from.
-v, --verbose Print debugging messages to the console.
-f, --force Force tracking the given channel, even if already tracked.
-y Answer yes to all prompts.
--prereqs Print prereqs for dotnet on Ubuntu.
-s, --sdk-dir <sdkDir> Track the channel in a separate directory with the
given name.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void SelfInstallHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "selfinstall", param ]));
Assert.Equal("""
usage: dnvm selfinstall [-v | --verbose] [-f | --force] [--feed-url <feedUrl>]
[-y] [--update] [--dest-path <destPath>] [-h | --help]
Install dnvm to the local machine.
Options:
-v, --verbose Print debugging messages to the console.
-f, --force Force install the given SDK, even if already installed
--feed-url <feedUrl> Set the feed URL to download the SDK from.
-y Answer yes to all prompts.
--update [internal] Update the current dnvm installation. Only intended to
be called from dnvm.
--dest-path <destPath> Set the destination path for the dnvm executable.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void UpdateHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "update", param ]));
Assert.Equal("""
usage: dnvm update [--dnvm-url <dnvmReleasesUrl>] [--feed-url <feedUrl>] [-v |
--verbose] [--self] [-y] [-h | --help]
Update the installed SDKs or dnvm itself.
Options:
--dnvm-url <dnvmReleasesUrl> Set the URL for the dnvm releases endpoint.
--feed-url <feedUrl> Set the feed URL to download the SDK from.
-v, --verbose Print debugging messages to the console.
--self Update dnvm itself in the current location.
-y Answer yes to all prompts.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void UninstallHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "uninstall", param ]));
Assert.Equal("""
usage: dnvm uninstall [-s | --sdk-dir <sdkDir>] [-h | --help] <sdkVersion>
Uninstall an SDK.
Arguments:
<sdkVersion> The version of the SDK to uninstall.
Options:
-s, --sdk-dir <sdkDir> Uninstall the SDK from the given directory.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void PruneHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "prune", param ]));
Assert.Equal("""
usage: dnvm prune [-v | --verbose] [--dry-run] [-h | --help]
Remove all SDKs with older patch versions.
Options:
-v, --verbose Print extra debugging info to the console.
--dry-run Print the list of the SDKs to be uninstalled, but don't
uninstall.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void UntrackHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "untrack", param ]));
Assert.Equal("""
usage: dnvm untrack [-h | --help] <channel>
Remove a channel from the list of tracked channels.
Arguments:
<channel> The channel to untrack.
Options:
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
[Theory]
[InlineData("-h")]
[InlineData("--help")]
public void RestoreHelp(string param)
{
var console = new TestConsole();
Assert.Null(CommandLineArguments.ParseRaw(
console,
[ "restore", param ]));
Assert.Equal("""
usage: dnvm restore [-l | --local] [-f | --force] [-v | --verbose] [-h | --help]
Downloads the SDK in the global.json in or above the current directory.
Options:
-l, --local Install the sdk into the .dotnet folder in the same directory
as global.json.
-f, --force Force install the SDK, even if already installed.
-v, --verbose Print extra debugging info to the console.
-h, --help Show help information.
""".NormalizeLineEndings(), console.Output.TrimLines());
}
}