Skip to content

Commit

Permalink
* Remove Lingo entirely
Browse files Browse the repository at this point in the history
* Upgrade RT libraries
* Move Test1Cmd class to separate file
* Add a test for subcommands that uses JSON comparison to test the whole result
  • Loading branch information
Timwi committed Sep 25, 2024
1 parent e961fff commit 9fd7bba
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 2,244 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ jobs:
- name: "dotnet pack: ${{ env.VER_STR }}"
run: dotnet pack Src/RT.CommandLine.csproj --configuration Release -p:InformationalVersion="${{env.VER_STR}}" -p:VersionPrefix=${{env.VER_NUM}} -p:VersionSuffix=${{env.VER_SUF}} -p:FileVersion=${{env.VER_NUM}} -p:AssemblyVersion=${{env.VER_NUM}} -o Publish

- name: "dotnet pack Lingo: ${{ env.VER_STR }}"
run: dotnet pack SrcLingo/RT.CommandLine.Lingo.csproj --configuration Release -p:InformationalVersion="${{env.VER_STR}}" -p:VersionPrefix=${{env.VER_NUM}} -p:VersionSuffix=${{env.VER_SUF}} -p:FileVersion=${{env.VER_NUM}} -p:AssemblyVersion=${{env.VER_NUM}} -o Publish

- name: Push to NuGet
run: dotnet nuget push Publish/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json

Expand Down
6 changes: 0 additions & 6 deletions RT.CommandLine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RT.CommandLine", "Src\RT.CommandLine.csproj", "{DED68431-337E-439C-94E4-ACE2E5363178}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RT.CommandLine.Lingo", "SrcLingo\RT.CommandLine.Lingo.csproj", "{DC6401A1-14F1-44E3-A121-43CC2F192809}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RT.CommandLine.Tests", "Tests\RT.CommandLine.Tests.csproj", "{294D2B02-3FA6-4B9A-82BF-F80396943892}"
EndProject
Global
Expand All @@ -18,10 +16,6 @@ Global
{DED68431-337E-439C-94E4-ACE2E5363178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DED68431-337E-439C-94E4-ACE2E5363178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DED68431-337E-439C-94E4-ACE2E5363178}.Release|Any CPU.Build.0 = Release|Any CPU
{DC6401A1-14F1-44E3-A121-43CC2F192809}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC6401A1-14F1-44E3-A121-43CC2F192809}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DC6401A1-14F1-44E3-A121-43CC2F192809}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DC6401A1-14F1-44E3-A121-43CC2F192809}.Release|Any CPU.Build.0 = Release|Any CPU
{294D2B02-3FA6-4B9A-82BF-F80396943892}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{294D2B02-3FA6-4B9A-82BF-F80396943892}.Debug|Any CPU.Build.0 = Debug|Any CPU
{294D2B02-3FA6-4B9A-82BF-F80396943892}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion Src/CommandLine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;
using System.Reflection;
using RT.Internal;
using RT.PostBuild;
using RT.Util;
Expand Down
4 changes: 2 additions & 2 deletions Src/RT.CommandLine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="RT.PostBuild" Version="2.0.1770" />
<PackageReference Include="RT.Util.Core" Version="2.0.1770" />
<PackageReference Include="RT.PostBuild" Version="2.0.1774" />
<PackageReference Include="RT.Util.Core" Version="2.0.1774" />
</ItemGroup>

<ItemGroup>
Expand Down
2,127 changes: 0 additions & 2,127 deletions SrcLingo/CommandLine.cs

This file was deleted.

24 changes: 0 additions & 24 deletions SrcLingo/RT.CommandLine.Lingo.csproj

This file was deleted.

32 changes: 0 additions & 32 deletions Tests/CommandLineLingoTests.cs

This file was deleted.

60 changes: 15 additions & 45 deletions Tests/CommandLineTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using RT.Util.Consoles;
using RT.Json;
using RT.Serialization;
using RT.Util.Consoles;
using Xunit;

namespace RT.CommandLine.Tests;
Expand Down Expand Up @@ -92,50 +94,6 @@ public static void TestInvalidOption()
}
}


class Test1Cmd : ICommandLineValidatable
{
[IsPositional, IsMandatory]
public string Base;

[IsPositional, IsMandatory]
public Test1SubcommandBase Subcommand;

public static int ValidateCalled = 0;

public ConsoleColoredString Validate()
{
ValidateCalled++;
return null;
}
}

[CommandGroup]
abstract class Test1SubcommandBase : ICommandLineValidatable
{
public static int ValidateCalled = 0;
public abstract ConsoleColoredString Validate();
}

[CommandName("sub1")]
sealed class Test1Subcommand1 : Test1SubcommandBase
{
[IsPositional, IsMandatory]
public string ItemName;

public override ConsoleColoredString Validate()
{
ValidateCalled++;
return null;
}
}

[CommandName("sub2")]
sealed class Test1Subcommand2 : Test1SubcommandBase
{
public override ConsoleColoredString Validate() { return null; }
}

[Fact]
public static void TestSubcommandValidation()
{
Expand All @@ -157,4 +115,16 @@ public static void TestSubcommandValidation()
Assert.Equal(1, Test1Cmd.ValidateCalled);
Assert.Equal(0, Test1SubcommandBase.ValidateCalled);
}

[Fact]
public static void TestMore()
{
Assert.True(
JsonValue.Parse(@"{""Boolean"":true,""Subcommand"":{""SharedString"":null,""Name"":""this"","":type"":""Test2SubcommandAdd""}}")
== ClassifyJson.Serialize(CommandLineParser.Parse<Test2Cmd>(["-b", "add", "this"])));

Assert.True(
JsonValue.Parse(@"{""Boolean"":false,""Subcommand"":{""SharedString"":null,""Id"":""this"","":type"":""Test2SubcommandDelete""}}")
== ClassifyJson.Serialize(CommandLineParser.Parse<Test2Cmd>(["del", "this"])));
}
}
7 changes: 4 additions & 3 deletions Tests/RT.CommandLine.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="RT.Serialization" Version="2.0.1774" />
<PackageReference Include="RT.Serialization.Json" Version="2.0.1774" />
<PackageReference Include="xunit" Version="2.9.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -22,7 +24,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SrcLingo\RT.CommandLine.Lingo.csproj" />
<ProjectReference Include="..\Src\RT.CommandLine.csproj" />
</ItemGroup>

Expand Down
46 changes: 46 additions & 0 deletions Tests/Test1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using RT.Util.Consoles;

namespace RT.CommandLine.Tests;

class Test1Cmd : ICommandLineValidatable
{
[IsPositional, IsMandatory]
public string Base;

Check warning on line 8 in Tests/Test1.cs

View workflow job for this annotation

GitHub Actions / build

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

[IsPositional, IsMandatory]
public Test1SubcommandBase Subcommand;

Check warning on line 11 in Tests/Test1.cs

View workflow job for this annotation

GitHub Actions / build

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

Check warning on line 11 in Tests/Test1.cs

View workflow job for this annotation

GitHub Actions / build

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

public static int ValidateCalled = 0;

public ConsoleColoredString Validate()
{
ValidateCalled++;
return null;
}
}

[CommandGroup]
abstract class Test1SubcommandBase : ICommandLineValidatable
{
public static int ValidateCalled = 0;
public abstract ConsoleColoredString Validate();
}

[CommandName("sub1")]
sealed class Test1Subcommand1 : Test1SubcommandBase
{
[IsPositional, IsMandatory]
public string ItemName;

Check warning on line 33 in Tests/Test1.cs

View workflow job for this annotation

GitHub Actions / build

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

public override ConsoleColoredString Validate()
{
ValidateCalled++;
return null;
}
}

[CommandName("sub2")]
sealed class Test1Subcommand2 : Test1SubcommandBase
{
public override ConsoleColoredString Validate() { return null; }
}
30 changes: 30 additions & 0 deletions Tests/Test2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace RT.CommandLine.Tests;

class Test2Cmd
{
[Option("-b")]
public bool Boolean;

Check warning on line 6 in Tests/Test2.cs

View workflow job for this annotation

GitHub Actions / build

Field 'Test2Cmd.Boolean' is never assigned to, and will always have its default value false

public Test2Subcommand Subcommand;

Check warning on line 8 in Tests/Test2.cs

View workflow job for this annotation

GitHub Actions / build

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

Check warning on line 8 in Tests/Test2.cs

View workflow job for this annotation

GitHub Actions / build

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

[CommandGroup]
abstract class Test2Subcommand
{
[Option("-k")]
public string SharedString;

Check warning on line 15 in Tests/Test2.cs

View workflow job for this annotation

GitHub Actions / build

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

[CommandName("add")]
class Test2SubcommandAdd : Test2Subcommand
{
[IsPositional, IsMandatory]
public string Name;

Check warning on line 22 in Tests/Test2.cs

View workflow job for this annotation

GitHub Actions / build

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

[CommandName("del")]
class Test2SubcommandDelete : Test2Subcommand
{
[IsPositional, IsMandatory]
public string Id;

Check warning on line 29 in Tests/Test2.cs

View workflow job for this annotation

GitHub Actions / build

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

0 comments on commit 9fd7bba

Please sign in to comment.