-
Notifications
You must be signed in to change notification settings - Fork 83
/
SkipAsserts.cs
83 lines (72 loc) · 2.08 KB
/
SkipAsserts.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma warning disable CA1052 // Static holder types should be static
#pragma warning disable IDE0058 // Expression value is never used
#pragma warning disable IDE0161 // Convert to file-scoped namespace
#if XUNIT_SKIP
#if XUNIT_NULLABLE
#nullable enable
#endif
using Xunit.Sdk;
#if XUNIT_NULLABLE
using System.Diagnostics.CodeAnalysis;
#endif
namespace Xunit
{
#if XUNIT_VISIBILITY_INTERNAL
internal
#else
public
#endif
partial class Assert
{
/// <summary>
/// Skips the current test. Used when determining whether a test should be skipped
/// happens at runtime rather than at discovery time.
/// </summary>
/// <param name="reason">The message to indicate why the test was skipped</param>
#if XUNIT_NULLABLE
[DoesNotReturn]
#endif
public static void Skip(string reason)
{
GuardArgumentNotNull(nameof(reason), reason);
throw SkipException.ForSkip(reason);
}
/// <summary>
/// Will skip the current test unless <paramref name="condition"/> evaluates to <c>true</c>.
/// </summary>
/// <param name="condition">When <c>true</c>, the test will continue to run; when <c>false</c>,
/// the test will be skipped</param>
/// <param name="reason">The message to indicate why the test was skipped</param>
public static void SkipUnless(
#if XUNIT_NULLABLE
[DoesNotReturnIf(false)] bool condition,
#else
bool condition,
#endif
string reason)
{
GuardArgumentNotNull(nameof(reason), reason);
if (!condition)
throw SkipException.ForSkip(reason);
}
/// <summary>
/// Will skip the current test when <paramref name="condition"/> evaluates to <c>true</c>.
/// </summary>
/// <param name="condition">When <c>true</c>, the test will be skipped; when <c>false</c>,
/// the test will continue to run</param>
/// <param name="reason">The message to indicate why the test was skipped</param>
public static void SkipWhen(
#if XUNIT_NULLABLE
[DoesNotReturnIf(true)] bool condition,
#else
bool condition,
#endif
string reason)
{
GuardArgumentNotNull(nameof(reason), reason);
if (condition)
throw SkipException.ForSkip(reason);
}
}
}
#endif