-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnhancedErrorMessageTests.cs
More file actions
110 lines (92 loc) · 3.42 KB
/
EnhancedErrorMessageTests.cs
File metadata and controls
110 lines (92 loc) · 3.42 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
namespace IntelliTect.TestTools.Console.Tests;
[TestClass]
public class EnhancedErrorMessageTests
{
[TestMethod]
public void ExpectLike_WildcardMismatch_ShowsDetailedDiff()
{
// Arrange - pattern with wildcards that will NOT match
string expected = "PING *(::1) 56 data bytes\n64 bytes from *";
// Act & Assert - ConsoleAssert throws System.Exception on mismatch
Exception exception = Assert.ThrowsExactly<Exception>(() =>
{
ConsoleAssert.ExpectLike(expected, () =>
{
System.Console.Write("PING localhost(::1) WRONG data bytes\n64 bytes from localhost");
});
});
// Assert - Check that the error message contains the enhanced output
string errorMessage = exception.Message;
// Should contain the line-by-line comparison header
StringAssert.Contains(errorMessage, "Line-by-line comparison");
// Should contain status indicators
StringAssert.Contains(errorMessage, "❌"); // Lines don't match
}
[TestMethod]
public void ExpectLike_ExtraLines_IdentifiedAsSuch()
{
// Arrange - pattern expecting one line, but getting two
string expected = "Line 1";
// Act & Assert
Exception exception = Assert.ThrowsExactly<Exception>(() =>
{
ConsoleAssert.ExpectLike(expected, () =>
{
System.Console.WriteLine("Line 1");
System.Console.WriteLine("Line 2");
});
});
// Assert
string errorMessage = exception.Message;
// With line-by-line comparison, we should see the extra line marked
StringAssert.Contains(errorMessage, "Line 2: ❌");
StringAssert.Contains(errorMessage, "Unexpected extra line");
}
[TestMethod]
public void ExpectLike_MissingLines_IdentifiedAsSuch()
{
// Arrange - pattern with wildcards expecting more lines
string expected = "Line 1\nLine *";
// Act & Assert
Exception exception = Assert.ThrowsExactly<Exception>(() =>
{
ConsoleAssert.ExpectLike(expected, () =>
{
System.Console.WriteLine("Line 1");
});
});
// Assert
string errorMessage = exception.Message;
StringAssert.Contains(errorMessage, "Missing line");
}
[TestMethod]
public void ExecuteProcess_WildcardMismatch_ShowsDetailedDiff()
{
// This test demonstrates the improved error output for ExecuteProcess
// when wildcard matching fails.
string expected = "This * should match";
Exception exception = null;
try
{
ConsoleAssert.ExecuteProcess(
expected,
"echo",
"Output that does not match",
out string _,
out _);
}
catch (Exception ex)
{
exception = ex;
}
// Assert
Assert.IsNotNull(exception);
string errorMessage = exception.Message;
// Should contain wildcard matching error message
StringAssert.Contains(errorMessage, "wildcard");
// Should contain the line-by-line comparison
StringAssert.Contains(errorMessage, "Line-by-line comparison");
}
}