<div dir="ltr"><p dir="ltr">Although using DeepEquals on sorted lists does make for easier-to-understand test failure messages, the burden on the developer to sort the slices when they write the test doesn't seem worth it to me. Â We write tests a lot more often than we need to debug failing tests. Â If it was just slices of strings, then sorting is easy enough, but for other random types, you now have to figure out how to sort the types in a fully deterministic way, which can be difficult and error prone for large structs, especially as those structs change. </p>
<p>It's much easier and less error prone to say "just use jc.SameContents".</p>

<div class="gmail_quote">On May 22, 2014 10:42 AM, "Gustavo Niemeyer" <<a href="mailto:gustavo.niemeyer@canonical.com" target="_blank">gustavo.niemeyer@canonical.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

I apologize. After reading one of the review entries using<br>
SameContents, I see I've misunderstood what the problem is about. The<br>
v1 and v2 in your example is a slice, not a map, which means the test<br>
is comparing slices of undefined order. This is certainly bogus and<br>
needs addressing in the code itself, irrespective of any map-related<br>
issues.<br>
<br>
What I generally do in those cases is to define the ordering of the<br>
slice. Besides enabling DeepEquals, it also makes the visual<br>
comparison more pleasant.<br>
<br>
<br>
<br>
On Thu, May 22, 2014 at 11:34 AM, Gustavo Niemeyer<br>
<<a href="mailto:gustavo.niemeyer@canonical.com" target="_blank">gustavo.niemeyer@canonical.com</a>> wrote:<br>
> On Wed, May 21, 2014 at 10:43 PM, Ian Booth <<a href="mailto:ian.booth@canonical.com" target="_blank">ian.booth@canonical.com</a>> wrote:<br>
>> We are working to make all juju-core unit tests pass using gccgo. In case you<br>
>> didn't already know, there's a common issue which has caused a lot of the<br>
>> failures to date. Here's a quick heads up on how to deal with it.<br>
>><br>
>> golang-go and gcc-go have different map implementations which results in<br>
>> ordering differences, affecting things like range etc (simplistically put,<br>
>> gcc-go's map ordering is random whereas currently golang-go is somewhat<br>
>> deterministic).<br>
><br>
> This is changing in the main compiler as well, in Go 1.3:<br>
><br>
> Â  Â  <a href="http://tip.golang.org/doc/go1.3#map" target="_blank">http://tip.golang.org/doc/go1.3#map</a><br>
><br>
> So it'll become even less deterministic there as well.<br>
><br>
>> Now of course, maps are unordered but what we sometimes do in<br>
>> the code is to use a map to hold some data (maybe to eliminate duplicates) and<br>
>> then expose that data via a slice or array. If we then do a c.Assert(v1,<br>
>> gc.DeepEquals, v2), it will fail on gcc-go, since the order of items in the 2<br>
>> slices is different, even though the values are the same.<br>
><br>
> If that's really the case, it's definitely a bug in gccgo. gocheck's<br>
> DeepEquals is implemented in terms of reflect.DeepEqual, which should<br>
> not care about the map order. In the standard library of the main<br>
> compiler, it clearly does not:<br>
><br>
> Â  Â  Â  Â  for _, k := range v1.MapKeys() {<br>
> Â  Â  Â  Â  Â  Â  Â  Â  if !deepValueEqual(v1.MapIndex(k), v2.MapIndex(k),<br>
> visited, depth+1) {<br>
> Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  return false<br>
> Â  Â  Â  Â  Â  Â  Â  Â  }<br>
> Â  Â  Â  Â  }<br>
><br>
> So gocheck's DeepEquals is fine for such map tests, assuming no bugs<br>
> in the underlying implementation.<br>
><br>
><br>
> gustavo @ <a href="http://niemeyer.net" target="_blank">http://niemeyer.net</a><br>
<br>
<br>
<br>
--<br>
gustavo @ <a href="http://niemeyer.net" target="_blank">http://niemeyer.net</a><br>
<br>
--<br>
Juju-dev mailing list<br>
<a href="mailto:Juju-dev@lists.ubuntu.com" target="_blank">Juju-dev@lists.ubuntu.com</a><br>
Modify settings or unsubscribe at: <a href="https://lists.ubuntu.com/mailman/listinfo/juju-dev" target="_blank">https://lists.ubuntu.com/mailman/listinfo/juju-dev</a><br>
</blockquote></div>
</div>