-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathassertions.cake
47 lines (40 loc) · 1.46 KB
/
assertions.cake
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
// ***********************************************************************
// Copyright (c) Charlie Poole and contributors.
// Licensed under the MIT License. See LICENSE.txt in root directory.
// ***********************************************************************
public static class Assert
{
internal static List<string> FailureMessages = new List<string>();
internal static int AssertCount { get; set; }
internal static int FailureCount { get; set; }
internal static int SuccessCount => AssertCount - FailureCount;
public static void That<T>(T actual, Constraint<T> constraint, string message = null)
{
Assert.AssertCount++;
if (!constraint.Matches(actual))
{
if (message != null)
FailureMessages.Add(message);
ReportFailure(constraint.Message);
}
}
public static void That(bool condition, string message)
{
Assert.AssertCount++;
if (!condition)
ReportFailure(message);
}
public static void Fail(string message = null)
{
throw new System.Exception(message);
}
internal static void ReportFailure(string message)
{
// Note that this version does not automatically
// terminate the test upon failure of an Assert.
// Use Assert.Fail if you want the test to end.
if (!string.IsNullOrEmpty(message))
FailureMessages.Add(message);
FailureCount++;
}
}