Echo Writes Code

expect.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "crucible/test/expect.hpp"

#include <cstring>
#include <sstream>

namespace crucible::test::expect {

#ifdef _WIN32
  constexpr char SOURCE_FILE_PATH_SEPARATOR = '\\';
#else
  constexpr char SOURCE_FILE_PATH_SEPARATOR = '/';
#endif // _WIN32

  auto fail(char const *message, char const *file, int const line, char const *function) -> void {
    char const *final_path_separator = std::strrchr(file, SOURCE_FILE_PATH_SEPARATOR);
    char const *truncated_file = final_path_separator ? final_path_separator + 1 : file;

    std::ostringstream buffer;
    buffer << truncated_file << ":" << line << " [" << function << "]: " << message;
    throw ExpectFailed(buffer.str());
  }
}