fish-shell/tests/checks
Fabian Homborg f6fb347d98 Add "path" builtin
This adds a "path" builtin that can handle paths.

Implemented so far:

- "path filter PATHS", filters paths according to existence and optionally type and permissions
- "path base" and "path dir", run basename and dirname, respectively
- "path extension PATHS", prints the extension, if any
- "path strip-extension", prints the path without the extension
- "path normalize PATHS", normalizes paths - removing "/./" components
- and such.
- "path real", does realpath - i.e. normalizing *and* link resolution.

Some of these - base, dir, {strip-,}extension and normalize operate on the paths only as strings, so they handle nonexistent paths. filter and real ignore any nonexistent paths.

All output is split explicitly, so paths with newlines in them are
handled correctly. Alternatively, all subcommands have a "--null-input"/"-z" and "--null-output"/"-Z" option to handle null-terminated input and create null-terminated output. So

    find . -print0 | path base -z

prints the basename of all files in the current directory,
recursively.

With "-Z" it also prints it null-separated.

(if stdout is going to a command substitution, we probably want to
skip this)

All subcommands also have a "-q"/"--quiet" flag that tells them to skip output. They return true "when something happened". For match/filter that's when a file passed, for "base"/"dir"/"extension"/"strip-extension" that's when something about the path *changed*.

Filtering
---------

`filter` supports all the file*types* `test` has - "dir", "file", "link", "block"..., as well as the permissions - "read", "write", "exec" and things like "suid".

It is missing the tty check and the check for the file being non-empty. The former is best done via `isatty`, the latter I don't think I've ever seen used.

There currently is no way to only get "real" files, i.e. ignore links pointing to files.

Examples
--------

> path real /bin///sh
/usr/bin/bash

> path extension foo.mp4
mp4

> path extension ~/.config
  (nothing, because ".config" isn't an extension.)
2022-05-29 17:48:11 +02:00
..
broken-config/fish Port config tests to littlecheck 2019-06-25 22:31:06 +02:00
abbr.fish Fix abbr return status 2021-11-11 16:46:23 +01:00
alias.fish Print nicer "defined in" for functions defined on stdin/via source 2020-12-11 23:09:16 +01:00
andandoror.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
andor.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
argparse.fish argparse: Jump to the next option after an unknown one 2022-01-15 12:17:43 +01:00
bad-option.fish Fix typo in bad options test 2020-02-08 13:30:48 +01:00
basic.fish Make byte/unicode escapes with no digits a tokenizer error 2022-03-03 12:18:13 +01:00
bind.fish Clarify that the variable/mode *name* is invalid 2022-04-08 16:38:46 +02:00
braces.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
broken-config.fish Port config tests to littlecheck 2019-06-25 22:31:06 +02:00
builtinbuiltin.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
caller-observer.fish Fix up --on-job-exit caller 2020-02-08 16:23:25 -08:00
cd.fish broken-symbolic-link test to enter a new directory 2021-09-24 17:35:45 -07:00
check-all-fish-files.fish Revert "Revert "Speed up check-all-fish-files when executed locally"" 2021-03-06 17:13:20 -06:00
check-completions.fish source the files instead 2022-04-21 17:40:25 +02:00
check-translations.fish Add a test to check format strings in translations 2021-10-18 17:02:17 +02:00
cmdsub-limit.fish Add a test for background procs in cmdsubs 2021-01-07 11:38:52 -08:00
cmdsub.fish Fix spurious syntax error on escaped $@ inside quoted command substitution 2022-04-03 16:18:47 +02:00
colon-delimited-var.fish Clean up how PATH and CDPATH munging occurs 2019-11-02 16:48:08 -07:00
command-1.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
command-2.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
command-not-found.fish Move executable-check to C++ 2022-03-31 15:16:01 +02:00
command-vars-persist.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
commandline.fish commandline: Add --is-valid option (#8142) 2021-08-14 11:29:22 +02:00
complete_directories.fish Run __fish_complete_entries test in its own sandbox 2020-10-25 23:01:51 -05:00
complete.fish complete: Print better error for -x -F 2022-05-26 14:17:15 +02:00
contains_opt.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
count.fish Port count test to littlecheck 2019-06-26 21:19:40 +02:00
deep-cmdsub.fish Add a test for deep command substitutions 2020-01-18 11:50:50 -08:00
directory-redirect.fish Fix tests 2020-01-19 15:07:06 +01:00
disown-parent.fish Add a tricky test to verify disowning an in-flight job 2019-12-08 11:44:21 -08:00
empty.fish Run fish_indent on all our fish scripts 2020-01-13 20:34:22 +01:00
env.fish Correctly mark a node when erasing an exported variable 2019-06-28 11:22:49 -07:00
eval.fish Make eval a reserved keyword 2022-05-18 18:47:10 +02:00
exec.fish Improve error for redirections to invalid paths 2021-11-20 17:44:05 +01:00
exit-status-with-closing-stderr.fish Run fish_indent on all our fish scripts 2020-01-13 20:34:22 +01:00
expansion.fish builtin string: don't print final newline if it's missing from stdin 2021-11-27 19:11:24 +01:00
fds.fish necro working tests from 11a373f121 2021-10-21 23:50:42 -07:00
features-ampersand-nobg-in-token1.fish Teach fish_indent about our feature flags 2021-07-23 22:58:51 +02:00
features-nocaret1.fish Force stderr-nocaret feature flag on 2022-04-15 13:42:38 +02:00
features-nocaret2.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-nocaret3.fish Force stderr-nocaret feature flag on 2022-04-15 13:42:38 +02:00
features-nocaret4.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-qmark1.fish Re-add explicit littlecheck HOME/XDG_CONFIG_HOME overrides on request 2021-08-29 12:38:28 -05:00
features-qmark2.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-string-backslashes-off.fish tests, CHANGELOG: regex-easyesc 2019-08-13 22:56:31 -07:00
features-string-backslashes.fish tests, CHANGELOG: regex-easyesc 2019-08-13 22:56:31 -07:00
fish_add_path.fish Fix tests 2022-05-17 17:21:42 +02:00
fish_user_paths.fish Deduplicate $fish_user_paths automatically 2021-07-14 16:37:30 +02:00
for.fish Don't fire variable set event before entering a for-loop 2021-10-28 16:32:58 +02:00
function-definition.fish Properly print leading comments and indentation in functions 2020-01-03 14:40:28 -08:00
function.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
functions.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
git.fish completions/git: Check alias definitions for an option 2022-03-30 18:25:00 +02:00
glob.fish tests: Don't rely on $HOME existing 2020-12-29 12:48:11 +01:00
history.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
indent.fish fish_indent: handle tokens with trailing escaped newlines 2021-08-01 18:59:45 +02:00
init-command-2.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
init-command-mix-ordering.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
init-command-mix.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
init-command.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
init-unreadable-cwd.fish Ignore unreadable cwd error harder 2020-02-14 20:09:07 +01:00
invocation.fish Actually return when reading file failed 2021-08-29 08:36:54 +02:00
job-control-noninteractive.fish tests: Remove unnecessary status fish-path 2021-03-10 18:04:04 +01:00
job-control-not-a-tty.fish terminal_maybe_give_to_job to stop returning error on ENOTTY 2020-04-18 16:26:54 -07:00
job-ids.fish tests/job-ids: Wait for job to die 2020-01-25 14:06:34 +01:00
jobs.fish Test that --on-job-exit functions run even if the job has already exited 2021-10-28 10:02:48 -07:00
line-continuation.fish Reformat fish scripts with escaped newline changes to fish_indent 2020-03-15 21:01:11 +01:00
line-number.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
locale-numeric.fish Move the numeric locale tests to a different file 2021-08-17 15:36:07 +02:00
locale.fish Try to set LC_CTYPE to something UTF-8 capable (#8031) 2021-06-06 09:28:32 +02:00
loops.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
math.fish Merge branch 'master' into te-refactor 2022-03-13 11:24:31 +01:00
no-config.fish Only use DATADIR in $fish_function_path if no-config is used 2021-05-01 18:59:25 +02:00
no-execute.fish Don't time --no-execute 2020-02-17 11:39:53 +01:00
noshebang.fish postfork: further updates to error messages 2021-12-29 22:33:24 +08:00
not.fish Declare that two "not" keywords cancel each other out 2021-12-28 19:32:30 +01:00
path.fish Add "path" builtin 2022-05-29 17:48:11 +02:00
pipeline-pgroup.fish tests: Pass $fish as a variable in some cases 2020-10-06 17:40:22 +02:00
pipestatus.fish Improve error for redirections to invalid paths 2021-11-20 17:44:05 +01:00
printf.fish printf: Explain what couldn't be converted 2021-11-20 17:44:05 +01:00
prompt.fish prompt_pwd: full-dirs set to 0 means not even last component is safe 2021-08-09 17:42:00 +02:00
psub.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
random.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
rc-returned.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
read.fish Use head instead of dd in the read test 2022-04-02 13:44:58 -07:00
realpath.fish normalize_path: Squash leading slashes even without allow_leading 2021-09-09 18:41:11 +02:00
redirect.fish Improve error for redirections to invalid paths 2021-11-20 17:44:05 +01:00
regex-import.fish Correct behavior of string match variable import with multiple arguments 2021-04-20 15:15:52 -07:00
return.fish Let "return" exit a script (#8148) 2021-07-21 22:33:39 +02:00
scoping.fish Update tests for changed error output 2021-11-03 22:54:55 -07:00
self-signal-usr1.fish Stop storing block_io in job_t 2019-12-11 16:34:20 -08:00
set.fish set: Add special error for set foo=bar 2022-04-08 16:50:34 +02:00
setenv.fish Port setenv tests to littlecheck 2019-07-09 10:02:50 -07:00
sigint.fish tests: Remove unnecessary status fish-path 2021-03-10 18:04:04 +01:00
sigint2.fish Disable job control inside command substitutions 2021-08-18 22:20:03 +08:00
signal.fish Fix some tests for OpenIndiana 2021-06-24 18:17:10 +02:00
slices.fish Revert "Disallow escaped characters in variable expansion" 2021-06-10 16:46:17 +02:00
stack-overflow.fish Remove the forbidden function stack 2019-11-10 12:36:46 -08:00
status-command.fish Skip some tests on OpenBSD 2021-06-24 20:46:03 +02:00
status-value.fish Rationalize $status and errors 2020-01-25 17:28:41 -08:00
status.fish Let stderr-nocaret description say it's read-only 2022-04-15 13:42:38 +02:00
string-advanced.fish Test string replace transforms 2021-03-21 10:03:35 +01:00
string.fish Merge branch 'master' into string-preserve-missing-newline 2022-03-13 11:21:53 +01:00
switch.fish Point wildcard error at a more specific help section 2021-08-11 18:40:37 +02:00
symlinks-not-overwritten.fish Re-add explicit littlecheck HOME/XDG_CONFIG_HOME overrides on request 2021-08-29 12:38:28 -05:00
syntax-error-location.fish Make string syntax error location a bit more precise 2022-04-03 16:34:46 +02:00
test.fish test: Also print proper caret for too many arguments 2021-12-24 16:08:41 +01:00
threads.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
time.fish Revert changes to time formatting 2022-02-21 22:48:43 +01:00
tmux-abbr.fish Only expand abbreviations if cursor is directly at command token 2021-11-14 11:52:10 +01:00
tmux-bind.fish isolated-tmux to more reliably initialize and other fixes 2021-09-24 08:07:17 -07:00
tmux-complete.fish Fix tmux-complete test on macOS CI 2021-12-02 15:10:13 +01:00
tmux-history-search.fish Disable tmux-history-search test on GH Actions 2022-03-13 11:48:52 +01:00
tmux-prompt.fish isolated-tmux to more reliably initialize and other fixes 2021-09-24 08:07:17 -07:00
trace.fish Change fish_trace prefix to "->" instead of plusses 2020-12-11 21:24:33 +01:00
type.fish type: Add --quiet back 2021-03-02 14:53:02 +01:00
ulimit.fish ulimit: add basic tests 2022-03-24 10:23:04 +08:00
umask.fish Port umask tests to littlecheck 2020-03-16 21:21:10 +01:00
variable-assignment.fish use variable assignments on commandline in completions 2020-01-17 14:53:35 +01:00
vars_as_commands.fish Forbid $status as a command 2021-07-27 18:37:20 +02:00
version.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
wait.fish Fix some tests for OpenIndiana 2021-06-24 18:17:10 +02:00
wildcard.fish Remove TMPDIR dependency from tests/ 2021-08-29 08:56:12 +02:00
wraps.fish Rework variable assignments during tab completion 2020-09-26 18:39:38 -07:00
zero_based_array.fish Add more tests for literal zero indexes 2021-08-15 13:48:41 -05:00