bazelbuild / bazelbuild/bazel-skylib

asserts.equals could give better diffs when comparing objects of same built-in type

Open
#333 3 comments 0 reactions 0 assignees View on GitHub
P3 type: feature request
Dominant language
Starlark
Stars
444
Forks
202
PR merge metrics
No merged PRs in 30d

Description

The current implementation of `asserts.equals(expected, actual)` in unittest.bzl puts just `str(value)` for each of the values in the assertion failure message. It would be nice if it gave a more detailed analysis of where the values differed when the values being compared were both lists, dicts, or (multi-line) strings. (This is analagous to what Python does in `unittest.TestCase.assertEqual`.)

For `list`, it should provide a diff of the items which makes it clear which subsequences are shared, which appear just in `expected`, and which appear just in `actual`.

For `dict`, it should make it clear which keys are just in `expected`, which are just in `actual`, which are in both with the same value, and which are in both with different values.

For `str`, it should show a multi-line readable diff, possibly in unified diff format.

That would make these tests much easier to debug when the values in the assertions are complicated.

Contributor guide

Open the contributing guide

Research direction

Start in unittest.bzl at the implementation of asserts.equals(expected, actual). Read how assertion failure messages are currently built, then define coverage for list, dict, and multiline string comparisons; done means failures clearly identify shared, expected-only, actual-only, and differing content as requested.

Written by the indexing model from the issue text.

Assessment

Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.