Skip to content

Commit 108ecfb

Browse files
committed
Option group - empty name tests + ignore required tests
1 parent dd51d95 commit 108ecfb

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace CommandLine.Tests.Fakes
2+
{
3+
public class Simple_Options_With_OptionGroup_WithDefaultValue
4+
{
5+
[Option(HelpText = "Define a string value here.", Required = true, Group = "")]
6+
public string StringValue { get; set; }
7+
8+
[Option('s', "shortandlong", HelpText = "Example with both short and long name.", Required = true, Group = "")]
9+
public string ShortAndLong { get; set; }
10+
11+
[Option('x', HelpText = "Define a boolean or switch value here.")]
12+
public bool BoolValue { get; set; }
13+
}
14+
}

tests/CommandLine.Tests/Fakes/Simple_Options_With_Required_OptionGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public class Simple_Options_With_Required_OptionGroup
55
[Option(HelpText = "Define a string value here.", Required = true, Group = "string-group")]
66
public string StringValue { get; set; }
77

8-
[Option('s', "shortandlong", HelpText = "Example with both short and long name.", Group = "string-group")]
8+
[Option('s', "shortandlong", HelpText = "Example with both short and long name.", Required = true, Group = "string-group")]
99
public string ShortAndLong { get; set; }
1010

1111
[Option('x', HelpText = "Define a boolean or switch value here.")]

tests/CommandLine.Tests/Unit/Core/InstanceBuilderTests.cs

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
1+
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
22

3-
using System;
4-
using System.Collections.Generic;
5-
using System.Globalization;
6-
using System.Linq;
73
using Microsoft.FSharp.Core;
84
using CommandLine.Core;
95
using CommandLine.Infrastructure;
6+
using CommandLine.Tests.Fakes;
107

118
using CSharpx;
12-
using CommandLine.Tests.Fakes;
9+
1310
using FluentAssertions;
11+
12+
using System;
13+
using System.Collections.Generic;
14+
using System.Globalization;
15+
using System.Linq;
16+
1417
using Xunit;
1518
using System.Reflection;
1619

@@ -1194,6 +1197,47 @@ public void Options_In_Group_With_Values_Does_Not_Generate_MissingGroupOptionErr
11941197
// Teardown
11951198
}
11961199

1200+
[Fact]
1201+
public void Options_In_Group_WithRequired_Does_Not_Generate_RequiredError()
1202+
{
1203+
// Fixture setup
1204+
var optionNames = new List<NameInfo>
1205+
{
1206+
new NameInfo("", "stingvalue"),
1207+
new NameInfo("s", "shortandlong")
1208+
};
1209+
var expectedResult = new[] { new MissingGroupOptionError("string-group", optionNames) };
1210+
1211+
// Exercize system
1212+
var result = InvokeBuild<Simple_Options_With_Required_OptionGroup>(new string[] { "-x" });
1213+
1214+
// Verify outcome
1215+
result.Should().BeOfType<NotParsed<Simple_Options_With_Required_OptionGroup>>();
1216+
var errors = ((NotParsed<Simple_Options_With_Required_OptionGroup>)result).Errors;
1217+
1218+
errors.Should().HaveCount(1);
1219+
errors.Should().BeEquivalentTo(expectedResult);
1220+
}
1221+
1222+
[Fact]
1223+
public void Options_In_Group_Ignore_Option_Group_If_Option_Group_Name_Empty()
1224+
{
1225+
var expectedResult = new[]
1226+
{
1227+
new MissingRequiredOptionError(new NameInfo("", "stringvalue")),
1228+
new MissingRequiredOptionError(new NameInfo("s", "shortandlong"))
1229+
};
1230+
1231+
// Exercize system
1232+
var result = InvokeBuild<Simple_Options_With_OptionGroup_WithDefaultValue>(new string[] { "-x" });
1233+
1234+
// Verify outcome
1235+
result.Should().BeOfType<NotParsed<Simple_Options_With_OptionGroup_WithDefaultValue>>();
1236+
var errors = ((NotParsed<Simple_Options_With_OptionGroup_WithDefaultValue>)result).Errors;
1237+
1238+
errors.Should().BeEquivalentTo(expectedResult);
1239+
}
1240+
11971241
private class ValueWithNoSetterOptions
11981242
{
11991243
[Value(0, MetaName = "Test", Default = 0)]

0 commit comments

Comments
 (0)