Skip to content

Commit

Permalink
Test for inherited option ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
rstarkov committed Sep 28, 2024
1 parent db9c292 commit 5d8a023
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Tests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,17 @@ public static void TestMore()
== ClassifyJson.Serialize(CommandLineParser.Parse<Test2Cmd>(["del", "this"])));
}

[Fact]
public static void TestSubcommandIntermediate()
{
var c3 = CommandLineParser.Parse<Test3Cmd>(["sub", "base", "subbase", "item"]);
Assert.IsType<Test3SubCmd>(c3.Cmd);
var cs3 = (Test3SubCmd) c3.Cmd;
Assert.Equal("base", cs3.Base);
Assert.Equal("subbase", cs3.SubBase);
Assert.Equal("item", cs3.ItemName);
}

[Fact]
public static void TestPostBuild()
{
Expand All @@ -136,6 +147,7 @@ public static void TestPostBuild()
CommandLineParser.PostBuildStep<CommandLineWithArray>(reporter);
CommandLineParser.PostBuildStep<Test1Cmd>(reporter);
CommandLineParser.PostBuildStep<Test2Cmd>(reporter);
CommandLineParser.PostBuildStep<Test3Cmd>(reporter);
}

class Reporter : IPostBuildReporter
Expand Down
27 changes: 27 additions & 0 deletions Tests/Test3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace RT.CommandLine.Tests;

class Test3Cmd
{
[IsPositional, IsMandatory]
public Test3CmdBase Cmd;

Check warning on line 6 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3Cmd.Cmd' is never assigned to, and will always have its default value null

Check warning on line 6 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3Cmd.Cmd' is never assigned to, and will always have its default value null
}

[CommandGroup]
abstract class Test3CmdBase
{
[IsPositional, IsMandatory]
public string Base;

Check warning on line 13 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3CmdBase.Base' is never assigned to, and will always have its default value null

Check warning on line 13 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3CmdBase.Base' is never assigned to, and will always have its default value null
}

abstract class Test3CmdSubBase : Test3CmdBase
{
[IsPositional, IsMandatory]
public string SubBase;

Check warning on line 19 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3CmdSubBase.SubBase' is never assigned to, and will always have its default value null

Check warning on line 19 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3CmdSubBase.SubBase' is never assigned to, and will always have its default value null
}

[CommandName("sub")]
sealed class Test3SubCmd : Test3CmdSubBase
{
[IsPositional, IsMandatory]
public string ItemName;

Check warning on line 26 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3SubCmd.ItemName' is never assigned to, and will always have its default value null

Check warning on line 26 in Tests/Test3.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test3SubCmd.ItemName' is never assigned to, and will always have its default value null
}

0 comments on commit 5d8a023

Please sign in to comment.