-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib.fileset.fileFilter
: init
#260265
Merged
Merged
lib.fileset.fileFilter
: init
#260265
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -678,6 +678,73 @@ tree=( | |||||||||
checkFileset 'intersection (unions [ ./a/b ./c/d ./c/e ]) (unions [ ./a ./c/d/f ./c/e ])' | ||||||||||
|
||||||||||
|
||||||||||
## File filter | ||||||||||
|
||||||||||
# The predicate is not called when there's no files | ||||||||||
tree=() | ||||||||||
checkFileset 'fileFilter (file: abort "this is not needed") ./.' | ||||||||||
checkFileset 'fileFilter (file: abort "this is not needed") _emptyWithoutBase' | ||||||||||
|
||||||||||
# The predicate must be able to handle extra attributes | ||||||||||
touch a | ||||||||||
expectFailure 'toSource { root = ./.; fileset = fileFilter ({ name, type }: true) ./.; }' 'called with unexpected argument '\''"lib.fileset.fileFilter: The predicate function passed as the first argument must be able to handle extra attributes for future compatibility. If you'\''re using `\{ name, file \}:`, use `\{ name, file, ... \}:` instead."'\' | ||||||||||
rm -rf -- * | ||||||||||
|
||||||||||
# .name is the name, and it works correctly, even recursively | ||||||||||
tree=( | ||||||||||
[a]=1 | ||||||||||
[b]=0 | ||||||||||
[c/a]=1 | ||||||||||
[c/b]=0 | ||||||||||
[d/c/a]=1 | ||||||||||
[d/c/b]=0 | ||||||||||
) | ||||||||||
checkFileset 'fileFilter (file: file.name == "a") ./.' | ||||||||||
tree=( | ||||||||||
[a]=0 | ||||||||||
[b]=1 | ||||||||||
[c/a]=0 | ||||||||||
[c/b]=1 | ||||||||||
[d/c/a]=0 | ||||||||||
[d/c/b]=1 | ||||||||||
) | ||||||||||
checkFileset 'fileFilter (file: file.name != "a") ./.' | ||||||||||
|
||||||||||
# `.type` is the file type | ||||||||||
mkdir d | ||||||||||
touch d/a | ||||||||||
ln -s d/b d/b | ||||||||||
mkfifo d/c | ||||||||||
expectEqual \ | ||||||||||
'toSource { root = ./.; fileset = fileFilter (file: file.type == "regular") ./.; }' \ | ||||||||||
'toSource { root = ./.; fileset = ./d/a; }' | ||||||||||
expectEqual \ | ||||||||||
'toSource { root = ./.; fileset = fileFilter (file: file.type == "symlink") ./.; }' \ | ||||||||||
'toSource { root = ./.; fileset = ./d/b; }' | ||||||||||
expectEqual \ | ||||||||||
'toSource { root = ./.; fileset = fileFilter (file: file.type == "unknown") ./.; }' \ | ||||||||||
'toSource { root = ./.; fileset = ./d/c; }' | ||||||||||
expectEqual \ | ||||||||||
'toSource { root = ./.; fileset = fileFilter (file: file.type != "regular") ./.; }' \ | ||||||||||
'toSource { root = ./.; fileset = union ./d/b ./d/c; }' | ||||||||||
expectEqual \ | ||||||||||
'toSource { root = ./.; fileset = fileFilter (file: file.type != "symlink") ./.; }' \ | ||||||||||
'toSource { root = ./.; fileset = union ./d/a ./d/c; }' | ||||||||||
expectEqual \ | ||||||||||
'toSource { root = ./.; fileset = fileFilter (file: file.type != "unknown") ./.; }' \ | ||||||||||
'toSource { root = ./.; fileset = union ./d/a ./d/b; }' | ||||||||||
rm -rf -- * | ||||||||||
|
||||||||||
# It's lazy | ||||||||||
tree=( | ||||||||||
[b]=1 | ||||||||||
[c/a]=1 | ||||||||||
) | ||||||||||
# Note that union evaluates the first argument first if necessary, that's why we can use ./c/a here | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
|
||||||||||
checkFileset 'union ./c/a (fileFilter (file: assert file.name != "a"; true) ./.)' | ||||||||||
# but here we need to use ./c | ||||||||||
checkFileset 'union (fileFilter (file: assert file.name != "a"; true) ./.) ./c' | ||||||||||
|
||||||||||
## Tracing | ||||||||||
|
||||||||||
# The second trace argument is returned | ||||||||||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, nice one!