tests: attempt to find assets for tests run from build subfolder

This commit is contained in:
ochafik 2024-09-28 23:15:36 +01:00
parent bc3e0c0830
commit a072f30a8d
2 changed files with 8 additions and 1 deletions

View file

@ -63,6 +63,10 @@ static std::vector<std::string> find_files(const std::string & folder, const std
static std::string read_file(const std::string &path) {
std::ifstream fs(path, std::ios_base::binary);
if (!fs.is_open()) {
fs = std::ifstream("../" + path, std::ios_base::binary);
if (!fs.is_open()) {
throw std::runtime_error("Failed to open file: " + path);
}
throw std::runtime_error("Failed to open file: " + path);
}
fs.seekg(0, std::ios_base::end);

View file

@ -21,7 +21,10 @@ static void assert_equals(const std::string & expected, const std::string & actu
static std::string read_file(const std::string &path) {
std::ifstream fs(path, std::ios_base::binary);
if (!fs.is_open()) {
throw std::runtime_error("Failed to open file: " + path);
fs = std::ifstream("../" + path, std::ios_base::binary);
if (!fs.is_open()) {
throw std::runtime_error("Failed to open file: " + path);
}
}
fs.seekg(0, std::ios_base::end);
auto size = fs.tellg();