1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00
nix/tests/unit/libexpr/value/value.cc
José Luis Lafuente 5cc4af5231
Add isInitialized to nix::Value
Add a method to check if a value has been initialized. This helps avoid
segfaults when calling `type()`.
Useful in the context of the new C API.

Closes #10524
2024-04-21 22:44:13 +02:00

26 lines
432 B
C++

#include "value.hh"
#include "tests/libstore.hh"
namespace nix {
class ValueTest : public LibStoreTest
{};
TEST_F(ValueTest, unsetValue)
{
Value unsetValue;
ASSERT_EQ(false, unsetValue.isInitialized());
ASSERT_EQ(nThunk, unsetValue.type(true));
ASSERT_DEATH(unsetValue.type(), "");
}
TEST_F(ValueTest, vInt)
{
Value vInt;
vInt.mkInt(42);
ASSERT_EQ(true, vInt.isInitialized());
}
} // namespace nix