32 lines
1.0 KiB
C++
32 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <thread>
|
|
|
|
#define CHECK(expression) \
|
|
do { \
|
|
if (!(expression)) { \
|
|
std::cerr << __FILE__ << ':' << __LINE__ << ": check failed: " #expression << '\n'; \
|
|
return 1; \
|
|
} \
|
|
} while (false)
|
|
|
|
inline std::filesystem::path test_directory(const char* name) {
|
|
auto path = std::filesystem::temp_directory_path() /
|
|
(std::string("izo-") + name + '-' +
|
|
std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()));
|
|
std::filesystem::create_directories(path);
|
|
return path;
|
|
}
|
|
|
|
template <typename Predicate>
|
|
bool wait_until(Predicate predicate, std::chrono::milliseconds timeout = std::chrono::seconds(3)) {
|
|
const auto deadline = std::chrono::steady_clock::now() + timeout;
|
|
while (!predicate() && std::chrono::steady_clock::now() < deadline)
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
return predicate();
|
|
}
|