syncthing/vendor/github.com/d4l3k/messagediff
Jakob Borg 944ddcf768
all: Become a Go module (fixes #5148) (#5384)
* go mod init; rm -rf vendor

* tweak proto files and generation

* go mod vendor

* clean up build.go

* protobuf literals in tests

* downgrade gogo/protobuf
2018-12-18 12:36:38 +01:00
..
.coveralls.yml all: Become a Go module (fixes #5148) (#5384) 2018-12-18 12:36:38 +01:00
.gitignore all: Become a Go module (fixes #5148) (#5384) 2018-12-18 12:36:38 +01:00
.travis.yml all: Become a Go module (fixes #5148) (#5384) 2018-12-18 12:36:38 +01:00
bypass.go Add deps 2016-03-06 20:32:10 +00:00
bypasssafe.go Add deps 2016-03-06 20:32:10 +00:00
CHANGELOG.md all: Become a Go module (fixes #5148) (#5384) 2018-12-18 12:36:38 +01:00
LICENSE Add deps 2016-03-06 20:32:10 +00:00
messagediff.go vendor: Update everything 2017-12-29 11:38:00 +00:00
README.md all: Become a Go module (fixes #5148) (#5384) 2018-12-18 12:36:38 +01:00

messagediff Build Status Coverage Status GoDoc

A library for doing diffs of arbitrary Golang structs.

If the unsafe package is available messagediff will diff unexported fields in addition to exported fields. This is primarily used for testing purposes as it allows for providing informative error messages.

Optionally, fields in structs can be tagged as testdiff:"ignore" to make messagediff skip it when doing the comparison.

Example Usage

In a normal file:

package main

import "gopkg.in/d4l3k/messagediff.v1"

type someStruct struct {
    A, b int
    C []int
}

func main() {
    a := someStruct{1, 2, []int{1}}
    b := someStruct{1, 3, []int{1, 2}}
    diff, equal := messagediff.PrettyDiff(a, b)
    /*
        diff =
        `added: .C[1] = 2
        modified: .b = 3`

        equal = false
    */
}

In a test:

import "gopkg.in/d4l3k/messagediff.v1"

...

type someStruct struct {
    A, b int
    C []int
}

func TestSomething(t *testing.T) {
    want := someStruct{1, 2, []int{1}}
    got := someStruct{1, 3, []int{1, 2}}
    if diff, equal := messagediff.PrettyDiff(want, got); !equal {
        t.Errorf("Something() = %#v\n%s", got, diff)
    }
}

To ignore a field in a struct, just annotate it with testdiff:"ignore" like this:

package main

import "gopkg.in/d4l3k/messagediff.v1"

type someStruct struct {
    A int
    B int `testdiff:"ignore"`
}

func main() {
    a := someStruct{1, 2}
    b := someStruct{1, 3}
    diff, equal := messagediff.PrettyDiff(a, b)
    /*
        equal = true
        diff = ""
    */
}

See the DeepDiff function for using the diff results programmatically.

License

Copyright (c) 2015 Tristan Rice rice@fn.lc

messagediff is licensed under the MIT license. See the LICENSE file for more information.

bypass.go and bypasssafe.go are borrowed from go-spew and have a seperate copyright notice.