mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:02:55 +08:00
Add test coverage for ignoring null mods returned by rulesets
This commit is contained in:
parent
c9cb4250bb
commit
0418d70056
49
osu.Game.Tests/Rulesets/TestSceneBrokenRulesetHandling.cs
Normal file
49
osu.Game.Tests/Rulesets/TestSceneBrokenRulesetHandling.cs
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Tests.Visual;
|
||||
|
||||
namespace osu.Game.Tests.Rulesets
|
||||
{
|
||||
[HeadlessTest]
|
||||
public class TestSceneBrokenRulesetHandling : OsuTestScene
|
||||
{
|
||||
[Resolved]
|
||||
private OsuGameBase gameBase { get; set; } = null!;
|
||||
|
||||
[Test]
|
||||
public void TestNullModsReturnedByRulesetAreIgnored()
|
||||
{
|
||||
AddStep("set ruleset with null mods", () => Ruleset.Value = new TestRulesetWithNullMods().RulesetInfo);
|
||||
AddAssert("no null mods in available mods", () => gameBase.AvailableMods.Value.SelectMany(kvp => kvp.Value).All(mod => mod != null));
|
||||
}
|
||||
|
||||
#nullable disable // purposefully disabling nullability to simulate broken or unannotated API user code.
|
||||
|
||||
private class TestRulesetWithNullMods : Ruleset
|
||||
{
|
||||
public override string ShortName => "nullmods";
|
||||
public override string Description => "nullmods";
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type) => new Mod[] { null };
|
||||
|
||||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => null;
|
||||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => null;
|
||||
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => null;
|
||||
}
|
||||
|
||||
#nullable enable
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user