| 166 | } |
| 167 | |
| 168 | for (const auto& candidate : candidates) { |
| 169 | if (Valdi::DiskUtils::stat(candidate).exists()) { |
| 170 | return candidate; |
| 171 | } |
| 172 | } |
| 173 | if (!candidates.empty()) { |
| 174 | return candidates.front(); |
| 175 | } |
| 176 | return Valdi::Path(path); |
| 177 | } |
| 178 | |
| 179 | Valdi::Result<Valdi::BytesView> loadFileFromAbsolutePath(const Valdi::Path& absolutePath) { |
| 180 | return Valdi::DiskUtils::load(absolutePath); |
| 181 | } |
| 182 | |
| 183 | Valdi::Result<Valdi::BytesView> loadResourceFromDisk(const std::string& path) { |
| 184 | auto result = loadFileFromAbsolutePath(resolveOpenSourceTestPath(path)); |
| 185 | if (result) { |
| 186 | return result; |
| 187 | } |
| 188 | // Fallbacks: Bazel may run tests with cwd = runfiles root without setting TEST_SRCDIR. |
| 189 | char cwdBuffer[PATH_MAX]; |
| 190 | if (::getcwd(cwdBuffer, PATH_MAX) != nullptr) { |
| 191 | Valdi::Path runfilesPath(cwdBuffer); |
| 192 | runfilesPath.append("valdi"); |
| 193 | runfilesPath.append(path); |
| 194 | runfilesPath.normalize(); |
| 195 | auto fallback = loadFileFromAbsolutePath(runfilesPath); |
| 196 | if (fallback) { |
| 197 | return fallback; |
no test coverage detected