Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Feb 8, 2024
1 parent dfd65c3 commit 5d29435
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions HarmonyTests/Patching/Assets/Specials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,26 @@ public class OptionalPatch
[HarmonyPostfix, HarmonyOptional, HarmonyPatch(typeof(OptionalPatch), nameof(NotEnumerator), MethodType.Async)]
public static void Test5() => throw new InvalidOperationException();

[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyOptional]
[HarmonyPatch(typeof(OptionalPatch), "missing_method1")]
[HarmonyPatch(typeof(OptionalPatch), nameof(NotEnumerator), MethodType.Normal)]
[HarmonyPatch(typeof(OptionalPatch), nameof(Thrower), MethodType.Normal)]
[HarmonyPatch(typeof(OptionalPatch), "missing_method2")]
public static void Test6() => throw new InvalidOperationException();
public static bool Test6() => false;

private void NotEnumerator() => throw new InvalidOperationException();
public static void Thrower() => throw new InvalidOperationException();
}

public static class OptionalPatchNone
{
[HarmonyPrefix, HarmonyPatch(typeof(OptionalPatch), "missing_method")]
public static void Prefix() => throw new InvalidOperationException();
[HarmonyPrefix]
[HarmonyPatch(typeof(OptionalPatch), "missing_method1")]
[HarmonyPatch(typeof(OptionalPatch), nameof(Thrower), MethodType.Normal)]
[HarmonyPatch(typeof(OptionalPatch), "missing_method2")]
public static bool Test6() => false;

public static void Thrower() => throw new InvalidOperationException();
}

public static class SafeWrapPatch
Expand Down
4 changes: 4 additions & 0 deletions HarmonyTests/Patching/Specials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ public void Test_Optional_Patch()
var instance = new Harmony("special-case-optional-patch");
Assert.NotNull(instance);

Assert.Throws<InvalidOperationException>(OptionalPatch.Thrower);
Assert.DoesNotThrow(() => instance.PatchAll(typeof(OptionalPatch)));
Assert.DoesNotThrow(OptionalPatch.Thrower);

Assert.Throws<InvalidOperationException>(OptionalPatchNone.Thrower);
Assert.Throws<HarmonyException>(() => instance.PatchAll(typeof(OptionalPatchNone)));
Assert.Throws<InvalidOperationException>(OptionalPatchNone.Thrower);
}

[Test]
Expand Down

0 comments on commit 5d29435

Please sign in to comment.