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

Add DoesNotReturnIf to Assert.IsTrue/Assert.IsFalse and DoesNotReturn to Assert.Fail #1005

Merged
merged 1 commit into from
Nov 2, 2021
Merged
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
28 changes: 16 additions & 12 deletions src/TestFramework/MSTest.Core/Assertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static Assert That
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue(bool condition)
public static void IsTrue([DoesNotReturnIf(false)] bool condition)
{
IsTrue(condition, string.Empty, null);
}
Expand All @@ -75,7 +75,7 @@ public static void IsTrue(bool condition)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue(bool? condition)
public static void IsTrue([DoesNotReturnIf(false)] bool? condition)
{
IsTrue(condition, string.Empty, null);
}
Expand All @@ -94,7 +94,7 @@ public static void IsTrue(bool? condition)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue(bool condition, string message)
public static void IsTrue([DoesNotReturnIf(false)] bool condition, string message)
{
IsTrue(condition, message, null);
}
Expand All @@ -113,7 +113,7 @@ public static void IsTrue(bool condition, string message)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue(bool? condition, string message)
public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string message)
{
IsTrue(condition, message, null);
}
Expand All @@ -135,7 +135,7 @@ public static void IsTrue(bool? condition, string message)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue(bool condition, string message, params object[] parameters)
public static void IsTrue([DoesNotReturnIf(false)] bool condition, string message, params object[] parameters)
{
if (!condition)
{
Expand All @@ -160,7 +160,7 @@ public static void IsTrue(bool condition, string message, params object[] parame
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is false.
/// </exception>
public static void IsTrue(bool? condition, string message, params object[] parameters)
public static void IsTrue([DoesNotReturnIf(false)] bool? condition, string message, params object[] parameters)
{
if (condition == false || condition == null)
{
Expand All @@ -178,7 +178,7 @@ public static void IsTrue(bool? condition, string message, params object[] param
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse(bool condition)
public static void IsFalse([DoesNotReturnIf(true)] bool condition)
{
IsFalse(condition, string.Empty, null);
}
Expand All @@ -193,7 +193,7 @@ public static void IsFalse(bool condition)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse(bool? condition)
public static void IsFalse([DoesNotReturnIf(true)] bool? condition)
{
IsFalse(condition, string.Empty, null);
}
Expand All @@ -212,7 +212,7 @@ public static void IsFalse(bool? condition)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse(bool condition, string message)
public static void IsFalse([DoesNotReturnIf(true)] bool condition, string message)
{
IsFalse(condition, message, null);
}
Expand All @@ -231,7 +231,7 @@ public static void IsFalse(bool condition, string message)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse(bool? condition, string message)
public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string message)
{
IsFalse(condition, message, null);
}
Expand All @@ -253,7 +253,7 @@ public static void IsFalse(bool? condition, string message)
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse(bool condition, string message, params object[] parameters)
public static void IsFalse([DoesNotReturnIf(true)] bool condition, string message, params object[] parameters)
{
if (condition)
{
Expand All @@ -278,7 +278,7 @@ public static void IsFalse(bool condition, string message, params object[] param
/// <exception cref="AssertFailedException">
/// Thrown if <paramref name="condition"/> is true.
/// </exception>
public static void IsFalse(bool? condition, string message, params object[] parameters)
public static void IsFalse([DoesNotReturnIf(true)] bool? condition, string message, params object[] parameters)
{
if (condition == true || condition == null)
{
Expand Down Expand Up @@ -1905,6 +1905,7 @@ public static void IsNotInstanceOfType(object value, Type wrongType, string mess
/// <exception cref="AssertFailedException">
/// Always thrown.
/// </exception>
[DoesNotReturn]
public static void Fail()
{
Fail(string.Empty, null);
Expand All @@ -1920,6 +1921,7 @@ public static void Fail()
/// <exception cref="AssertFailedException">
/// Always thrown.
/// </exception>
[DoesNotReturn]
public static void Fail(string message)
{
Fail(message, null);
Expand All @@ -1938,6 +1940,7 @@ public static void Fail(string message)
/// <exception cref="AssertFailedException">
/// Always thrown.
/// </exception>
[DoesNotReturn]
public static void Fail(string message, params object[] parameters)
{
HandleFail("Assert.Fail", message, parameters);
Expand Down Expand Up @@ -2374,6 +2377,7 @@ public static string ReplaceNullChars(string input)
/// <param name="parameters">
/// The parameters.
/// </param>
[DoesNotReturn]
internal static void HandleFail(string assertionName, string message, params object[] parameters)
{
string finalMessage = string.Empty;
Expand Down