File Helpers
-
namespace fh
Namespace for file and data helpers.
Functions
-
auto unitTestExecutablePath() -> std::filesystem::path
Access the executable path for the unittest executable.
- Returns:
The absolute path to the currently executed unittest executable.
-
auto resolveDataPath(std::string_view relativePath) -> std::filesystem::path
Resolves the path to a test data file or directory.
This method searches for the given relative path in the directory containing the executable and its parent directory to support various CMake build configurations (e.g., MSVC multi-config builds).
- Parameters:
relativePath – The relative path to the test data.
- Throws:
AssertFailed – If the path cannot be resolved.
- Returns:
The resolved absolute path to the test data.
-
auto readDataText(std::string_view relativePath, std::size_t maximumSize) -> std::string
Reads the complete contents of a test data file into a string.
- Parameters:
relativePath – The relative path to the test data file.
maximumSize – The maximum allowed size of the file in bytes (default 10MB).
- Throws:
AssertFailed – If the file cannot be found or exceeds the maximum size.
- Returns:
The contents of the file as a string.
-
auto readDataLines(std::string_view relativePath, std::size_t maximumSize = 10000000U) -> std::vector<std::string>
Reads a test data file line by line into a vector of strings.
- Parameters:
relativePath – The relative path to the test data file.
maximumSize – The maximum allowed size of the file in bytes (default 10MB).
- Throws:
AssertFailed – If the file cannot be found or exceeds the maximum size.
- Returns:
A vector containing each line of the file.
-
auto unitTestExecutablePath() -> std::filesystem::path