1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

coerceToSingleDerivedPathUnchecked: pass through experimental features

This fixes a few of the property tests, now that the property tests
are actually generating arbitrary data - some of that data now
requiring experimental features to function properly.
This commit is contained in:
Brian McKenna 2025-03-08 10:56:44 +11:00
parent 9a04f1e732
commit c82ef825d4
5 changed files with 25 additions and 16 deletions

View file

@ -44,11 +44,11 @@ RC_GTEST_FIXTURE_PROP(
* to worry about race conditions if the tests run concurrently. * to worry about race conditions if the tests run concurrently.
*/ */
ExperimentalFeatureSettings mockXpSettings; ExperimentalFeatureSettings mockXpSettings;
mockXpSettings.set("experimental-features", "ca-derivations"); mockXpSettings.set("experimental-features", "ca-derivations dynamic-derivations");
auto * v = state.allocValue(); auto * v = state.allocValue();
state.mkOutputString(*v, b, std::nullopt, mockXpSettings); state.mkOutputString(*v, b, std::nullopt, mockXpSettings);
auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, ""); auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings);
RC_ASSERT(SingleDerivedPath { b } == d); RC_ASSERT(SingleDerivedPath { b } == d);
} }
@ -57,9 +57,12 @@ RC_GTEST_FIXTURE_PROP(
prop_derived_path_built_out_path_round_trip, prop_derived_path_built_out_path_round_trip,
(const SingleDerivedPath::Built & b, const StorePath & outPath)) (const SingleDerivedPath::Built & b, const StorePath & outPath))
{ {
ExperimentalFeatureSettings mockXpSettings;
mockXpSettings.set("experimental-features", "dynamic-derivations");
auto * v = state.allocValue(); auto * v = state.allocValue();
state.mkOutputString(*v, b, outPath); state.mkOutputString(*v, b, outPath, mockXpSettings);
auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, ""); auto [d, _] = state.coerceToSingleDerivedPathUnchecked(noPos, *v, "", mockXpSettings);
RC_ASSERT(SingleDerivedPath { b } == d); RC_ASSERT(SingleDerivedPath { b } == d);
} }

View file

@ -124,7 +124,9 @@ RC_GTEST_PROP(
prop_round_rip, prop_round_rip,
(const NixStringContextElem & o)) (const NixStringContextElem & o))
{ {
RC_ASSERT(o == NixStringContextElem::parse(o.to_string())); ExperimentalFeatureSettings xpSettings;
xpSettings.set("experimental-features", "dynamic-derivations");
RC_ASSERT(o == NixStringContextElem::parse(o.to_string(), xpSettings));
} }
#endif #endif

View file

@ -2245,18 +2245,18 @@ std::string_view EvalState::forceString(Value & v, const PosIdx pos, std::string
} }
void copyContext(const Value & v, NixStringContext & context) void copyContext(const Value & v, NixStringContext & context, const ExperimentalFeatureSettings & xpSettings)
{ {
if (v.payload.string.context) if (v.payload.string.context)
for (const char * * p = v.payload.string.context; *p; ++p) for (const char * * p = v.payload.string.context; *p; ++p)
context.insert(NixStringContextElem::parse(*p)); context.insert(NixStringContextElem::parse(*p, xpSettings));
} }
std::string_view EvalState::forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx) std::string_view EvalState::forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings)
{ {
auto s = forceString(v, pos, errorCtx); auto s = forceString(v, pos, errorCtx);
copyContext(v, context); copyContext(v, context, xpSettings);
return s; return s;
} }
@ -2462,10 +2462,10 @@ StorePath EvalState::coerceToStorePath(const PosIdx pos, Value & v, NixStringCon
} }
std::pair<SingleDerivedPath, std::string_view> EvalState::coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx) std::pair<SingleDerivedPath, std::string_view> EvalState::coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings)
{ {
NixStringContext context; NixStringContext context;
auto s = forceString(v, context, pos, errorCtx); auto s = forceString(v, context, pos, errorCtx, xpSettings);
auto csize = context.size(); auto csize = context.size();
if (csize != 1) if (csize != 1)
error<EvalError>( error<EvalError>(

View file

@ -159,7 +159,7 @@ void printEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env &
std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env); std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const Env & env);
void copyContext(const Value & v, NixStringContext & context); void copyContext(const Value & v, NixStringContext & context, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
std::string printValue(EvalState & state, Value & v); std::string printValue(EvalState & state, Value & v);
@ -510,7 +510,7 @@ public:
*/ */
void forceFunction(Value & v, const PosIdx pos, std::string_view errorCtx); void forceFunction(Value & v, const PosIdx pos, std::string_view errorCtx);
std::string_view forceString(Value & v, const PosIdx pos, std::string_view errorCtx); std::string_view forceString(Value & v, const PosIdx pos, std::string_view errorCtx);
std::string_view forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx); std::string_view forceString(Value & v, NixStringContext & context, const PosIdx pos, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
std::string_view forceStringNoCtx(Value & v, const PosIdx pos, std::string_view errorCtx); std::string_view forceStringNoCtx(Value & v, const PosIdx pos, std::string_view errorCtx);
template<typename... Args> template<typename... Args>
@ -562,7 +562,7 @@ public:
/** /**
* Part of `coerceToSingleDerivedPath()` without any store IO which is exposed for unit testing only. * Part of `coerceToSingleDerivedPath()` without any store IO which is exposed for unit testing only.
*/ */
std::pair<SingleDerivedPath, std::string_view> coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx); std::pair<SingleDerivedPath, std::string_view> coerceToSingleDerivedPathUnchecked(const PosIdx pos, Value & v, std::string_view errorCtx, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
/** /**
* Coerce to `SingleDerivedPath`. * Coerce to `SingleDerivedPath`.

View file

@ -84,7 +84,9 @@ RC_GTEST_FIXTURE_PROP(
prop_legacy_round_rip, prop_legacy_round_rip,
(const DerivedPath & o)) (const DerivedPath & o))
{ {
RC_ASSERT(o == DerivedPath::parseLegacy(*store, o.to_string_legacy(*store))); ExperimentalFeatureSettings xpSettings;
xpSettings.set("experimental-features", "dynamic-derivations");
RC_ASSERT(o == DerivedPath::parseLegacy(*store, o.to_string_legacy(*store), xpSettings));
} }
RC_GTEST_FIXTURE_PROP( RC_GTEST_FIXTURE_PROP(
@ -92,7 +94,9 @@ RC_GTEST_FIXTURE_PROP(
prop_round_rip, prop_round_rip,
(const DerivedPath & o)) (const DerivedPath & o))
{ {
RC_ASSERT(o == DerivedPath::parse(*store, o.to_string(*store))); ExperimentalFeatureSettings xpSettings;
xpSettings.set("experimental-features", "dynamic-derivations");
RC_ASSERT(o == DerivedPath::parse(*store, o.to_string(*store), xpSettings));
} }
#endif #endif