Skip to content

Commit

Permalink
Added tests for same argument in sub commands. These tests check the …
Browse files Browse the repository at this point in the history
…fix to the issue #518.
  • Loading branch information
ernstc committed Nov 14, 2022
1 parent 99c5417 commit 1c89f04
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/CommandLineUtils.Tests/ArgumentAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -94,5 +95,47 @@ public void KeepsDefaultValues()
Assert.Equal("a", app3.Model.Arg1);
Assert.Equal(new[] { "b", "c" }, app3.Model.Arg2);
}

[Subcommand(typeof(ACommand))]
public class Program
{
}

[Command("a")]
[Subcommand(typeof(BCommand))]
public class ACommand
{
[Argument(0)]
public string? Arg1 { get; set; }
}

[Command("b")]
public class BCommand
{
[Argument(0)]
public string? Arg1 { get; set; }
}

[Fact]
public void SameArgumentInSubcommandsCallingACommand()
{
var app1 = new CommandLineApplication<Program>();
app1.Conventions.UseDefaultConventions();
var result = app1.Parse("a", "any-value");
var command = result.SelectedCommand as CommandLineApplication<ACommand>;
Assert.NotNull(command);
Assert.Equal("any-value", command.Model.Arg1);
}

[Fact]
public void SameArgumentInSubcommandsCallingBCommand()
{
var app1 = new CommandLineApplication<Program>();
app1.Conventions.UseDefaultConventions();
var result = app1.Parse("a", "b", "any-value");
var command = result.SelectedCommand as CommandLineApplication<BCommand>;
Assert.NotNull(command);
Assert.Equal("any-value", command.Model.Arg1);
}
}
}

0 comments on commit 1c89f04

Please sign in to comment.