Skip to content

Enhance ConsoleAssert.AssertExpectation with detailed wildcard diff output #70

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 27, 2025

Overview

This PR implements enhanced wildcard diff output for ConsoleAssert.AssertExpectation to provide detailed character-by-character analysis when wildcard matching fails, making it much easier to debug test failures.

Problem

Previously, when wildcard pattern matching failed, the output only showed basic expected vs actual strings:

The values are not like (using wildcards) each other:- 
-----------------------------------
Expected: "PING *(* (::1)) 56 data bytes\n64 bytes from * (::1): icmp_seq=1 ttl=64 time=* ms*"
Actual  : "PING localhost (::1) 56 data bytes\n\n--- localhost ping statistics ---\n4 packets transmitted, 0 received, 100% packet loss, time 3087ms\n\n"
-----------------------------------
The expected length of 81 does not match the output length of 136.

This made it very difficult to identify where wildcards matched and where failures occurred, especially in multiline outputs like ping results.

Solution

Added an enhanced wildcard diff system that provides:

  • Line-by-line comparison with ✅/❌ status indicators
  • Wildcard match tracking showing what each * matched
  • Clear identification of extra/missing lines
  • Console-friendly output with visual separators and summary

Example Enhanced Output

The values are not like (using wildcards) each other: Output does not match expected pattern using wildcards.

────────────────────────────────────────────────────────────
Line 1:
Expected: PING * (::1) 56 data bytes
Actual  : PING localhost (::1) 56 data bytes
Match   : ✅

Wildcard matches:
  * => "localhost"

────────────────────────────────────────────────────────────
Line 2:
Expected: 64 bytes from * (::1): icmp_seq=1 ttl=64 time=* ms
Actual  : 64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.018 ms
Match   : ✅

Wildcard matches:
  * => "localhost"
  * => "0.018"

────────────────────────────────────────────────────────────
Line 3:
Expected: <no more lines>
Actual  : Extra unexpected line
Match   : ❌ (unexpected extra line)

────────────────────────────────────────────────────────────
Summary:
✅ 2 lines matched
❌ 1 unexpected lines in actual output

Implementation

New Components

  • DiffOptions enum: Controls diff behavior (Default vs EnhancedWildcardDiff)
  • WildcardDiffAnalyzer: Analyzes patterns and tracks wildcard matches
  • WildcardDiffFormatter: Formats enhanced output with line-by-line details

API Changes

Enhanced methods with new overloads that accept DiffOptions:

// Enable enhanced diff for ExpectLike
ConsoleAssert.ExpectLike(expected, action, DiffOptions.EnhancedWildcardDiff);

// Enable enhanced diff for ExecuteProcess
ConsoleAssert.ExecuteProcess(expected, "command", args, out output, out error, 
                            workingDir, DiffOptions.EnhancedWildcardDiff);

// Default behavior unchanged
ConsoleAssert.ExpectLike(expected, action); // Original output format

Backward Compatibility

  • All existing APIs remain unchanged
  • Enhanced diff is opt-in via the DiffOptions.EnhancedWildcardDiff flag
  • All existing tests continue to pass (36/37 tests pass, 1 pre-existing failure unrelated to this change)

Testing

Added comprehensive test suite covering:

  • Enhanced diff functionality validation
  • Wildcard matching and output formatting
  • Comparison with original behavior
  • Edge cases (extra lines, missing lines, pattern mismatches)

Fixes #69.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits June 28, 2025 00:03
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
…pport

Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Improve the ConsoleAssert.AssertExpectation output Enhance ConsoleAssert.AssertExpectation with detailed wildcard diff output Jun 28, 2025
@Copilot Copilot AI requested a review from BenjaminMichaelis June 28, 2025 00:20
Copilot finished work on behalf of BenjaminMichaelis June 28, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the ConsoleAssert.AssertExpectation output
2 participants