forked from UbiquityDotNET/Ubiquity.NET.Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineTests.cs
More file actions
71 lines (58 loc) · 2.76 KB
/
Copy pathCommandLineTests.cs
File metadata and controls
71 lines (58 loc) · 2.76 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
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.
using System.CommandLine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Ubiquity.NET.CommandLine.UT
{
[TestClass]
public class CommandLineTests
{
[TestMethod]
public void CommandLine_parse_with_version_option_only_succeeds( )
{
var settings = CreateTestSettings();
var result = ArgsParsing.Parse<TestOptions>(["--version"], settings);
Assert.HasCount( 0, result.Errors, "Version alone should not produce errors" );
var versionOption = result.GetVersionOption();
Assert.IsNotNull(versionOption);
Assert.AreEqual( versionOption.Action, result.Action);
}
[TestMethod]
public void CommandLine_with_help_option_only_succeeds( )
{
var settings = CreateTestSettings();
var result = ArgsParsing.Parse<TestOptions>(["--help"], settings);
Assert.HasCount( 0, result.Errors );
}
[TestMethod]
public void CommandLine_with_unknown_option_has_errors( )
{
var settings = CreateTestSettings();
ParseResult result = ArgsParsing.Parse<TestOptions>(["--FooBar"], settings );
Assert.HasCount( 2, result.Errors, "Errors should include missing Required, and invalid param" );
}
[TestMethod]
public void CommandLine_with_known_option_and_version_has_errors( )
{
var settings = CreateTestSettings();
ParseResult result = ArgsParsing.Parse<TestOptions>(["--version", "--option1"], settings );
Assert.HasCount( 1, result.Errors, "Should be one error (--version must be set alone) [Other errors ignored for --version]" );
}
[TestMethod]
[Ignore("https://github.com/dotnet/command-line-api/issues/2664")]
public void CommandLine_with_known_option_requiring_arg_and_version_has_errors( )
{
var settings = CreateTestSettings();
ParseResult result = ArgsParsing.Parse<TestOptions>(["--option1", "--version"], settings );
// until https://github.com/dotnet/command-line-api/issues/2664 is resolved this will fail
Assert.HasCount( 2, result.Errors, "Should be one error (--version must be set alone, missing arg for --option1)" );
}
internal static CmdLineSettings CreateTestSettings( DefaultOption defaultOptions = DefaultOption.Help | DefaultOption.Version )
{
return new CmdLineSettings()
{
DefaultOptions = defaultOptions,
};
}
}
}