Skip to content

Commit

Permalink
Add tests for failure cases as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jun 17, 2024
1 parent 2e92a52 commit 76c655c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/tests/JIT/Intrinsics/TypeIntrinsics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ private static void GetGenericTypeDefinitionTests()
AreEqual(GetGenericTypeDefinition<List<string>>(), typeof(List<>));
AreEqual(GetGenericTypeDefinition<Action<string>>(), typeof(Action<>));
AreEqual(GetGenericTypeDefinition<Func<string, int>>(), typeof(Func<,>));

// Test for failures
GetGenericTypeDefinitionThrows<int>();
GetGenericTypeDefinitionThrows<string>();
GetGenericTypeDefinitionThrows<object>();
}

private static int _varInt = 42;
Expand Down Expand Up @@ -346,6 +351,27 @@ private static void GetGenericTypeDefinitionTests()
[MethodImpl(MethodImplOptions.NoInlining)]
private static Type GetGenericTypeDefinition<T>() => typeof(T).GetGenericTypeDefinition();

[MethodImpl(MethodImplOptions.NoInlining)]
private static void GetGenericTypeDefinitionThrows<T>([CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
{
bool success = false;

try
{
_ = typeof(T).GetGenericTypeDefinition();
}
catch (InvalidOperationException)
{
success = true;
}

if (!success)
{
Console.WriteLine($"{file}:L{line} test failed (expected: 'InvalidOperationException').");
_errors++;
}
}

[MethodImpl(MethodImplOptions.NoInlining)]
static void IsTrue(bool expression, [CallerLineNumber] int line = 0, [CallerFilePath] string file = "")
{
Expand Down

0 comments on commit 76c655c

Please sign in to comment.