forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
299 additions
and
2,292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
@@ -27,23 +28,50 @@ public static async Task PrepareGameHost(TestContext context) | |
return; | ||
|
||
var hostContext = new TestSceneContext(testScene); | ||
|
||
host_contexts[context] = hostContext; | ||
await hostContext.Start().ConfigureAwait(false); | ||
|
||
testScene.RunSetUpSteps(); | ||
await hostContext.CheckForErrors().ConfigureAwait(false); | ||
} | ||
|
||
[AfterEvery(Test)] | ||
public static async Task ShutdownGameHost(TestContext context) | ||
{ | ||
if (context.TestDetails.ClassInstance is not TestScene) | ||
if (context.TestDetails.ClassInstance is not TestScene testScene) | ||
return; | ||
|
||
var hostContext = host_contexts[context]; | ||
host_contexts.Remove(context, out _); | ||
|
||
await hostContext.CheckForErrors().ConfigureAwait(false); | ||
await hostContext.Stop().ConfigureAwait(false); | ||
} | ||
try | ||
{ | ||
testScene.RunTearDownSteps(); | ||
await hostContext.CheckForErrors().ConfigureAwait(false); | ||
|
||
hostContext.Runner.RunTestBlocking(testScene); | ||
await hostContext.CheckForErrors().ConfigureAwait(false); | ||
|
||
public static TestSceneContext? GetCurrentContext() => host_contexts.GetValueOrDefault(TestContext.Current!); | ||
if (FrameworkEnvironment.ForceTestGC) | ||
{ | ||
// Force any unobserved exceptions to fire against the current test run. | ||
// Without this they could be delayed until a future test scene is running, making tracking down the cause difficult. | ||
GC.Collect(); | ||
GC.WaitForPendingFinalizers(); | ||
} | ||
|
||
testScene.RunAfterTest(); | ||
await hostContext.CheckForErrors().ConfigureAwait(false); | ||
} | ||
catch (AssertionException exc) | ||
{ | ||
throw new TUnit.Assertions.Exceptions.AssertionException(null, exc); | ||
} | ||
finally | ||
{ | ||
await hostContext.Stop().ConfigureAwait(false); | ||
host_contexts.Remove(context, out _); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.