Skip to content

Commit 8d91fb0

Browse files
committed
instance builder tests with option group error
1 parent a1952be commit 8d91fb0

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
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 Options_With_Group
4+
{
5+
[Option('v', "version")]
6+
public string Version { get; set; }
7+
8+
[Option("option1", Group = "err-group")]
9+
public string Option1 { get; set; }
10+
11+
[Option("option2", Group = "err-group")]
12+
public string Option2 { get; set; }
13+
}
14+
}

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.Linq;
7-
using Microsoft.FSharp.Core;
7+
88
using CommandLine.Core;
99
using CommandLine.Infrastructure;
10+
using CommandLine.Tests.Fakes;
1011

1112
using CSharpx;
12-
using CommandLine.Tests.Fakes;
13+
1314
using FluentAssertions;
15+
1416
using Xunit;
15-
using System.Reflection;
1617

1718
namespace CommandLine.Tests.Unit.Core
1819
{
@@ -1158,6 +1159,42 @@ public void OptionClass_IsImmutable_HasNoCtor()
11581159
act.Should().Throw<InvalidOperationException>();
11591160
}
11601161

1162+
[Fact]
1163+
public void Options_In_Group_With_No_Values_Generates_MissingGroupOptionError()
1164+
{
1165+
// Fixture setup
1166+
var optionNames = new List<NameInfo>
1167+
{
1168+
new NameInfo("", "option1"),
1169+
new NameInfo("", "option2")
1170+
};
1171+
var expectedResult = new[] { new MissingGroupOptionError("err-group", optionNames) };
1172+
1173+
// Exercize system
1174+
var result = InvokeBuild<Options_With_Group>(
1175+
new[] { "-v 10.42" });
1176+
1177+
// Verify outcome
1178+
((NotParsed<Options_With_Group>)result).Errors.Should().BeEquivalentTo(expectedResult);
1179+
1180+
// Teardown
1181+
}
1182+
1183+
[Theory]
1184+
[InlineData("-v", "10.5", "--option1", "test1", "--option2", "test2")]
1185+
[InlineData("-v", "10.5", "--option1", "test1")]
1186+
[InlineData("-v", "10.5", "--option2", "test2")]
1187+
public void Options_In_Group_With_Values_Does_Not_Generate_MissingGroupOptionError(params string[] args)
1188+
{
1189+
// Exercize system
1190+
var result = InvokeBuild<Options_With_Group>(args);
1191+
1192+
// Verify outcome
1193+
result.Should().BeOfType<Parsed<Options_With_Group>>();
1194+
1195+
// Teardown
1196+
}
1197+
11611198
private class ValueWithNoSetterOptions
11621199
{
11631200
[Value(0, MetaName = "Test", Default = 0)]

0 commit comments

Comments
 (0)