fish-shell/tests/checks
Fabian Homborg 733114fefb
Add set --function (#8145)
* Add `set --function`

This makes the function's scope available, even inside of blocks. Outside of blocks it's the toplevel local scope.

This removes the need to declare variables locally before use, and will probably end up being the main way variables get set.

E.g.:

```fish
set -l thing
if condition
    set thing one
else
    set thing two
end
```

could be written as

```fish
if condition
    set -f thing one
else
    set -f thing two
end
```

Note: Many scripts shipped with fish use workarounds like `and`/`or`
instead of `if`, so it isn't easy to find good examples.

Also, if there isn't an else-branch in that above, just with

```fish
if condition
    set -f thing one
end
```

that means something different from setting it before! Now, if
`condition` isn't true, it would use a global (or universal) variable of
te same name!

Some more interesting parts:

Because it *is* a local scope, setting a variable `-f` and
`-l` in the toplevel of a function ends up the same:

```fish
function foo2
    set -l foo bar
    set -f foo baz # modifies the *same* variable!
end
```

but setting it locally inside a block creates a new local variable
that shadows the function-scoped variable:

```fish
function foo3
    set -f foo bar
    begin
        set -l foo banana
        # $foo is banana
    end
    # $foo is bar again
end
```

This is how local variables already work. "Local" is actually "block-scoped".

Also `set --show` will only show the closest local scope, so it won't
show a shadowed function-level variable. Again, this is how local
variables already work, and could be done as a separate change.

As a fun tidbit, functions with --no-scope-shadowing can now use this to set variables in the calling function. That's probably okay given that it's already an escape hatch (but to be clear: if it turns out to problematic I reserve the right to remove it).

Fixes #565
2021-08-01 20:08:12 +02:00
..
broken-config/fish Port config tests to littlecheck 2019-06-25 22:31:06 +02:00
abbr.fish abbr: Don't write an error if erasing nonexisting abbrs 2020-10-04 12:34:38 +02:00
alias.fish Print nicer "defined in" for functions defined on stdin/via source 2020-12-11 23:09:16 +01:00
andandoror.fish Add a note for help thing to the missing doc error message 2021-03-19 17:39:36 +01:00
andor.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
argparse.fish argparse: Make short flag names optional (#7585) 2021-01-01 11:37:25 +01:00
bad-option.fish Fix typo in bad options test 2020-02-08 13:30:48 +01:00
basic.fish Fix crash if $PWD is used as for-loop variable 2021-07-30 15:33:04 +02:00
bind.fish Fix bind tests 2021-02-16 16:45:59 +01: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 Port some smaller tests to littlecheck 2020-02-08 09:31:49 +01:00
caller-observer.fish Fix up --on-job-exit caller 2020-02-08 16:23:25 -08:00
cd.fish Implicitly use $PWD in $CDPATH in completions and highlighting 2021-07-23 17:22:06 +02: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
cmdsub-limit.fish Add a test for background procs in cmdsubs 2021-01-07 11:38:52 -08:00
cmdsub.fish Support $(cmd) command substitution as alternative to (cmd) 2021-07-13 21:33:42 +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 Point to builtins begin/end when a failed command starts with "{" 2021-06-23 21:47:40 +02:00
command-vars-persist.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
complete_directories.fish Run __fish_complete_entries test in its own sandbox 2020-10-25 23:01:51 -05:00
complete.fish Resolve relative paths in command names for complete -p 2021-05-16 21:52:38 +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 source: Escape filenames in errors 2021-02-15 17:08:26 +01:00
exec.fish tests: Remove test for windows line ending message 2020-09-26 15:19:24 +02: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 Run parse_util_detect_errors on -c commands 2021-07-27 18:37:20 +02:00
fds.fish Revert "Prevent redirecting internal processes to file descriptors above 2" 2021-03-03 22:26:33 +01: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 Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-nocaret2.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-nocaret3.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-nocaret4.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
features-nocaret5.fish Fix some tests for OpenIndiana 2021-06-24 18:17:10 +02:00
features-qmark1.fish Port qmark1 test to littlecheck 2019-06-25 22:31:06 +02: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 fish_add_path tests 2021-06-23 21:30:10 +02:00
fish_user_paths.fish Deduplicate $fish_user_paths automatically 2021-07-14 16:37:30 +02:00
for.fish Don't overwrite unrelated variables with for-loop-variables 2020-01-08 09:10:14 +01:00
function-definition.fish Properly print leading comments and indentation in functions 2020-01-03 14:40:28 -08:00
function.fish Print nicer "defined in" for functions defined on stdin/via source 2020-12-11 23:09:16 +01:00
functions.fish functions: Add "--no-details" flag and use it in funced 2021-03-30 16:54:26 +02:00
git.fish completions/git: define function before use 2021-07-12 23:42:01 +02:00
glob.fish tests: Don't rely on $HOME existing 2020-12-29 12:48:11 +01:00
history.fish Port history tests to littlecheck 2020-02-07 20:53:20 +01: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 Run parse_util_detect_errors on -c commands 2021-07-27 18:37:20 +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 Try to fix tests for Solaris' ps 2021-06-24 18:19:28 +02: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 argparse: Only print stacktrace when it's an error in argparse usage 2020-06-17 20:05:48 +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 Shorten set --show output 2020-04-26 08:49:01 +02:00
math.fish tinyexpr: Check for nan in ncr 2021-07-26 18:40:50 +02: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 Migrate remaining calls from debug_safe to FLOGF_SAFE 2021-07-05 15:47:56 -07:00
pipeline-pgroup.fish tests: Pass $fish as a variable in some cases 2020-10-06 17:40:22 +02:00
pipestatus.fish Fix some tests for OpenIndiana 2021-06-24 18:17:10 +02:00
printf.fish printf: Don't print an error if not given an argument 2020-05-18 20:48:36 +02:00
psub.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
random.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
rc-returned.fish Port most of the invocation tests to littlecheck 2019-06-25 20:56:29 +02:00
read.fish checks/read: Print maximum if we fail to read it 2020-06-13 19:53:21 +02:00
realpath.fish builtin realpath: use absolute path also with -s/--no-symlinks 2020-12-24 08:53:08 +01:00
redirect.fish Revert "Prevent redirecting internal processes to file descriptors above 2" 2021-03-03 22:26:33 +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 Add a note for help thing to the missing doc error message 2021-03-19 17:39:36 +01:00
self-signal-usr1.fish Stop storing block_io in job_t 2019-12-11 16:34:20 -08:00
set.fish Add set --function (#8145) 2021-08-01 20:08:12 +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 Skip some tests on OpenBSD 2021-06-24 20:46:03 +02: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 Make '&' only background if followed by a separating character 2021-07-23 22:58:51 +02:00
string-advanced.fish Test string replace transforms 2021-03-21 10:03:35 +01:00
string.fish string: Add "--groups-only" to match 2021-07-16 20:27:54 +02:00
switch.fish Better errors when calling a command in a command substitution fails 2021-04-19 16:47:17 +02:00
symlinks-not-overwritten.fish Rewrite the real file if history file is a symlink (#7754) 2021-03-08 17:46:17 +01:00
test.fish Test numeric locale 2021-07-29 17:20:20 +02:00
threads.fish Reindent functions to remove useless quotes 2020-03-09 19:46:43 +01:00
time.fish List time as builtin, support time --help 2020-02-23 23:42:57 +01:00
tmux-bind.fish reader: fix regressions when moving between lines 2021-08-01 17:50:44 +02:00
tmux-complete.fish fix 'socket file name too long' error 2021-07-11 09:28:51 +02:00
tmux-prompt.fish Increase tmux-prompt test timeout in CI 2021-07-14 08:46:03 +02: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
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 Update littlecheck 2020-09-26 14:56:03 +02:00
wraps.fish Rework variable assignments during tab completion 2020-09-26 18:39:38 -07:00
zero_based_array.fish Port some smaller tests to littlecheck 2020-02-08 09:31:49 +01:00