question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intentions to change `assert(a == b)` to `assert_eq(a, b)`

See original GitHub issue

There are handy assert_eq, assert_ne macros in Rust. It would be nice to have inspections which would highlightassert!(a == b) and assert!(a != b) and suggest to change them into assert_eq(a, b) and assert_ne!(a, b).

A similar inspection is implemented here: https://github.com/intellij-rust/intellij-rust/blob/master/src/main/kotlin/org/rust/ide/inspections/RsSimplifyPrintInspection.kt

A complete example of adding new inspections is here: https://github.com/intellij-rust/intellij-rust/commit/df64cbac9b6d14413bd15f3e33971ea725108a1e#diff-5e7848624647a9a96dd649e15fa64ae5

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
mkaputcommented, Oct 5, 2017

At the moment, assert_eq! gives a better error message, so I think we should flip the direction of the intention once the RFC is implemented and is stable. If one does not want better messages, now, one can disable the inspection 😃

Note that our plugin is often used by beginner rustaceans, and so this intention might encourage them to use pattern which soon will be deprecated.

2reactions
robinstcommented, Oct 4, 2017

Note that recently an RFC was accepted that makes assert!(a == b) the preferred form in the future: RFC 2011 Nicer assert messages

So I would consider undoing the warning about using assert!, to not make people switch to assert_eq! and then back when the better assert! is implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python's assert: Debug and Test Your Code Like a Pro
In this tutorial, you'll learn how to use Python's assert statement to document, debug, and test code in development.
Read more >
Python Assert Statement - Programiz
In this article we will learn about assertion in Python using assert. What is Assertion? Assertions are statements that assert or state a...
Read more >
unittest — Unit testing framework — Python 3.11.1 ...
The crux of each test is a call to assertEqual() to check for an expected result; ... There is less temptation to change...
Read more >
What is the use of "assert" in Python? - Stack Overflow
The assert statement exists in almost every programming language. It has two main uses: It helps detect problems early in your program, ...
Read more >
Assertion assertNotEquals Provides Wrong Error Message On ...
Failed asserting that 'a b c' is not equal to 'a b c'. ... And it produces an unexpected error message that it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found