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

tests: switch to using go-cmp.Equal instead of reflect.DeepEqual #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rorycl
Copy link

@rorycl rorycl commented Jan 4, 2025

Hi @mnako

This is a suggestion to use go-cmp for easier comparison of failing test cases.


go-cmp provides convenient diffing of compound data types, for example (for a contrived case):

=== RUN   TestParseEmailHeadersEnglishPlaintextAsciiOver7bit
    letters_test.go:32: email headers are not equal
          letters.Headers{
        - 	Date:   s"2019-04-01 07:55:00 +0100 BST",
        + 	Date:   s"2091-04-01 07:55:00 +0100 BST",
          	Sender: &{Name: "Alice Sender", Address: "alice.sender@example.com"},
          	From:   {&{Name: "Alice Sender", Address: "alice.sender@example.com"}, &{Name: "Alice Sender", Address: "alice.sender@example.net"}},
          	... // 5 identical fields
          	InReplyTo:  {"Message-Id-0@example.com"},
          	References: {"Message-Id-0@example.com"},
        - 	Subject:    "📧 Test English Pangrams",
        + 	Subject:    "Test English Pangrams",
          	Comments:   "Message Header Comment",
          	Keywords:   {"Keyword 1", "Keyword 2"},
          	... // 10 identical fields
          }
--- FAIL: TestParseEmailHeadersEnglishPlaintextAsciiOver7bit (0.00s)
FAIL
FAIL	github.com/mnako/letters	0.006s
FAIL

go-cmp provides convenient diffing of compound data types, for example
(for a contrived case):

=== RUN   TestParseEmailHeadersEnglishPlaintextAsciiOver7bit
    letters_test.go:32: email headers are not equal
          letters.Headers{
        - 	Date:   s"2019-04-01 07:55:00 +0100 BST",
        + 	Date:   s"2091-04-01 07:55:00 +0100 BST",
          	Sender: &{Name: "Alice Sender", Address: "alice.sender@example.com"},
          	From:   {&{Name: "Alice Sender", Address: "alice.sender@example.com"}, &{Name: "Alice Sender", Address: "alice.sender@example.net"}},
          	... // 5 identical fields
          	InReplyTo:  {"Message-Id-0@example.com"},
          	References: {"Message-Id-0@example.com"},
        - 	Subject:    "📧 Test English Pangrams",
        + 	Subject:    "Test English Pangrams",
          	Comments:   "Message Header Comment",
          	Keywords:   {"Keyword 1", "Keyword 2"},
          	... // 10 identical fields
          }
--- FAIL: TestParseEmailHeadersEnglishPlaintextAsciiOver7bit (0.00s)
FAIL
FAIL	github.com/mnako/letters	0.006s
FAIL
@rorycl rorycl requested a review from mnako as a code owner January 4, 2025 17:47
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.

1 participant