aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2021-06-29Regen Android.bp with go2bp am: 3debcec779Dan Willemsen
Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1716978 Change-Id: I2fdc020178077e2a94b42d8ae2632ebf86b11100
2021-06-28Regen Android.bp with go2bpDan Willemsen
This adds support for the cmpopts package, which is required by the new protobuf API. It also includes the tests so that they get run. Change-Id: Ib020b6ce4cccc1ec0a60c5d89193ca437ddcc1a6
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-27[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmp am: 5996e935ac am: ↵Bob Badour
2edf3ba00c am: 3c08d93f9d am: a627337043 Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1719333 Change-Id: Ia13d4112eee5f58866bdbea5cf649c98d1d9c3d5
2021-05-27[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmp am: 5996e935ac am: ↵Bob Badour
2edf3ba00c am: 3c08d93f9d Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1719333 Change-Id: I6565661ee60ce37fecae923fbb4426dc6f54c60c
2021-05-27[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmp am: 5996e935ac am: 2edf3ba00cBob Badour
Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1719333 Change-Id: Ic5124e94f1a33c104d69d88215ec4a57c2710a76
2021-05-27[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmp am: 5996e935acBob Badour
Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1719333 Change-Id: Ia25cc737edbc7a47010362473a6286e7bd316b49
2021-05-26[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmpBob Badour
Added SPDX-license-identifier-BSD to: Android.bp Bug: 68860345 Bug: 151177513 Bug: 151953481 Test: m all Exempt-From-Owner-Approval: janitorial work Change-Id: I986cbf13affb6752d52e3002bc01d37e32d3b52c
2021-05-26[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmp am: 3b8a7ef8d4 am: 93d737cc3eBob Badour
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/go-cmp/+/14735751 Change-Id: I1de483b7150dff9a7e8ae08f7c6d3f575130bb41
2021-05-26[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmp am: 3b8a7ef8d4Bob Badour
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/go-cmp/+/14735751 Change-Id: I0d87e8f8f9a048db2f44898c327049e9b8711896
2021-05-26[LSC] Add LOCAL_LICENSE_KINDS to external/go-cmpBob Badour
Added SPDX-license-identifier-BSD to: Android.bp Bug: 68860345 Bug: 151177513 Bug: 151953481 Test: m all Exempt-From-Owner-Approval: janitorial work Change-Id: Ia15c0733793a7619c617c746a0c4e24d739d45f5
2021-05-26Update go-cmp to 'v0.5.5' am: 58624c34adDan Willemsen
Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1712605 Change-Id: Id511fce83de15f590e6102179878a208428bbae4
2021-05-26Create go-cmp module am: 0f7c828c80Sasha Smundak
Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1327476 Change-Id: I1b0ffa29cd77a579ca4e88366c9a5198bdde5b1d
2021-05-26Merge sso://github/google/go-cmp, add mandatory files am: 1ea8835d09Sasha Smundak
Original change: https://android-review.googlesource.com/c/platform/external/go-cmp/+/1327475 Change-Id: I9bb13705cff688a5f4b6ecdf12f2a9a374880b7d
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-05-19Update go-cmp to 'v0.5.5'Dan Willemsen
Change-Id: Ic01ac28abadcda509aab67e4da9c0e0ea83769f5
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.
2020-07-14Adjust panic for IgnoreUnexported and IgnoreFields (#228)k.nakada
Adjust the panic message to be more specific about what the user should do, and reduces the need for the user to look at the source code.
2020-06-22Swallow panic when calling String or Error (#221)Joe Tsai
If a panic occurs while calling String or Error, the reporter recovers from it and ignores it, proceeding with its usual functionality for formatting a value.
2020-06-17Improve reporting of values with cycles (#217)Joe Tsai
Previously, the reporter could handle formatting values with cycles in that it did not crash with a stack overflow. However, the output was not particularly understandable as it did not surface to the user why a particular value was truncated, and if it was truncated due to a cyclic reference, what was the referent. This change annotates the reporter tree with pointer information so that a later pass can inject reference information if it is needed to produce more understandable output. Consider the following example: map[string]*cmp_test.CycleAlpha{ "Foo": &⟪ref#0⟫{ Name: "Foo", Bravos: map[string]*cmp_test.CycleBravo{ "FooBravo": &{ - ID: 101, + ID: 0, Name: "FooBravo", Mods: 100, Alphas: {"Foo": &⟪ref#0⟫(...)}, }, }, }, } This graph contains a cycle. To ensure that a graph can be formatted, the cycle is truncated as indicated with: &⟪ref#0⟫(...). The referent was identified earlier with: &⟪ref#0⟫{...}.
2020-06-17Update test case names (#218)Joe Tsai
Provide a unique name for every test case. Provide a reason for every test case. The purpose of a unique name is so that insertion/removal of a case does not cause all subsequent names to suddenly shift, causing a larger number of differences in testdata/diffs.
2020-06-17Fix documentation on IgnoreFields (#220)Joe Tsai
The function now handles unexported fields since #203.
2020-06-12Disambiguate reporter output (#216)Joe Tsai
The reporter tries to aggresively elide data that is not interesting to the user. However, doing so many result in an output that does not visually indicate the difference between semantically different objects. This CL modifies the reporter to try increasingly verbose presets until two different objects are formatted differently. This CL includes a custom implementation of reflect.Type.String that can print the type with fully qualified names to disambiguate types that happen to have the same base package name. Fixes #194
2020-06-11Limit verbosity of reporter output (#215)Joe Tsai
A common complaint is that the reporter it prints out too much irrelevant information, resulting in a low signal-to-noise ratio. Improve this metric by imposing a verbosity limit. For nodes that are equal, we set the verbosity level is a lower value than when the nodes are inequal. Other minor changes: * Adjust heuristic for triple-quote usage to operate on more cases. * Elide type more aggressively for equal nodes. * Printing the address for a slice includes the length and capacity. * The pointed-at value for map keys are printed.
2020-06-10Limit number of printed differences for variable-length composites (#213)Joe Tsai
For large slices, arrays, and maps, the reporter can be unreadable if there are many differences. Limit the number of results to some reasonable maximum.
2020-06-10Introduce deliberate instability to difference output (#214)Joe Tsai
The reporter output is documented as unstable. The API for custom reporters also specifies that the diffing of slices is unstable. Introduce deliberate instability to the diffing algorithm so that we have the flexibility to improve it in the future. The current algorithm optimizes for speed, rather than optimality, so there is much room for improvement.
2020-06-10Use custom triple-quote syntax for diffing string literals (#212)Joe Tsai
Using strings.Join to denote differences in a multi-line string is visually noisy due to extensive use of quotes and escape sequences. Add a custom triple-quote syntax that unambiguously shows line differences with less visual noise. If the triple-quote syntax cannot unmabiguously show differences, then the reporter falls back on using the strings.Join format, which is never ambiguous. Fixes #195
2020-06-10Use raw string literal syntax only for valid UTF-8 (#211)Joe Tsai
2020-06-10Allow batched diffing of slices with a custom comparer (#210)Joe Tsai
For correctness, cmp checks applicability of the options for every element in a slice. For large []byte, this is a significant performance detriment. The workaround is to specify Comparer(bytes.Equal). However, we would still like to have the batched diffing if the slices are different. Specialize for this situation.
2020-06-10Batch reporter output for simple lists of textLine elements (#208)Joe Tsai
Rather than having a single element on each line, which hurts readability due to the need for scrolling quite a bit. Batch multiple elements for simple lists to be on a single line. Fixes #170
2020-06-10Mention minimally supported Go version in TODO (#209)Joe Tsai
Specify the exact minimumally supported version of Go required in order to address certain TODOs. This makes it easier to filter out inactionable TODOs.