Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ASSERT to speed up tests #1750

Open
kuznetsss opened this issue Nov 22, 2024 · 0 comments
Open

Improve ASSERT to speed up tests #1750

kuznetsss opened this issue Nov 22, 2024 · 0 comments
Labels
testability Makes code testable and/or adds unit-tests
Milestone

Comments

@kuznetsss
Copy link
Collaborator

Summary

Improve ASSERT to speed up tests.

Motivation

Testing ASSERT() cases using gtest's death tests is very slow with code coverage enabled.

Solution

ASSERT() could be rewritten into something like:

class AssertImpl {
  static std::function<void(...)> onAssertFailed_;
public:
   static operator()(bool cond, ... ) {
      if (not cond) {
        if (not onAssertFailed) {
            defaultAssertFailed(...);
        } else {
           onAssertFailed_(...);
        }
      }
   }
   
  static defaultAssertFailed(...) { ... }
  static setAssertCallback(std::function<void(...)>) { ... }
};

Having such implementation we could create WithAssertMock class for tests which will set mock assert implementation in constructor and reset it in destructor. To mimic runtime break the real assert does, mock could throw an exception and tests could expect the exception instead of expecting death. Probably there are cases where ASSERT() is used inside try cache block, but there should be not so many of them and for such cases we could throw some unusual exception which is not inherited from std::exception.

@kuznetsss kuznetsss added the testability Makes code testable and/or adds unit-tests label Nov 22, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Clio Nov 22, 2024
@godexsoft godexsoft added this to the 2.4 milestone Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testability Makes code testable and/or adds unit-tests
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants