Skip to content

Commit 987dc15

Browse files
authored
Issue 162 (#164)
1 parent 41ac4a3 commit 987dc15

File tree

7 files changed

+14
-9
lines changed

7 files changed

+14
-9
lines changed

src/HydraScript/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ private static ExecuteCommand GetCommand()
1818
{
1919
var fileInfo = parseResult.GetValue(command.PathArgument)!;
2020
var dump = parseResult.GetValue(command.DumpOption);
21-
var serviceProvider = GetServiceProvider(fileInfo, dump);
21+
using var serviceProvider = GetServiceProvider(fileInfo, dump);
2222
var executor = serviceProvider.GetRequiredService<Executor>();
2323
return executor.Invoke();
2424
});
2525
return command;
2626
}
2727

28-
internal static IServiceProvider GetServiceProvider(
28+
internal static ServiceProvider GetServiceProvider(
2929
FileInfo fileInfo,
3030
bool dump,
3131
Action<IServiceCollection>? configureServices = null)

tests/HydraScript.IntegrationTests/DumpOptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class DumpOptionTests(TestHostFixture fixture) : IClassFixture<TestHostFi
99
[Fact]
1010
public void Invoke_DumpOptionPassed_FilesCreated()
1111
{
12-
var runner = fixture.GetRunner(new TestHostFixture.Options(Dump: true));
12+
using var runner = fixture.GetRunner(new TestHostFixture.Options(Dump: true));
1313
runner.Invoke();
1414

1515
var fileSystemMock = runner.ServiceProvider.GetRequiredService<IFileSystem>();

tests/HydraScript.IntegrationTests/ErrorPrograms/NullAssignmentWhenUndefinedTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class NullAssignmentWhenUndefinedTests(TestHostFixture fixture) : IClassF
77
[Theory, MemberData(nameof(NullAssignmentScripts))]
88
public void NullAssignment_UndefinedDestinationOrReturnType_HydraScriptError(string script)
99
{
10-
var runner = fixture.GetRunner(new TestHostFixture.Options(InMemoryScript: script));
10+
using var runner = fixture.GetRunner(new TestHostFixture.Options(InMemoryScript: script));
1111
var code = runner.Invoke();
1212
code.Should().Be(Executor.ExitCodes.HydraScriptError);
1313
fixture.LogMessages.Should()

tests/HydraScript.IntegrationTests/ErrorPrograms/VariableInitializationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class VariableInitializationTests(TestHostFixture fixture) : IClassFixtur
77
[Theory, MemberData(nameof(VariableInitializationScripts))]
88
public void VariableWithoutTypeDeclared_AccessedBeforeInitialization_HydraScriptError(string script)
99
{
10-
var runner = fixture.GetRunner(new TestHostFixture.Options(InMemoryScript: script));
10+
using var runner = fixture.GetRunner(new TestHostFixture.Options(InMemoryScript: script));
1111
var code = runner.Invoke();
1212
code.Should().Be(Executor.ExitCodes.HydraScriptError);
1313
fixture.LogMessages.Should()

tests/HydraScript.IntegrationTests/ErrorPrograms/VoidAssignmentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function func(b: boolean) {
1616
}
1717
let x = func(true)
1818
""";
19-
var runner = fixture.GetRunner(new TestHostFixture.Options(InMemoryScript: script));
19+
using var runner = fixture.GetRunner(new TestHostFixture.Options(InMemoryScript: script));
2020
var code = runner.Invoke();
2121
code.Should().Be(Executor.ExitCodes.HydraScriptError);
2222
fixture.LogMessages.Should()

tests/HydraScript.IntegrationTests/SuccessfulProgramsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SuccessfulProgramsTests(TestHostFixture fixture) : IClassFixture<Te
88
[ClassData(typeof(SuccessfulPrograms))]
99
public void Invoke_NoError_ReturnCodeIsZero(string relativePathToFile)
1010
{
11-
var runner = fixture.GetRunner(
11+
using var runner = fixture.GetRunner(
1212
new TestHostFixture.Options(
1313
FileName: relativePathToFile,
1414
MockFileSystem: false));

tests/HydraScript.IntegrationTests/TestHostFixture.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,15 @@ public record Options(
1818
bool MockFileSystem = true,
1919
string InMemoryScript = "");
2020

21-
public class Runner(IServiceProvider serviceProvider, Executor executor)
21+
public class Runner(ServiceProvider serviceProvider, Executor executor): IDisposable
2222
{
23-
public IServiceProvider ServiceProvider => serviceProvider;
23+
public ServiceProvider ServiceProvider => serviceProvider;
2424
public int Invoke() => executor.Invoke();
25+
26+
public void Dispose()
27+
{
28+
serviceProvider.Dispose();
29+
}
2530
}
2631

2732
private readonly List<string> _logMessages = [];

0 commit comments

Comments
 (0)