Skip to content

Commit

Permalink
test: 更新测试ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaitonn committed Nov 22, 2024
1 parent 930eec8 commit a1550e5
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 35 deletions.
27 changes: 12 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ on:
- "**.cs"
workflow_dispatch:

permissions:
id-token: write
contents: write
checks: write

jobs:
test:
runs-on: windows-latest
Expand All @@ -25,18 +20,20 @@ jobs:
dotnet-version: 6.0.x

- name: Run tests
run:
dotnet test src/Serein.Tests --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"

- name: Generate coverage
continue-on-error: true
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
run: |
dotnet test src/Serein.Tests
dotnet tool install --global JetBrains.dotCover.CommandLineTools
dotnet dotcover cover-dotnet --Output=AppCoverageReport.xml --ReportType=DetailedXML -- test --no-build
- name: Upload test results
uses: actions/upload-artifact@v4
- name: Run codacy-coverage-reporter
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: codacy/codacy-coverage-reporter-action@v1.3.0
with:
path: ./src/Serein.Tests/TestResults.trx
api-token: ${{ secrets.CODACY_API_TOKEN }}
coverage-reports: AppCoverageReport.xml

- name: Report test results
uses: dorny/test-reporter@v1
with:
name: Test Result
path: ./src/Serein.Tests/TestResults.trx
reporter: dotnet-trx
7 changes: 4 additions & 3 deletions src/Serein.Cli/Services/Interaction/CommandPromptCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ .. _commandProvider
}

if (args.Length > 0)
{
switch (args[0])
{
case "connection" when args.Length == 2:
Expand All @@ -75,8 +76,8 @@ .. _pluginSubcommnads
);

case "plugin"
when args.Length == 3
&& args[1].Equals("disable", StringComparison.InvariantCultureIgnoreCase):
when args.Length == 3
&& args[1].Equals("disable", StringComparison.InvariantCultureIgnoreCase):
return Task.FromResult<IReadOnlyList<CompletionItem>>(
[
.. GetPluginIdCompletionItem()
Expand Down Expand Up @@ -108,7 +109,7 @@ .. GetServerCompletionItem()
]
);
}

}
return _emptyTask;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Serein.Cli/Services/Interaction/Handlers/PluginHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ NetPluginLoader netPluginLoader
public override void Invoke(IReadOnlyList<string> args)
{
if (args.Count == 1)
{
throw new InvalidArgumentException("缺少参数。可用值:\"reload\"\"list\"\"disable\"");
}

switch (args[1].ToLowerInvariant())
{
Expand Down
2 changes: 2 additions & 0 deletions src/Serein.Cli/Services/Interaction/InputLoopService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private void ProcessInput(string? input)
_serverManager.Servers.TryGetValue(_serverSwitcher.Value.CurrentId, out var server)
&& server.Status
)
{
if (input.StartsWith(_settingProvider.Value.Application.CliCommandHeader))
{
input = input[_settingProvider.Value.Application.CliCommandHeader.Length..];
Expand All @@ -131,6 +132,7 @@ private void ProcessInput(string? input)
server.Input(input);
return;
}
}
}

_inputHandler.Handle(
Expand Down
2 changes: 2 additions & 0 deletions src/Serein.Core/Services/Commands/CommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ public static Command Parse(CommandOrigin origin, string? command, bool throws =
catch
{
if (throws)
{
throw;
}

return new() { Origin = origin, Type = CommandType.Invalid };
}
Expand Down
4 changes: 4 additions & 0 deletions src/Serein.Tests/Serein.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
18 changes: 1 addition & 17 deletions src/Serein.Tests/Services/CommandParser/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,8 @@
namespace Serein.Tests.Services.CommandParser;

[Collection(nameof(Serein))]
public sealed class CommandTests : IDisposable
public static class CommandTests
{
private readonly IHost _app;
private readonly Parser _commandParser;

public CommandTests()
{
_app = HostFactory.BuildNew();
_app.StartAsync();
_commandParser = _app.Services.GetRequiredService<Parser>();
}

public void Dispose()
{
_app.StopAsync();
_app.Dispose();
}

[Theory]
[InlineData("[cmd]114", CommandType.ExecuteShellCommand, "114")]
[InlineData("[CmD]514", CommandType.ExecuteShellCommand, "514")]
Expand Down

0 comments on commit a1550e5

Please sign in to comment.