diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index a708111e5..f4270ee86 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1461,12 +1461,15 @@ static RegisterPrimOp primop_baseNameOf({ static void prim_dirOf(EvalState & state, const PosIdx pos, Value * * args, Value & v) { PathSet context; - auto path = state.coerceToString(pos, *args[0], context, false, false); - auto dir = dirOf(*path); - abort(); - #if 0 - if (args[0]->type() == nPath) v.mkPath(dir); else v.mkString(dir, context); - #endif + state.forceValue(*args[0], pos); + if (args[0]->type() == nPath) { + auto path = args[0]->path(); + v.mkPath({path.accessor, dirOf(path.path)}); + } else { + auto path = state.coerceToString(pos, *args[0], context, false, false); + auto dir = dirOf(*path); + v.mkString(dir, context); + } } static RegisterPrimOp primop_dirOf({ diff --git a/src/libexpr/tests/json.cc b/src/libexpr/tests/json.cc index f1ea1b197..6741a0221 100644 --- a/src/libexpr/tests/json.cc +++ b/src/libexpr/tests/json.cc @@ -57,6 +57,7 @@ namespace nix { ASSERT_EQ(getJSONValue(v), "\"test\\\"\""); } + #if 0 // The dummy store doesn't support writing files. Fails with this exception message: // C++ exception with description "error: operation 'addToStoreFromDump' is // not supported by store 'dummy'" thrown in the test body. @@ -65,4 +66,5 @@ namespace nix { v.mkPath("test"); ASSERT_EQ(getJSONValue(v), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\""); } + #endif } /* namespace nix */ diff --git a/src/libexpr/tests/libexprtests.hh b/src/libexpr/tests/libexprtests.hh index 4f6915882..418da6b6d 100644 --- a/src/libexpr/tests/libexprtests.hh +++ b/src/libexpr/tests/libexprtests.hh @@ -99,14 +99,17 @@ namespace nix { } MATCHER_P(IsPathEq, p, fmt("Is a path equal to \"%1%\"", p)) { - if (arg.type() != nPath) { - *result_listener << "Expected a path got " << arg.type(); - return false; - } else if (std::string_view(arg.string.s) != p) { - *result_listener << "Expected a path that equals \"" << p << "\" but got: " << arg.string.s; + if (arg.type() != nPath) { + *result_listener << "Expected a path got " << arg.type(); + return false; + } else { + auto path = arg.path(); + if (path.path != p) { + *result_listener << "Expected a path that equals \"" << p << "\" but got: " << path.path; return false; } - return true; + } + return true; } diff --git a/src/libexpr/tests/local.mk b/src/libexpr/tests/local.mk index b95980cab..115c70818 100644 --- a/src/libexpr/tests/local.mk +++ b/src/libexpr/tests/local.mk @@ -8,7 +8,7 @@ libexpr-tests_INSTALL_DIR := libexpr-tests_SOURCES := $(wildcard $(d)/*.cc) -libexpr-tests_CXXFLAGS += -I src/libexpr -I src/libutil -I src/libstore -I src/libexpr/tests +libexpr-tests_CXXFLAGS += -I src/libexpr -I src/libutil -I src/libstore -I src/libexpr/tests -I src/libfetchers libexpr-tests_LIBS = libexpr libutil libstore libfetchers