You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #205190 some property tests were added, but extending those turns out to be pretty hard, which was noticed in #209099 when trying to add more.
This is a draft for a new generic property-testing framework that's pretty simple to use. It should eventually be usable for all the path library functions from #210426
Here's a messed up regex for the lib.path.subpath.isValid check:
diff --git a/lib/path/default.nix b/lib/path/default.nix
index 96a9244407b..8c6fa15af44 100644
--- a/lib/path/default.nix+++ b/lib/path/default.nix@@ -34,7 +34,7 @@ let
else if substring 0 1 value == "/" then
"The given string \"${value}\" starts with a `/`, representing an absolute path"
# We don't support ".." components, see ./path.md#parent-directory
- else if match "(.*/)?\\.\\.(/.*)?" value != null then+ else if match "(.*/)?\\.\\.(/.+)?" value != null then
"The given string \"${value}\" contains a `..` component, which is not allowed in subpaths"
else null;
And this is what you get when you try to run the property tests:
$ lib/path/tests/run.sh
Running property test normalise-append
Running property test normalise-error
Property test normalise-error failed: Expected variables valid and normalise_success to be the same, but they're not
[awk] subpath = gen_subpath() =
../
[awk] valid = subpath_is_valid(subpath) ? "true" : "false" =
false
[nix] normalise_success = lib.boolToString (builtins.tryEval (lib.path.subpath.normalise subpath)).success =
true
To reproduce run: lib/path/tests/run.sh normalise-error 15645
While this was interesting to create, and awk is a surprisingly good language (except the lack of local variables), the proper way to do this is to have stable language bindings for e.g. Python. For this there's already https://github.com/Mic92/pythonix, but that was archived due to requiring too much maintenance (since it relied on the unstable Nix library interface).
I updated pythonix to the latest Nix version in this fork's commit, but I'm considering upstreaming those bindings to Nix, such that they don't need to be maintained independently anymore.
I'm closing this since there's now a PR to have Python bindings for Nix (outdated, won't get merged), and another one for C bindings (could get merged). Any of those approaches would be better than this hack here :).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.severity: significantNovel ideas, large API changes, notable refactorings, issues with RFC potential, etc.6.topic: libThe Nixpkgs function library
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of changes
In #205190 some property tests were added, but extending those turns out to be pretty hard, which was noticed in #209099 when trying to add more.
This is a draft for a new generic property-testing framework that's pretty simple to use. It should eventually be usable for all the path library functions from #210426
This work is sponsored by Antithesis ✨
Example
Here's a messed up regex for the
lib.path.subpath.isValidcheck:And this is what you get when you try to run the property tests: