mirror of
https://github.com/NixOS/nix.git
synced 2025-12-16 14:01:05 +01:00
Fix segfault in getUnitTestData() when env var not set
The previous implementation called .value() on std::optional without checking if it had a value. When _NIX_TEST_UNIT_DATA was not set, this would throw std::bad_optional_access or cause a segfault in code that used the raw getenv() result. The new implementation checks the optional first and throws an Error with a helpful message directing users to run tests via meson. The example includes --gdb since this situation may arise when trying to debug tests without knowing about meson's test infrastructure.
This commit is contained in:
parent
bb718d20a2
commit
b54dfb66dd
1 changed files with 5 additions and 1 deletions
|
|
@ -15,7 +15,11 @@ namespace nix {
|
|||
*/
|
||||
static inline std::filesystem::path getUnitTestData()
|
||||
{
|
||||
return getEnv("_NIX_TEST_UNIT_DATA").value();
|
||||
auto data = getEnv("_NIX_TEST_UNIT_DATA");
|
||||
if (!data)
|
||||
throw Error(
|
||||
"_NIX_TEST_UNIT_DATA environment variable is not set. Recommendation: use meson, example: 'meson test -C build --gdb'");
|
||||
return std::filesystem::path(*data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue