Skip to content

Commit 5912b05

Browse files
committed
#43 - increase coverage
1 parent 99ed062 commit 5912b05

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

.github/workflows/develop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
with:
6464
path: ./tests/HydraScript.IntegrationTests/coverage.cobertura.xml
6565
repo_token: ${{ secrets.GITHUB_TOKEN }}
66-
minimum_coverage: 20
66+
minimum_coverage: 80
6767
fail_below_threshold: true
6868
show_class_names: true
6969
show_missing: true

src/HydraScript/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.CommandLine.Builder;
22
using System.CommandLine.Hosting;
33
using System.CommandLine.Parsing;
4+
using System.Diagnostics.CodeAnalysis;
45
using HydraScript;
56
using HydraScript.Infrastructure;
67
using Microsoft.Extensions.DependencyInjection;
@@ -10,6 +11,7 @@
1011

1112
return GetRunner(ConfigureHost).Invoke(args);
1213

14+
[ExcludeFromCodeCoverage]
1315
internal static partial class Program
1416
{
1517
internal static readonly ExecuteCommand Command = new();

src/HydraScript/SimplestConsoleFormatter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Microsoft.Extensions.Logging;
23
using Microsoft.Extensions.Logging.Abstractions;
34
using Microsoft.Extensions.Logging.Console;
45

56
namespace HydraScript;
67

8+
[ExcludeFromCodeCoverage]
79
internal class SimplestConsoleFormatter() : ConsoleFormatter(nameof(SimplestConsoleFormatter))
810
{
911
public override void Write<TState>(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.CommandLine.Parsing;
2+
using System.IO.Abstractions;
3+
using NSubstitute;
4+
5+
namespace HydraScript.IntegrationTests;
6+
7+
public class DumpOptionTests(TestHostFixture fixture) : IClassFixture<TestHostFixture>
8+
{
9+
[Fact]
10+
public void Invoke_DumpOptionPassed_FilesCreated()
11+
{
12+
var fileSystemMock = Substitute.For<IFileSystem>();
13+
var runner = fixture.GetRunner(
14+
configureTestServices: services =>
15+
services.SetupInMemoryScript(script: string.Empty, fileSystemMock));
16+
runner.Invoke(fixture.InMemoryScriptWithDump);
17+
18+
fileSystemMock.File.Received(1)
19+
.WriteAllText(
20+
TestHostFixture.ScriptFileName + ".tokens",
21+
Arg.Any<string>());
22+
fileSystemMock.File.Received(1)
23+
.WriteAllText(
24+
"ast.dot",
25+
Arg.Any<string>());
26+
fileSystemMock.File.Received(1)
27+
.WriteAllLines(
28+
TestHostFixture.ScriptFileName + ".tac",
29+
Arg.Any<IEnumerable<string>>());
30+
}
31+
}

tests/HydraScript.IntegrationTests/ServiceCollectionTestExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ namespace HydraScript.IntegrationTests;
66

77
internal static class ServiceCollectionTestExtensions
88
{
9-
internal static void SetupInMemoryScript(this IServiceCollection services, string script)
9+
internal static void SetupInMemoryScript(
10+
this IServiceCollection services,
11+
string script,
12+
IFileSystem? fileSystemMock = null)
1013
{
11-
var fileSystem = Substitute.For<IFileSystem>();
14+
var fileSystem = fileSystemMock ?? Substitute.For<IFileSystem>();
1215
var file = Substitute.For<IFile>();
1316
file.ReadAllText(default!).ReturnsForAnyArgs(script);
1417
fileSystem.File.ReturnsForAnyArgs(file);

tests/HydraScript.IntegrationTests/TestHostFixture.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ public class TestHostFixture(
1515
{
1616
private readonly List<string> _logMessages = [];
1717

18-
public readonly string[] InMemoryScript = ["file.js"];
18+
public const string ScriptFileName = "file";
19+
public readonly string[] InMemoryScript = [$"{ScriptFileName}.js"];
20+
public readonly string[] InMemoryScriptWithDump = [$"{ScriptFileName}.js", "-d"];
21+
1922
public IReadOnlyCollection<string> LogMessages => _logMessages;
2023

2124
public ITestOutputHelper? OutputHelper
@@ -41,12 +44,13 @@ public Parser GetRunner(Action<IServiceCollection>? configureTestServices = null
4144
.ConfigureServices((context, services) =>
4245
{
4346
services.Configure<InvocationLifetimeOptions>(options => options.SuppressStatusMessages = true);
44-
var fileInfo = context.GetInvocationContext().ParseResult
45-
.GetValueForArgument(Program.Command.PathArgument);
47+
var parseResult = context.GetInvocationContext().ParseResult;
48+
var fileInfo = parseResult.GetValueForArgument(Program.Command.PathArgument);
49+
var dump = parseResult.GetValueForOption(Program.Command.DumpOption);
4650
services
4751
.AddDomain()
4852
.AddApplication()
49-
.AddInfrastructure(dump: false, fileInfo);
53+
.AddInfrastructure(dump, fileInfo);
5054
configureTestServices?.Invoke(services);
5155
})
5256
.UseCommandHandler<ExecuteCommand, ExecuteCommandHandler>(),

0 commit comments

Comments
 (0)