Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace GoDotLog with Chickensoft.Log #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Godot.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<LangVersion>10.0</LangVersion>
<Nullable>enable</Nullable>
<RootNamespace>Chickensoft.GoDotTest.Tests</RootNamespace>
<!-- Required for some nuget packages to work -->
Expand Down
10 changes: 10 additions & 0 deletions Chickensoft.GoDotTest.Tests/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Debug Tests": {
"commandName": "Executable",
"executablePath": "%GODOT4%",
"commandLineArgs": "--run-tests --listen-trace --quit-on-finish",
"workingDirectory": "."
}
}
}
57 changes: 41 additions & 16 deletions Chickensoft.GoDotTest.Tests/badges/branch_coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 41 additions & 16 deletions Chickensoft.GoDotTest.Tests/badges/line_coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 33 additions & 6 deletions Chickensoft.GoDotTest.Tests/test/src/GoTestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ namespace Chickensoft.GoDotTest.Tests;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using Chickensoft.Log;
using Godot;
using GoDotLog;
using GoDotTest;
using LightMock;
using LightMock.Generator;
Expand Down Expand Up @@ -40,7 +41,7 @@ public GoTestTest(Node testScene) : base(testScene) { }
public async Task DoesNothingIfNotRunningTests() {
var adapter = new Mock<TestAdapter>();
GoTest.Adapter = adapter.Object;
var testEnv = TestEnvironment.From(Array.Empty<string>());
var testEnv = TestEnvironment.From([]);
var log = new Mock<ILog>();
var assembly = Assembly.GetExecutingAssembly();
await GoTest.RunTests(assembly, TestScene, testEnv, log.Object);
Expand All @@ -49,7 +50,7 @@ public async Task DoesNothingIfNotRunningTests() {
[Test]
public async Task ExitsWithFailingExitCodeWhenTestsFail() {
var testEnv = TestEnvironment.From(
new string[] { "--run-tests=ahem", "--quit-on-finish" }
["--run-tests=ahem", "--quit-on-finish"]
);
var log = new Mock<ILog>();
var provider = new Mock<ITestProvider>();
Expand All @@ -66,10 +67,36 @@ await GoTest.RunTests(
provider.VerifyAll();
}

[Test]
public async Task RemovesTraceListenerWhenTestsFail() {
// will be 1 in VSCode, 2 in VS (it adds its own DefaultTraceListener
// to run these tests)
var traceListenerCount = Trace.Listeners.Count;
var testEnv = TestEnvironment.From(
[
"--run-tests=ahem",
"--listen-trace",
"--quit-on-finish"
]
);
var log = new Mock<ILog>();
var provider = new Mock<ITestProvider>();

SetupTest(testEnv, log, provider);

int? testExitCode = null;
GoTest.OnExit = (node, exitCode) => testExitCode = exitCode;

await GoTest.RunTests(
Assembly.GetExecutingAssembly(), TestScene, testEnv, log.Object
);
Trace.Listeners.Count.ShouldBe(traceListenerCount);
}

[Test]
public async Task ExitsWithFailingExitCodeWhenTestsFailOnCoverage() {
var testEnv = TestEnvironment.From(
new string[] { "--run-tests=ahem", "--coverage", "--quit-on-finish" }
["--run-tests=ahem", "--coverage", "--quit-on-finish"]
);
var log = new Mock<ILog>();
var provider = new Mock<ITestProvider>();
Expand All @@ -88,7 +115,7 @@ await GoTest.RunTests(
[Test]
public async Task TimeoutMillisecondSetterShouldHaveAnImpactWhenCreatingExecutor() {
var testEnv = TestEnvironment.From(
new string[] { "--run-tests=ahem", "--coverage", "--quit-on-finish" }
["--run-tests=ahem", "--coverage", "--quit-on-finish"]
);
var log = new Mock<ILog>();
var provider = new Mock<ITestProvider>();
Expand All @@ -108,7 +135,7 @@ private void SetupTest(TestEnvironment testEnv, Mock<ILog> log, Mock<ITestProvid
provider
.Setup(provider => provider.GetTestSuitesByPattern(
The<Assembly>.IsAnyValue, "ahem"
)).Returns(new List<ITestSuite>());
)).Returns([]);

var reporter = new Mock<ITestReporter>();
reporter.Setup(reporter => reporter.HadError).Returns(true);
Expand Down
2 changes: 1 addition & 1 deletion Chickensoft.GoDotTest.Tests/test/src/TestAdapterTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Chickensoft.GoDotTest.Tests;

using Chickensoft.Log;
using Godot;
using GoDotLog;
using GoDotTest;
using LightMock.Generator;
using Shouldly;
Expand Down
12 changes: 7 additions & 5 deletions Chickensoft.GoDotTest.Tests/test/src/TestEnvironmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ public TestEnvironmentTest(Node testScene) : base(testScene) { }

[Test]
public void ConstructsTestEnvironmentWithPatternFlag() {
var testEnvironment = TestEnvironment.From(new string[] {
var testEnvironment = TestEnvironment.From([
"--run-tests=SomeTest"
});
]);
testEnvironment.TestPatternToRun.ShouldBe("SomeTest");
}

[Test]
public void ConstructsTestEnvironmentWithSimpleFlags() {
var args = new string[] {
"--quit-on-finish",
"--stop-on-error",
"--sequential",
"--coverage",
"--listen-trace",
"--stop-on-error",
"--sequential",
"--coverage",
};
var testEnvironment = TestEnvironment.From(args);
testEnvironment.QuitOnFinish.ShouldBeTrue();
testEnvironment.ListenTrace.ShouldBeTrue();
testEnvironment.StopOnError.ShouldBeTrue();
testEnvironment.Sequential.ShouldBeTrue();
testEnvironment.Coverage.ShouldBeTrue();
Expand Down
Loading