Skip to content

Commit

Permalink
ErrorMessagesSpec: make failures easier to read
Browse files Browse the repository at this point in the history
Old output of `sbt test`:

```
ErrorMessagesSpec:
- attr_invalid_switch_inner *** FAILED ***
  attr_invalid_switch_inner.ksy: /seq/1/size:
  	error: invalid type: expected integer, got CalcBooleanType

  attr_invalid_switch_inner.ksy: /seq/1/size:
  	error: invalid type: expected integer, got CalcBooleanType
   did not equal attr_invalid_switch_inner.ksy: /seq/1/size:
  	error: invalid type: expected integer, got CalcBooleanType (SimpleMatchers.scala:34)
```

New output of `sbt test`:

```
ErrorMessagesSpec:
- attr_invalid_switch_inner *** FAILED ***
  [attr_invalid_switch_inner.ksy: /seq/1/size:
         error: invalid type: expected integer, got CalcBooleanType

  attr_invalid_switch_inner.ksy: /seq/1/size:
         error: invalid type: expected integer, got CalcBooleanType
  ]
    did not equal
  [attr_invalid_switch_inner.ksy: /seq/1/size:
         error: invalid type: expected integer, got CalcBooleanType
  ] (SimpleMatchers.scala:34)
```
  • Loading branch information
generalmimon committed Mar 22, 2024
1 parent e31f147 commit f93fa66
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion jvm/src/test/scala/io/kaitai/struct/SimpleMatchers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait SimpleMatchers {
def shouldEqualPlainly(right: Any)(implicit equality: Equality[T]): Assertion =
if (!equality.areEqual(leftSideValue, right)) {
throw new exceptions.TestFailedException(
(e: exceptions.StackDepthException) => Some(s"""${leftSideValue} did not equal ${right}"""),
(e: exceptions.StackDepthException) => Some(s"""[${leftSideValue}]\n did not equal\n[${right}]"""),
None,
Position.here
)
Expand Down

2 comments on commit f93fa66

@Mingun
Copy link
Contributor

@Mingun Mingun commented on f93fa66 Mar 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add some diffing library so we could see pretty-printed diffs like https://lib.rs/crates/pretty_assertions does?

@GreyCat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is exactly the opposite. Any kind of pretty printing should happen externally after raw comparison results has been delivered. There are plenty of GUI tools for diffing (including ones in intellij, in vscode, in eclipse) which do a much better job than arbitrary static ASCII output can do. We shouldn't cripple them.

Please sign in to comment.