aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2023-08-31Add cmpopts.EquateComparable (#340)upstream-masterJoe Tsai
This helper function makes it easier to specify that comparable types are safe to directly compare with the == operator in Go. The API does not use generics as it follows existing options like cmp.AllowUnexported, cmpopts.IgnoreUnexported, or cmpopts.IgnoreTypes. While generics provides type safety, the user experience is not as nice. Our current API allows multiple types to be specified: cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{}) While generics would not allow variadic arguments: cmpopts.EquateComparable[netip.Addr]() cmpopts.EquateComparable[netip.Prefix]() Bump mininimum supported Go to 1.18 for net/netip type. Start testing on Go 1.21. Fixes #339
2023-08-30Use of hotlinking of Go identifiers (#337)Joe Tsai
GoDoc now supports hot linking to specific Go identifiers. Use that feature to enhance the usability of cmp docs. Since cmp lacks a direct dependency on cmpopts, you are forced to use the fully-qualified import path to references identifiers in the cmpopts package. It can future improvements to the go/doc to handle this case, either by rendering the doc with short form, or by detecting the use of cmpopts from the unit tests as well (since those can break circular dependencies).
2023-06-05set workflow permission to read-only (#327)Russ Cox
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2023-06-05Pin GitHub action versions (#332)Damien Neil
2023-02-22Run tests for Go 1.20 version (#322)Bəxtiyar
2023-02-22Remove purego fallbacks (#325)Caleb Spare
Having go-cmp panic when using the purego build tag makes it hard to use go-cmp for testing packages that themselves have purego fallbacks. Since go-cmp can't implement its functionality without unsafe (the "fallback" panics) and since environments that prohibit unsafe are much less common these days anyway, simply remove purego code entirely. Fixes #283.
2022-09-02Adjust heuristic for line-based versus byte-based diffing (#299)Joe Tsai
If the string has many characters that require escape sequences to print, then we need to take that into consideration and avoid byte-by-byte diffing. Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2022-08-30Run tests on Go 1.19 (#309)Aoang
* Run tests on Go 1.19 * Format comment Finish the rest of the work for https://github.com/google/go-cmp/pull/304 Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2022-08-30Use value.TypeString in PathStep.String (#306)Joe Tsai
The value.TypeString function is what the rest of the package uses and is slightly cleaner than using reflect.Type.String. Updates #305 Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2022-08-30Pre-declare global type variables (#302)Joe Tsai
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2022-08-30Fix typo in Result documentation (#300)Joe Tsai
2022-07-13Format with Go 1.19 formatter (#304)Joe Tsai
This allows the GoDoc to take advantage of new markup syntax introduced in Go 1.19. This does not require that our minimum supported version be bumped to Go 1.19 since the pkgsite renders our godoc regardless of supported Go version.
2022-06-06Use reflect.Value.IsZero (#297)Joe Tsai
Now that Go 1.13 is the minimum version, we can use the reflect.Value.IsZero method instead of our own internal/value.IsZero function. Interestingly, our IsZero function pre-dates the IsZero method, but fortunately has the exact same semantics, since both are targetting semantics defined by the Go language specification.
2022-04-26Additional cleanup with Go 1.13 as minimal version (#295)Joe Tsai
2022-04-26remove xerrors (#292)Tatsuya Kaneko
Versions older than Go 1.13 are no longer in use. Remove unnecessary dependencies.
2022-04-25Use string formatting for slice of bytes (#294)Joe Tsai
If a slice of bytes is mostly text, format them as text instead of as []byte literal with hexadecimal digits. Avoid always printing the type. This is technically invalid Go code, but is unnecessary in many cases since the type is inferred from the parent concrete type. Fixes #272
2022-04-25Fix printing of types in reporter output (#293)Joe Tsai
When printing a pointer, only elide the type for unnamed pointers. Otherwise, we can run into situations where named and unnamed pointers format the same way in indistinguishable ways. When printing an interview, never skip the interface type. Whether we skip printing the type should be determined by the parent containers, and not locally determined. For examples, interface values within a struct, slice, or map will always be elided since they can be inferred.
2022-03-22Run tests on Go 1.18 (#290)Aoang
2022-01-04Add //go:build lines (#285)Tobias Klauser
Starting with Go 1.17, //go:build lines are preferred over // +build lines, see https://golang.org/doc/go1.17#build-lines and https://golang.org/design/draft-gobuild for details. This change was generated by running Go 1.17 go fmt ./... which automatically adds //go:build lines based on the existing // +build lines. Also update the corresponding GitHub action to use Go 1.17 gofmt.
2021-12-07Drop hacks to work around Go reflection bugs in Go1.9 (#282)Joe Tsai
Now that Go 1.11 is the minimally supported version, we can drop some local hacks to work around bugs in reflect that were present in Go1.9.
2021-12-07Update minimum supported version to go1.11 (#281)Damien Neil
2021-10-12Reduce minimum length for specialize string diffing (#275)Joe Tsai
The original threshold of 64 was chosen without much thought. Lower it to 32 now that we have some concrete examples that it is aesthetically better. Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2021-10-12Use any alias instead of interface{} (#276)Joe Tsai
See golang/go#33232.
2021-09-16Change build status badge (#269)Jake Son
Co-authored-by: Damien Neil <neild@users.noreply.github.com>
2021-09-16Fix spelling mistakes (#271)Joe Tsai
2021-07-22Use sha256 in test (#268)Joe Tsai
Some aggressive dependency checks flag the use of md5. Switch to sha256 as it accomplishes the same purpose.
2021-07-19Merge pull request #266 from dsnet/fix-formatDamien Neil
Fix textual printing of byte slices
2021-07-18Fix textual printing of byte slicesJoe Tsai
There are two bugs being fixed: 1. The hueristic for whether a slice of byte looks like text should check whether a rune IsPrint OR IsSpace, and not both. Only a single rune (i.e., U+0020) ever satisfies both conditions. Previously, it would print as: MyBytes{0x68, 0x65, 0x6c, 0x6c, 0x6f} and now it would now print as: MyBytes(MyBytes("hello")) 2. If we're printing as string, then we should set skipType=true since we already explicitly format the value with the type. Previously, it would print as: MyBytes(MyBytes("hello")) and now it would now print as: MyBytes("hello")
2021-05-27Avoid shadowing variable (#263)Joe Tsai
Rename the shadowed variable i to j for better readability.
2021-05-27Fix staticcheck findings (#262)Joe Tsai
Address some minor issues flagged by staticcheck. None of these affect the correctness of the package.
2021-05-24Print as text if mostly text (#258)Joe Tsai
The previous heuristic of treating strings as binary data if it contains any invalid UTF-8 was too strict. Loosen the heuristic to check if most of the characters are printable text. Fixes #257
2021-05-24Avoid diffing by lines if inefficient (#260)Joe Tsai
Avoid diffing by lines if it turns out to be significantly less efficient than diffing by bytes. Before this change: ( """ - d5c14bdf6bac81c27afc5429500ed750 - 25483503b557c606dad4f144d27ae10b - 90bdbcdbb6ea7156068e3dcfb7459244 - 978f480a6e3cced51e297fbff9a506b7 + Xd5c14bdf6bac81c27afc5429500ed750 + X25483503b557c606dad4f144d27ae10b + X90bdbcdbb6ea7156068e3dcfb7459244 + X978f480a6e3cced51e297fbff9a506b7 """ ) After this change: strings.Join({ + "X", "d5c14bdf6bac81c27afc5429500ed750\n", + "X", "25483503b557c606dad4f144d27ae10b\n", + "X", "90bdbcdbb6ea7156068e3dcfb7459244\n", + "X", "978f480a6e3cced51e297fbff9a506b7\n", }, "")
2021-05-24Cleanup edit groups after coalescing (#259)Joe Tsai
Even with an optimal diffing algoritm, coalescing adjacent edit groups may cause the corresponding pair of strings for an edit group to have leading or trailing spans of equal elements. While this is technically a correct representation of a diff, it is a suboptimal outcome. As such, scan through all unequal groups and move leading/trailing equal spans to the preceding/succeeding equal group. Before this change: strings.Join({ "org-4747474747474747,bucket-4242424242424242:m,tag1=a,tag2=aa", - ",#=_value _value=2 ", + " _value=2 ", `11 org-4747474747474747,bucket-4242424242424242:m,tag1=a,tag2=bb`, - ",#=_value _value=2 2", + " _value=2 2", `1 org-4747474747474747,bucket-4242424242424242:m,tag1=b,tag2=cc`, - ",#=_value", ` _value=1 21 org-4747474747474747,bucket-4242424242424242:m,tag1`, "=a,tag2", - "=dd,#=_value", + "=dd", ` _value=3 31 org-4747474747474747,bucket-4242424242424242:m,tag1`, - "=c,#=_value", + "=c", ` _value=4 41 `, }, "") After this change: strings.Join({ "org-4747474747474747,bucket-4242424242424242:m,tag1=a,tag2=aa", - ",#=_value", ` _value=2 11 org-4747474747474747,bucket-4242424242424242:m,tag1`, "=a,tag2=bb", - ",#=_value", ` _value=2 21 org-4747474747474747,bucket-4242424242424242:m,tag1`, "=b,tag2=cc", - ",#=_value", ` _value=1 21 org-4747474747474747,bucket-4242424242424242:m,tag1`, "=a,tag2=dd", - ",#=_value", ` _value=3 31 org-4747474747474747,bucket-4242424242424242:m,tag1`, "=c", - ",#=_value", ` _value=4 41 `, }, "")
2021-04-12Fix typo in path.go (#256)Ikko Ashimine
s/seperate/separate/
2021-03-03Fix reporter verbosity bug (#253)Joe Tsai
FormatDiff should only set the verbosity to 3 if the current verbosity is lower than 3. Otherwise, it may remove an intended higher verbosity setting causing the reporter output to not differentiate between two large values that are different at the end. While we are at it, increase the maxVerbosityPreset to 6.
2021-03-03De-virtualize interfaces for specialized diffing (#254)Joe Tsai
Specialized diffing strings and slices should occur for interface types where both values have the same concrete type. This is especially relevant for protocmp.Transform, which transforms every proto.Message as a map[string]interface{}.
2021-02-20Run tests on Go 1.16 (#252)Tobias Klauser
Add Go 1.16 to the GitHub actions test coverage matrix. Also switch the gofmt check to only run on Go 1.16, i.e. the latest supported version.
2021-02-04cmp/cmpopts: use errors.Is with ≥go1.13 in compareErrors (#251)Tobias Klauser
Use the standard definition of errors.Is to implement compareErrors with ≥go1.13. Retain the implementation using golang.org/x/xerrors for versions <go1.13. This will allow packages using newer Go versions and already relying on the errors package to get rid of the transitive dependency on golang.org/x/xerrors.
2020-11-24Impose verbosity limit when formatting map keys (#248)Joe Tsai
Map keys should have a sensible verbosity limit imposed, otherwise the reporter can end up printing a massive data structure that cannot reasonably fit in memory.
2020-11-24Fix non-determinism in diffing algorithm (#247)Joe Tsai
A previous attempt to add non-determinism to the diffing algorithm unfortunately broke the algorithm for half the cases. This change modifies the algorithm to truly switch between starting with a forward search versus a reverse search. The main for-loop of Difference would switch repeatedly between performing a forward search, then a reverse search, and vice-versa. Since we can't jump into the middle of a for-loop to start with the reverse search first, we use a series of labels and goto statements to accomplish the same effect. Fixes #238
2020-11-23Use GitHub actions for testing (#246)Joe Tsai
Use a GitHub action to run test on each push and pull request. We test across a matrix covering Linux and MacOSX, and Go 1.8 to 1.15.
2020-11-12Fix Diff documentation (#237)Joe Tsai
The description inaccurately describes the operation of Diff, which is y - x, where a '+' prefix denotes elements added from y and a '-' prefix denotes elements removed from x. For example: // Consider this call to Diff and its result. x y cmp.Diff({b:2, c:3}, {a:1, b:2}) => {+a:1, b:2, -c:3} // Consider the same in mathematical notation. y - x {a:1, b:2} - {b:2, c:3} = {+a:1, b:2, -c:3}
2020-11-12Revert "Adjust for reflect.Type.NumMethod change in Go1.16 (#240)" (#242)Joe Tsai
This reverts commit ab46b8bd0abd4c4557cc4709ad7ae12d47570603. The upstream change in Go1.16 has been rolled back. See golang/go#42123
2020-10-20Adjust for reflect.Type.NumMethod change in Go1.16 (#240)Joe Tsai
In Go1.16, the reflect.Type.NumMethod method will no longer report unexported fields, matching the documented behavior on the method. This means that t.NumMethod() == 0 is no longer a reliable means to detect whether an interface type is the empty interface or not. Fix the code to check whether the empty interface itself implements the target type.
2020-10-04Add an example for IgnoreFields (#205)colinnewell
Add an example for IgnoreFields. This resuses the test data from the example in the cmp package to provide consistency between examples.
2020-09-23Fix license headers (#236)Joe Tsai
There is no LICENSE.md file, but there is a LICENSE file.
2020-08-18Suggest use of cmpopts.EquateErrors (#234)Joe Tsai
If cmp panics because it is trying to access an unexported field, specially suggest the use of cmpopts.EquateErrors if the parent type implements the error interface. Fixes #233
2020-08-12Add testing for Go1.15 (#232)Joe Tsai
2020-07-29Fix Diff documentation (#231)Ernest Galbrun
Fix the documentation on Diff. It was mentioning the plus or minus sign being printed if the field was added to y or removed from y, but both are the same. Fix it so that it properly mentions the use of a minus sign for elements removed from x.
2020-07-21Use triple-quote formatting for multiline strings (#229)Joe Tsai
For strings, []bytes containing text data, Error method output, and String method output, use the triple-quoted syntax. This improves readability by presenting the data more naturally compared to a single-line quoted string with many escaped characters.