Advertisement
chevengur

СПРИНТ № 3 | Фреймворк для юнит-тестов | Урок 3: Используем макросы и улучшаем фреймворк

Nov 14th, 2023 (edited)
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. void Assert(bool value, const string& str, const string& func_name,
  10.             const string& file_name, unsigned line_num, const string& hint) {
  11.     if(!value){
  12.         cout << func_name << "(" << line_num << "): " << file_name << ": ASSERT(" << str << ") ";
  13.         if(hint.empty()){
  14.             cout << "failed.";
  15.         }
  16.         else{
  17.             cout << "failed. Hint: " << hint;
  18.         }
  19.         cout << endl;
  20.         abort();
  21.     }
  22. }
  23.  
  24. void LogImpl();
  25.  
  26. #define ASSERT(expr) Assert(expr, #expr, __FILE__, __FUNCTION__, __LINE__, ""s)
  27.  
  28. #define ASSERT_HINT(expr, hint) Assert(expr, #expr, __FILE__, __FUNCTION__, __LINE__, (hint))
  29.  
  30. int main() {
  31.     string hello = "hello"s;
  32.     ASSERT(!hello.empty());
  33.     ASSERT_HINT(2 + 2 == 5, "This will fail"s);
  34.     return 0;
  35. }
  36.  
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement