Commit Graph

1668 Commits

Author SHA1 Message Date
ridiculousfish
0f56db55a2 Correct "fire_exit" event back to "fish_exit"
This was causing fish_exit to not fire, which caused (among other things)
leaking tmux processes from the tests.

This was bisected to eacbd6156d
2024-01-13 15:20:59 -08:00
Fabian Boehm
2e14c32c5e fish_indent: Another crash
NUL at the end, which is now ignored.

Not *great*, but better than crashing.
2024-01-10 20:56:13 +01:00
Fabian Boehm
50acc4f4de fish_indent: Fix crash with NUL in the source
Really we should *reject* this
2024-01-10 20:47:39 +01:00
Fabian Boehm
52a3e1393f Add tests 2024-01-10 19:36:06 +01:00
Fabian Boehm
b5ccacf5b5 fish_indent: Fix crash with redirection at the end of the source 2024-01-10 18:54:25 +01:00
Johannes Altmanninger
e84d110995 Fix arithmetic overflow in up-line
The C++ code implicitly relied on wrapping behavior.

There are probably more cases like this.  Maybe we should disable
"overflow-checks" in release mode.
2024-01-10 09:38:45 +01:00
Fabian Boehm
b82dad0160 Fix tokenizer crash
This would crash from the highlighter for something like

`PATH={$PATH[echo " "`

The underlying cause is that we use "char_at" which panics on
overread.

So instead this implements try_char_at and then just returns None.
2024-01-09 19:12:16 +01:00
Fabian Boehm
f7c9538fb0 wildcard: Check trailing components against
Forward-port of c31e194120,
Revert of 6823f5e337,
Fixes #10205
2024-01-09 19:08:52 +01:00
Fabian Boehm
16c2c14fb4 Restyle 2024-01-07 15:13:34 +01:00
Johannes Altmanninger
1093c636e5 Add missing expect_prompt to test_sigint.py
Somehow the Rust port of reader requires this.
2024-01-07 00:54:22 +01:00
Fabian Boehm
06de374ffd Log original exit code used when a builtin returns a negative exit code
Port of b91723dab6
2024-01-05 16:52:18 +01:00
Fabian Boehm
1fdbac3320 tests: Lengthen a timeout
This fails on ASAN a bunch now, let's see if it's just slower
2024-01-02 22:42:19 +01:00
Fabian Boehm
5a77db8353 fish_key_reader: Only name keys if they match the entire sequence
This would misname `\e\x7F` as "backspace":

bind -k backspace 'do something'
bind \e\x7F 'do something'

because it would check if there was any key *in there*.

This was probably meant for continuous mode, but it simply doesn't
work right. It's preferable to not give a key when one would work over
giving one when it's not correct.
2024-01-02 17:27:20 +01:00
Fabian Boehm
6618ca17f2 set: Fix set -e without arguments
This didn't actually error out because we passed all of args.

It *might* be cleaner to pass a slice?
2024-01-01 16:21:08 +01:00
Fabian Boehm
b895cf49ca umask: Correctly handle empty symbolic value
Simple return/echo confusion.

Fixes #10177
2023-12-31 19:39:23 +01:00
ridiculousfish
a54bb8dc14 Clean up tests/checks/bind.fish
This had some unnecessary bits and a CHECKERR was in a very confusing place.
2023-12-29 16:26:39 -08:00
Fabian Boehm
e318585021 Don't replace tilde for error messages if we have no $HOME
This was an issue with "--no-execute", which has no variables and
therefore no $HOME:

```fish
fish --no-execute /path/to/file
```

would say the error is in `~/path/to/file`.

Instead, since this is just for a message, we simply return the
filename without doing the replacement.

Fixes #10171
2023-12-28 10:19:48 +01:00
Fabian Boehm
b1a1a3b0a7 prompt_pwd: Fix missing --
Fixes #10169
2023-12-25 18:46:23 +01:00
Fabian Boehm
eb196c8330 Encode all ENCODE_DIRECT codepoints with encode_direct
forward-port of 09986f5563
2023-12-10 09:29:42 +01:00
Fabian Boehm
fe9d1228e1 function: Fix a broken format string 2023-12-01 18:15:11 +01:00
Fabian Boehm
13ba5bd405 disown: Fix a format string
Missed in 77aeb6a2a8, this would crash otherwise.
2023-11-29 16:59:53 +01:00
Fabian Boehm
45829804af tests: Skip job_summary under ASAN in CI 2023-11-19 19:46:05 +01:00
Johannes Altmanninger
7df70e18f4 Add hint to error message about cmdsub in command position
We might end up allowing this but let's add some help for now.

See #5575
2023-11-18 12:26:45 +01:00
Fabian Boehm
366b3f21c6 tests: Increase a sleep 2023-11-15 17:58:42 +01:00
Fabian Boehm
67faa107b0 expand_cmdsubst: Make more errors known
These printed "Unknown error while evaluating command substitution".

Now they print something like

```
fish: for: status: cannot overwrite read-only variable
for status in foo; end
    ^~~~~^
in command substitution
fish: Invalid arguments
echo (for status in foo; end)
     ^~~~~~~~~~~~~~~~~~~~~~~^
```

for `echo (for status in foo; end)`

This is, of course, still not *great*. Mostly the `fish: Invalid
arguments` is basically entirely redundant.

An alternative is to simply skip the error message, but that requires some
more scaffolding (describe_with_prefix adds some error messages on its
own, so we can't simply say "don't add the prefix if we don't have a
message")

(cherry picked from commit 1b5eec2af6)
2023-11-09 17:51:15 +01:00
ridiculousfish
f7e7396c69 Fix a deadlock affecting fish_config
This fixes the following deadlock. The C++ functions path_get_config and
path_get_data lazily determine paths and then cache those in a C++ static
variable. The path determination requires inspecting the environment stack.
If these functions are first called while the environment stack is locked
(in this case, when fetching the $history variable) we can get a deadlock.

The fix is to call them eagerly during env_init. This can be removed once
the corresponding C++ functions are removed.

This issue caused fish_config to fail to report colors and themes.

Add a test.
2023-10-07 15:20:14 -07:00
Fabian Boehm
496d65fb5d Apply variable overrides for exec
Fixes #9995
2023-10-06 18:15:25 +02:00
Fabian Boehm
3ce67ecbd2 printf: Fix octal escapes with leading zeroes
Octal escapes can be written as `\057` or as `\0057`.

Simply ported wrong initially.
2023-10-05 15:39:50 +02:00
Fabian Boehm
ff8a79a823 Add a test for fish_add_path with relative paths 2023-09-29 16:54:23 +02:00
Fabian Boehm
4d2f7b0c0d
ast: Require --help to parse more keywords as decorated statement (#10000)
This makes it so

```fish
if -e foo
    # do something
end
```

complains about `-e` not being a command instead of `end` being used
outside of an if-block.

That means both that `-e` could now be used as a command name (it
already can outside of `if`!) *and* that we get a better error!

The only way to get `if` to be a decorated statement now is to use `if
-h` or `if --help` specifically (with a literal option).

The same goes for switch, while and begin.

It would be possible, alternatively, to disallow `if -e` and point
towards using `test` instead, but the "unknown command" message should
already point towards using `test` more than pointing at the
"end" (that might be quite far away).
2023-09-19 17:34:13 +02:00
Fabian Boehm
6194899c6b tests: Remove a misunderstanding 2023-09-15 20:04:13 +02:00
Johannes Altmanninger
e2ee8a0beb isolated-tmux: fix quoting error 2023-09-14 20:42:25 +02:00
Fabian Boehm
136dc6ce28 Test for mktemp completion
Turns out fish isn't in $PATH on the CI systems
2023-09-11 16:52:38 +02:00
Fabian Boehm
110de8e0df Harden test
Turns out the order wasn't the same on CI as it was on my system. Just
match it.
2023-09-10 20:56:58 +02:00
Fabian Boehm
b03327f5d2 __fish_complete_command: Fix --foo= logic
This was already supposed to handle `--foo=bar<TAB>` cases, except it
printed the `--foo=` again, causing fish to take that as part of the
token.

See #9538 for a similar thing with __fish_complete_directories.

Fixes #10011
2023-09-10 18:16:41 +02:00
Henrik Hørlück Berg
676c3c9bc2 Re-use DEFAULT_PATH in setup_path
- No need to hard-code a different default
2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
3a4149a9e7 Add test that confirms behavior when PATH is unset 2023-09-05 11:38:59 +02:00
Henrik Hørlück Berg
eacbd6156d Port and adopt main written in Rust
We don't change anything about compilation-setup, we just immediately jump to
Rust, making the eventual final swap to a Rust entrypoint very easy.

There are some string-usage and format-string differences that are generally
quite messy.
2023-09-05 11:38:59 +02:00
Fabian Boehm
9f5f34267d key delay: Add tests
I already forsee these being annoying on CI, because they involve a timeout.
2023-08-30 23:13:10 +02:00
Fabian Boehm
55c425a0dd fish_key_reader: Humanize key descriptions
This used to print all codepoints outside of the ASCII range (i.e.
above 0x80) in \uXXXX or \UYYYYYYYY notation.

That's quite awkward, considering that this is about keys that are
being pressed, and many keyboards have actual symbols for these on
them - I have an "ö" key, so I would like to use `bind ö` and not
`bind \u00F6`. So we go by iswgraph.

On a slightly different note, `\e` was written as `\c[ (or \e)`. I do
not believe anyone really uses `\c[` (the `[` would need to
be escaped!), and it's confusing and unnecessary to even mention that.
2023-08-26 10:43:42 +02:00
Fabian Boehm
482616f101 parse_util: Only reject time in a pipeline without decorator
This allows e.g. `foo | command time`, while still rejecting `foo | time`.

(this should really be done in the ast itself, but tbh most of
parse_util kinda should)

Fixes #9985
2023-08-25 19:45:15 +02:00
Fabian Boehm
06b89083d5 tinyexpr: Check for wcstod errors
This would otherwise unwrap() an Err and crash.
2023-08-25 16:15:52 +02:00
Fabian Boehm
eaa3f0486c math: Add tests for args via stdin and argv
This reads stdin and ignores argv, which is certainly a choice.

Leaving it this way for now, and possibly discussing later.
2023-08-20 14:52:58 +02:00
Fabian Boehm
a29aa44183 functions: Fix command name
This was "function", needs to be "function*s*".

It was only an issue in the option parsing because we set cmd there
again instead of passing it. Maybe these should just be file-level constants?
2023-08-18 17:16:44 +02:00
Fabian Boehm
0874dd6a96 pexpects: Fix spurious failure in generic.py
This used expect_re with a regex ending in `.*`, followed by an
`expect_prompt`.

This meant that, depending on the timing, the regex could swallow the
prompt marker, which caused extremely confusing output like

>Testing file pexpects/generic.py:Failed to match pattern: prompt 14
> ...
> OUTPUT      +1.33 ms (Line 70): \rprompt 13>functions\r\nN_, abbr,
> alias, bg, cd, [SNIP], up-or-search, vared, wait\r\n⏎
> \r⏎ \r\rprompt 14>

Yeah - it shows that "prompt 14" was in the output and it can't find
"prompt 14".

I could reproduce the failure locally when running the tests
repeatedly. I got one after 17 attempts and so far haven't been able
to reproduce it with this change applied.
2023-08-15 19:14:33 +02:00
Fabian Boehm
6489ef5ac0 Rewrite builtin functions in rust 2023-08-13 14:17:44 +02:00
Fabian Boehm
ee8e790aa7 Fix event::print's header printing
Turns out doing `==` on Enums with values will do a deep comparison,
including the values.

So EventDescription::Signal(SIGTERM) is !=
EventDescription::Signal(SIGWINCH).

That's not what we want here, so this does a bit of a roundabout thing.
2023-08-13 14:17:44 +02:00
Fabian Boehm
27a11ef7fe builtin builtin: Print help if run without an action to do
Fixes #9942
2023-08-09 17:26:07 +02:00
Johannes Altmanninger
b7f7dcf788 Copy history pager search field to command line on Enter if no match
Closes #9934
2023-08-08 21:53:42 +02:00
ridiculousfish
6d4916a77c Stop using path sort in some path tests
Globs are already sorted, so this should be unnecessary. Remove these and add a
test that we are sorted already.
2023-08-07 19:56:27 -07:00
Fabian Boehm
ab6abaa114 Fix path tests on FreeBSD 2023-08-07 17:22:19 +02:00
ridiculousfish
f4132af114 Further improve builtin path tests 2023-08-06 18:51:11 -07:00
ridiculousfish
62ad661a5c Add some more builtin path tests
This plugs some holes in our tests.
2023-08-06 18:16:07 -07:00
ridiculousfish
0d3f943f30 Add some additional tests for builtin math
This fills some gaps in our error message test coverage.
2023-08-05 11:54:39 -07:00
Henrik Hørlück Berg
900a048744 Don't segfault if user has an invalid locale
Fixes #9928
2023-08-03 19:55:05 +02:00
Henrik Hørlück Berg
6dd2cd2b20 Fix behaviour in the presence of non-visible width
Padding with an unprintable character is now disallowed, like it was for other
zero-length characters.

`string shorten` now ignores escape sequences and non-printable characters
when calculating the visible width of the ellipsis used (except for `\b`,
which is treated as a width of -1).
Previously `fish_wcswidth` returned a length of -1 when the ellipsis-str
contained any non-printable character, causing the command to poentially
print a larger width than expected.

This also fixes an integer overflows in `string shorten`'s
`max` and `max2`, when the cumulative sum of character widths turned negative
(e.g. with any non-printable characters, or `\b` after the changes above).
The overflow potentially caused strings containing non-printable characters
to be truncated.

This adds test that verify the fixed behaviour.
2023-07-27 22:00:03 -07:00
Henrik Hørlück Berg
20be990fd9 Port builtins/string to Rust
- Add test to verify piped string replace exit code

Ensure fields parsing error messages are the same.

Note: C++ relied upon the value of the parsed value even when `errno` was set,
that is defined behaviour we should not rely on, and cannot easilt be replicated from Rust.
Therefore the Rust version will change the following error behaviour from:

```shell
> string split --fields=a "" abc
string split: Invalid fields value 'a'
> string split --fields=1a "" abc
string split: 1a: invalid integer
```

To:

```shell
> string split --fields=a "" abc
string split: a: invalid integer
> string split --fields=1a "" abc
string split: 1a: invalid integer
```
2023-07-27 22:00:03 -07:00
Henrik Hørlück Berg
6325b3662d Fix #9899 integer overflow in string repeat
We could end up overflowing if we print out something that's a multiple of the
chunk size, which would then finish printing in the chunk-printing, but not
break out early.
2023-07-17 15:41:08 +02:00
Fabian Boehm
a6c36a014c Return a falsey status if the last -c command has a parse error
This makes `fish -c begin` fail with a status of 127 - it already
printed a syntax error so that was weird. (127 was the status for
syntax errors when piping to fish, so we stay consistent with that)

We allow multiple `-c` commands, and this will return the regular
status if the last `-c` succeeded.

This is fundamentally an extremely weird situation but this is the
simple targeted fix - we did nothing, unsuccessfully, so we should
fail.

Things to consider in future:

1. Return something better than 127 - that's the status for "unknown
command"!
2. Fail after a `-c` failed, potentially even checking all of them
before executing the first?

Fixes #9888
2023-07-12 18:06:34 +02:00
elyashiv
3fbff14e9b [tests] added test for escaped job summary 2023-07-10 18:38:26 +02:00
Fabian Boehm
c7b43b3abf Truncate builtin arguments on NUL
This restores the status quo where builtins are like external commands
in that they can't see anything after a 0x00, because that's the c-style
string terminator.
2023-06-24 21:26:44 +02:00
Fabian Boehm
41568eb2a8 Move NUL-handling tests to their own file 2023-06-24 21:26:44 +02:00
Fabian Boehm
11c8d9684e
Make NULs work for builtins (#9859)
* Make NULs work for builtins

This switches from passing a c-string to output_stream_t::append to
passing a proper string.

That means a builtin that prints a NUL no longer crashes with "thread '' panicked
at 'String contained intermediate NUL character: ".

Instead, it will actually handle the NUL, even as an argument.

That means something like

`echo foo\x00bar` will now actually print a NUL instead of truncating
after the `foo` because we passed c-strings around everywhere.

The former is *necessary* for e.g. `string`, the latter is a change
that on the whole makes dealing with NULs easier, but it is a
behavioral change.

To restore the c-string behavior we would have to truncate arguments
at NUL.

See #9739.

* Use AsRef instead of trait bound
2023-06-22 20:50:22 +02:00
Fabian Boehm
4e3b3b3b0a share/config.fish: Quit if job expansion hack errors
This prevents something like `fg %5` to foreground the first job if
there is no fifth.

Fixes #9835
2023-06-10 15:36:36 +02:00
Fabian Boehm
65769bf8c8 history: Allow deleting ranges
This allows giving a range like "5..7".

It works in combination with more (including overlapping) ranges or
single indices.

Fixes #9736
2023-06-10 15:35:40 +02:00
Fabian Boehm
946ecf235c Restyle fishscript and python 2023-06-01 18:20:19 +02:00
Fabian Boehm
364f8223b2 pexpects: Skip eval-stack-overflow under ASAN CI 2023-05-12 19:26:10 +02:00
Fabian Boehm
56743ae770 tests: More slack for ASAN
Disable one and add a sleep to another
2023-05-11 22:14:12 +02:00
Fabian Boehm
8d5a223b39 tests/pexpect: Disable wait.py under SAN CI 2023-05-11 21:42:19 +02:00
Fabian Boehm
05e7732cb8 tests: Disable one commandline test
Keeps failing under ASAN on Github Actions
2023-04-28 17:41:29 +02:00
Fabian Boehm
3bfe798dbb Fix read_blocked
This caused math to assert out because it never wrote into the buffer.

Now, presumably it wrote somewhere but I don't know where, so fixing
this seems like a good idea.

Fixes #9735.
2023-04-17 17:28:24 +02:00
Fabian Boehm
662a4740e2 Rewrite the type builtin in rust 2023-04-16 11:27:08 +02:00
ridiculousfish
a487b1ecf2 Revert "Revert "Implement builtin_printf in Rust""
This reverts commit 9f7e6a6cd1.

Add additional fixes from code review.
2023-04-06 15:54:09 -07:00
Johannes Altmanninger
05bad5eda1 Port common.{h,cpp} to Rust
Most of it is duplicated, hence untested.

Functions like mbrtowc are not exposed by the libc crate, so declare them
ourselves.
Since we don't know the definition of C macros, add two big hacks to make
this work:
1. Replace MB_LEN_MAX and mbstate_t with values (resp types) that should
   be large enough for any implementation.
2. Detect the definition of MB_CUR_MAX in the build script. This requires
   more changes for each new libc. We could also use this approach for 1.

Additionally, this commit brings a small behavior change to
read_unquoted_escape(): we cannot decode surrogate code points like \UDE01
into a Rust char, so use � (\UFFFD, replacement character) instead.
Previously, we added such code points to a wcstring; looks like they were
ignored when printed.
2023-04-02 15:17:06 +02:00
Fabian Boehm
c39780fefb __fish_complete_directories: Remove --foo= from token
Otherwise this would complete

`git --exec-path=foo`, by running `complete -C"'' --exec-path=foo"`,

which would print "--exec-path=foo", and so it would end as

`git --exec-path=--exec-path=foo` because the "replaces token" bit was
lost.

I'm not sure how to solve it cleanly - maybe an additional option to
`complete`?

Anyway, for now this
Fixes #9538.
2023-03-27 22:57:34 +02:00
Fabian Boehm
a16abf22d9 builtins: Don't crash for negative return values
Another from the "why are we asserting instead of doing something
sensible" department.

The alternative is to make exit() and return() compute their own exit
code, but tbh I don't want any *other* builtin to hit this either?

Fixes #9659
2023-03-14 10:53:35 +01:00
Mahmoud Al-Qudsi
dabe7a1c7c Skip tmux-complete test under WSL
The test passes but only if executed on its own. It's not the most perfect test,
but I can basically never get `make test` to pass under WSL while that's not the
case on all my other machines.
2023-03-12 15:18:17 -05:00
Fabian Boehm
4fd1458d85 Port random to rust 2023-02-19 21:01:46 +01:00
Xiretza
ba0bfb9df7 functions: list caller-exit handlers correctly
`functions --handlers-type caller-exit` did not list any functions, while
`functions --handlers-type process-exit` listed both process-exit and
caller-exit handlers:

$ echo (function foo --on-job-exit caller; end; functions --handlers-type caller-exit | grep foo)

$ echo (function foo --on-job-exit caller; end; functions --handlers-type process-exit | grep foo)
caller-exit foo
2023-02-18 18:35:40 +01:00
Fabian Boehm
4a1a59c5a8 tests/git: Also give the email to stash
WHYYYYYYYY

(anyway this seems to affect old git versions since we only seem to
hit it on old Ubuntu)
2023-02-15 20:11:46 +01:00
Fabian Boehm
d32449fe2e tests/git: Don't silence error, give email
(otherwise git complains about "AUTHOR UNKNOWN HELP HELP HELP I CANNAE
DO ANYTHIN'")

(i also don't know why git is scottish in my imagination)
2023-02-15 19:50:45 +01:00
Sam Bull
ef3516ecdf
Test displaying only stash count (#9573) 2023-02-15 19:32:50 +01:00
Fabian Boehm
200095998a __fish_complete_directories: Use an empty command as the dummy
Fixes #9574
2023-02-14 17:09:58 +01:00
esdmr
a607421912
functions --copy: store file and lineno (#9542)
Keeps the location of original function definition, and also stores
where it was copied. `functions` and `type` show both locations,
instead of none. It also retains the line numbers in the stack trace.
2023-02-13 09:59:28 -06:00
ridiculousfish
b7de768c73 Allow custom completions to have leading dots
By default, fish does not complete files that have leading dots, unless the
wildcard itself has a leading dot. However this also affected completions;
for example `git add` would not offer `.gitlab-ci.yml` because it has a
leading dot.

Relax this for custom completions. Default file expansion still
suppresses leading dots, but now custom completions can create
leading-dot completions and they will be offered.

Fixes #3707.
2023-02-11 11:27:14 -08:00
Fabian Boehm
7f2cb47437 fish_key_reader: Don't translate things to "\v" and friends
This translated ctrl-k to "\v", which is a "vertical tab", and ctrl-l
to "\f" and ctrl-g to "\a".

There is no "vertical tab" or "alarm" or "\f" *key*, so these
shouldn't be translated. Just drop these and call them `\ck` and such.

(vertical tab specifically is utterly useless and I would be okay with
dropping it entirely, I have never seen it used anywhere)
2023-01-27 17:07:18 +01:00
Fabian Boehm
9043008933 abbr: Clarify universal variable message
And give explicit upgrade instructions.
2023-01-21 16:53:59 +01:00
Fabian Boehm
48db9e6a3f tests/signals.py: Increase a sleep 2023-01-18 16:48:49 +01:00
Johannes Altmanninger
e84f588d11 reader: make Escape during history search restore commandline again
Commit 3b30d92b6 (Commit transient edit when closing pager, 2022-08-31)
inadvertently introduced two regressions to history search:

1. It made Escape keeps the selected history entry,
   instead of restoring the commandline before history search.
2. It made history search commands add undo entries.

Fix both of this issues.
2023-01-17 09:31:04 +01:00
Fabian Boehm
6df09b3753
completions: Offer ../ and ./ again (#9477)
Inadvertently broken in a2d816710f,
this made `cd .` no longer offer `cd ../` (same for general file completions
like `ls .`, which only offers dotfiles)
2023-01-16 10:05:01 +01:00
Fabian Boehm
077118d983 abbr: Fix crash when no name has been given
This crashed for

```fish
abbr --add --regex '{\d+..\d+}' --function foo
```

i.e. a regex and a function but no name - that's 0 additional
arguments.
2023-01-15 10:50:09 +01:00
Fabian Boehm
dad8c527e0 read: Error on read-only variables
Fixes #9346
2023-01-13 17:56:28 +01:00
Fabian Boehm
1b1cf73b60 abbr: Stop escaping the name for abbr --list
This is so we can pass it to `abbr --erase`.

Fixes #9470
2023-01-13 16:38:34 +01:00
Fabian Boehm
572a568268 abbr: Erase the old universal variable with abbr --erase
This means cleaning out old universal variables is now just:

```fish
abbr --erase (abbr --list)
```

which makes upgrading much easier.

Note that this erases the currently defined variable and/or any
universal. It doesn't stop at the former because that makes it *easy*
to remove the universals (no running `abbr --erase` twice), and it
doesn't care about globals because, well, they would be gone on
restart anyway.

Fixes #9468.
2023-01-13 16:09:53 +01:00
Fabian Boehm
2da1a4ae77 completions/git: Fix git-foo commands
Broken in f5711ad5ed, this neglected to
remove the `git-` part from the command

Fixes #9457.
2023-01-09 18:40:24 +01:00
Fabian Boehm
4c39aeed87 abbr: Let --function use a mandatory argument
This now means `abbr --add` has two modes:

```fish
abbr --add name --function foo --regex regex
```

```fish
abbr --add name --regex regex replacement
```

This is because `--function` was seen to be confusing as a boolean flag.
2022-12-24 10:29:26 +01:00
Fabian Boehm
ff800c68e8 tests: Increase one more timeout
Example output from a Cirrus bionic-asan-clang run:

```
fish: Unknown command: man
/tmp/cirrus-ci-build/share/functions/__fish_man_page.fish (line 30):
        if man "$maincmd" &>/dev/null
           ^~^
in function '__fish_man_page'
�

[I] prompt 9>echo TEXT
[I] prompt 9>echo TEXThrAi
[I] prompt 9>echo TEXThrAi
TEXThrAi
```

Yes, this detected escape, waiting *300ms* and then "h" as being below
the escape timeout of 120ms.
2022-12-23 12:18:20 +01:00
Fabian Boehm
3932559409 Fix tests
I always forget that littlecheck escapes these
2022-12-22 17:34:10 +01:00
Fabian Boehm
3005adebd5 Revert "Remove print_hints from builtin_missing_argument and builtin_unknown_option"
Unfortunately print_hints was true *by default* - so for all builtins
that didn't pass it it would now be false instead.

This resulted in the trailer missing, which includes the line number
and context. So if you ran a script that includes `bind -M` the error
message would now just be "bind: -M: option requires an argument",
with no indication as to where.

This reverts commit 8a50d47a46.
2022-12-22 17:24:47 +01:00
Fabian Boehm
bb98cb01c7 abbr: Also show --position
(if not the default)
2022-12-14 18:06:24 +01:00
Fabian Boehm
30a37d9433 abbr: Make show output actually work
This would print

```
abbr -a -- dotdot --regex ^\\.\\.+\$ --function multicd
```

which expands "dotdot" to "--regex ^\\.\\.+\$...".

Instead, we move the name to right before the replacement, and move
the `--` before that:

```
abbr -a --regex ^\\.\\.+\$ --function -- dotdot multicd
```

It might be possible to improve that, but this at least round-trips.
2022-12-13 19:38:58 +01:00
Johannes Altmanninger
9790907ca8 abbr: stop parsing option after first expansion token
Historical behavior is to stop option parsing at the first non-option argument.
Since we have added more options, it seemed impractical to keep that behavior.

However people are using options in their abbr expansions ("abbr e emacs
-nw").  To support this, we ignore options. However, we only ignore them
if they are not valid "abbr" options.  Let's ignore all options in the
expansion definition, which is a small price to pay to keep most existing
configurations working.

Fixes #9410

This does not fix other cases which used to work, like

    abbr x -unknown

Those are hopefully not used by anyone, so I don't think we need to maintain
support for that.
2022-12-13 01:39:31 +01:00
ridiculousfish
d8dbb9b259 Switch abbreviation '-r' flag from --rename to --regex
This will be the more common option and provides consistency with
`string`.
2022-12-10 16:21:39 -08:00
ridiculousfish
e08f4db1f9 Rename abbreviation cursor "sentinel" to "marker"
Also default the marker to '%'. So you may write:

    abbr -a L --position anywhere --set-cursor "% | less"

or set an explicit marker:

   abbr -a L --position anywhere --set-cursor=! "! | less"
2022-12-10 16:15:03 -08:00
ridiculousfish
01039537b0 Remove abbreviation triggers
Per code review, this does not add enough value to introduce now.
Leaving the feature in history should want want to revisit this
in the future.
2022-12-10 16:15:00 -08:00
ridiculousfish
35a4688650 Rename abbreviation triggers
This renames abbreviation triggers from `--trigger-on entry` and
`--trigger-on exec` to `--on-space` and `--on-enter`. These names are less
precise, as abbreviations trigger on any character that terminates a word
or any key binding that triggers exec, but they're also more human friendly
and that's a better tradeoff.
2022-12-10 15:38:50 -08:00
ridiculousfish
5841e9f712 Remove '--quiet' feature of abbreviations
Per code review, this is too risky to introduce now. Leaving the feature
in history should want want to revisit this in the future.
2022-12-10 15:38:50 -08:00
ridiculousfish
c51a1f1f60 Implement trigger-on for abbreviations
trigger-on enables abbreviations to trigger only on "entry" (anything
which closes a token, like space) or only on "exec" (typically enter key).
2022-12-10 15:38:50 -08:00
ridiculousfish
7118cb1ae1 Implement set-cursor for abbreviations
set-cursor enables abbreviations to specify the cursor location after
expansion, by passing in a string which is expected to be found in the
expansion. For example you may create an abbreviation like `L!`:

    abbr L! --position anywhere --set-cursor ! "! | less"

and the cursor will be positioned where the "!" is after expansion, with
the "| less" appearing to its right.
2022-12-10 15:38:50 -08:00
ridiculousfish
1d205d0bbd Reimplement abbreviation expansion to support quiet abbreviations
This reimplements abbreviation to support quiet abbreviations. Quiet
abbreviations expand "in secret" before execution.
2022-12-10 15:38:46 -08:00
ridiculousfish
8135c52c13 Abbreviations to support functions
This adds support for the `--function` option of abbreviations, so that the
expansion of an abbreviation may be generated dynamically via a fish
function.
2022-12-10 15:29:04 -08:00
ridiculousfish
d15855d3e3 Abbreviations to support matching via regex
This adds the --regex option to abbreviations, allowing them to match a
pattern of tokens.
2022-12-10 15:29:04 -08:00
ridiculousfish
1402bae7f4 Re-implement abbreviations as a built-in
Prior to this change, abbreviations were stored as fish variables, often
universal. However we intend to add additional features to abbreviations
which would be very awkward to shoe-horn into variables.

Re-implement abbreviations using a builtin, managing them internally.

Existing abbreviations stored in universal variables are still imported,
for compatibility. However new abbreviations will need to be added to a
function. A follow-up commit will add it.

Now that abbr is a built-in, remove the abbr function; but leave the
abbr.fish file so that stale files from past installs do not override
the abbr builtin.
2022-12-10 15:29:03 -08:00
ridiculousfish
635cc3ee8d Add interactive tests for abbreviations 2022-12-10 15:28:48 -08:00
ridiculousfish
5523eb36db Switch functions tests from abbr to vared
abbr was a random function that was tested by this check, but we no
longer have an abbr function so switch to a new one.
2022-12-10 12:24:43 -08:00
Johannes Altmanninger
892a820672 Make sure that cd to a relative CDPATH results in absolute $PWD
We have had multiple crashes for relative CDPATH entries.  Commit 5e274066e
(Always return absolute path in path_get_cdpath, 2019-10-17) tried to fix
all of them but it failed to do justice to its title.  Let's fix this to
actually return absolute paths, always.  Take care to to normalize the path
because it is used for autosuggestions. The normalization is mostly relevant
for CDPATH=. (the default) but it doesn't hurt others.

Closes #9407
2022-12-10 11:06:54 +01:00
ridiculousfish
4159b2a33b Disable shebangless script tests in CI with sanitizers
Sanitizers inject a busted posix_spawn interceptor which mishandles
shebangless scripts. Disable this test under sanitizers.
2022-12-02 17:32:52 -08:00
Fabian Boehm
b8424e425f fixup! 2
That'll teach me
2022-11-15 19:05:18 +01:00
Fabian Boehm
cb48ab882c fixup! 2022-11-15 19:03:06 +01:00
Fabian Boehm
0f8b9699a1 Fix error for {$}
Fixes #9337
2022-11-15 19:02:30 +01:00
ridiculousfish
e9fde96d9c Fix the commandline test
This was tripping over < > redirections.
2022-11-12 14:25:47 -08:00
Johannes Altmanninger
c4a60feff1 Stop attempting to complete inside comments
Inside a comment we offer plain file completions (or command completions if
the comment is in command position). However these completions are broken
because they don't consider any of the surrounding characters. For example
with a command line

    echo # comment
              ^ cursor

we suggest file completions and insert them as

    echo # comsomefile ment

Providing completions inside comments does not seem useful and it can be
misleading. Let's remove the completions; this should communicate better that
we are in a free-form comment that's not subject to fish syntax.

Closes #9320
2022-11-12 22:37:27 +01:00
Johannes Altmanninger
c6e1704f00 pexpect test for commandline --current-process
It was not clear to me hwo this behaves when there are comments.

Include a friendly helper to compute control characters.
No functional change.
2022-11-12 22:34:31 +01:00
Aaron Gyes
e38c9bb062 builtin set --show: put read-only part on same line. 2022-11-12 06:21:36 -08:00
Aaron Gyes
1a0d6ebe59 builtins/printf: use wcsto[i,u]max, check EINVAL, add test
This fixes #9321

IEEE Std 1003.1-2017 Issue 6 added optional error condition
[EINVAL] for if no conversion could be performed.

Switch back to wcstoimax/wcstoumax: do not work around the old FreeBSD
8 issue.

Add a test for printf '%d %d' 1 2 3
2022-10-31 19:58:18 -07:00
Mahmoud Al-Qudsi
8168ed7bf6 Test complete builtin sort of (sorted + unsorted) completions
Like the pexpect-based pager compeltions test `complete-group-order.py`, but for
the `complete` builtin. Verifies the same sort/dedup rules that apply to the
pager are also applied to the output of `complete` and asserts the sort behavior
for multiple `complete -k` calls for the same command and with the same (or with
both passing) preconditions.
2022-10-31 16:52:44 -05:00
Mahmoud Al-Qudsi
4cb19e244b Sort and deduplicate output of complete -C
This addresses a long-standing TODO where `complete -C` output isn't
deduplicated.

With this patch, the same deduplication and sort procedure that is run on actual
pager completions is also executed for `complete -C` completions (with a `-C`
payload specified).

This makes it possible to use `complete -C` to test what completions will
actually be generated by the completions pager instead of it displaying
something completely divorced from reality, improving the productivity of fish
completions developers.

Note that completions that wouldn't be shown in the pager are also omitted from
the results, e.g. `test/buildroot/` and `test/fish_expand_test/` are omitted
from the check matches in `checks/complete_directories.fish` because even if
they were generated, the pager wouldn't have shown them. This again makes
reasoning about and debugging completions much easier and more sane.
2022-10-31 16:52:36 -05:00
Fabian Boehm
8d7662335e function: Don't list empty function names and directories 2022-10-29 10:24:42 +02:00
Aaron Gyes
92698dff48 Unallowed command subst error: add missing newline and simplify
Fixes ommitted newline char shown after complete -n'(foo)'
Also axes the 'contains syntax errors' line before the error.
Update tests

before
> complete -n'(foo)'
complete: Condition '(foo)' contained a syntax error
complete: Command substitutions not allowed⏎

after
> complete -n'(foo)'
complete: -n '(foo)': command substitutions not allowed here
2022-10-26 19:58:40 -07:00
Mahmoud Al-Qudsi
06d9708d40 Add complete -k group order test
Ensure that multiple `-k` completions intermixed with one or more non-`-k`
completions are produced in the expected order with the order of all completions
in a single `-k` completion respected, non-`-k` completions correctly sorted and
interspersed, and the results of multiple `-k` completions in the
reverse-intuitive order (with chronologically later completions coming before
chronologically earlier `-k` counterparts), as per #9221.
2022-10-26 13:22:45 -05:00
Mahmoud Al-Qudsi
125bcb8289 Add pexpect test for status current-commandline 2022-10-26 12:15:02 -05:00
Mahmoud Al-Qudsi
2c870b305d Add eval recursion overflow regression test
This particular variant must be executed as a pexpect test since it relies on
the interactive-only `$history` to trigger the recursion. Note that recursion is
possible via other means (e.g. reading/writing a file), the usage of history
here is just one such example.
2022-10-25 13:40:21 -05:00
Mahmoud Al-Qudsi
3913b28153 Only retry failed pexpect tests under CI
A false negative while testing locally should be a rare thing, and individual
pexpect tests already take too long in case of a non-match making for a painful
edit-test loop.
2022-10-25 13:40:21 -05:00
Mahmoud Al-Qudsi
21599a49ea Make CALL_STACK_LIMIT_EXCEEDED_ERR_MSG more generic
We're now using this when a stack overflow is detected during eval/substitution
loops, too.
2022-10-25 13:40:21 -05:00
Mahmoud Al-Qudsi
07fc04465f Add regression test for trap -p 2022-10-24 15:36:02 -05:00
ridiculousfish
74fd66fcbe Use -- before seq for negative numbers
busybox seq was complaining about the command:

    seq -550 -1

because it was trying to interpret -550 as a flag. Use -- to prevent
this.
2022-10-23 13:53:36 -07:00
Fabian Boehm
8c362c89b5
git prompt: Interpret values of "1", "yes" or "true" as true for bools instead of relying on defined-or-not (#9274)
This allows explicitly turning these settings off by setting the variable to e.g. 0.

See #7120
2022-10-21 20:22:20 +02:00
Mahmoud Al-Qudsi
fb7f2d97e9 Add tests for erasing from multiple scopes 2022-10-20 11:21:05 -05:00
Fabian Boehm
52dcfe11af Make \x the same as \X
Up to now, in normal locales \x was essentially the same as \X, except
that it errored if given a value > 0x7f.

That's kind of annoying and useless.

A subtle change is that `\xHH` now represents the character (if any)
encoded by the byte value "HH", so even for values <= 0x7f if that's
not the same as the ASCII value we would diverge.

I do not believe anyone has ever run fish on a system where that
distinction matters. It isn't a thing for UTF-8, it isn't a thing for
ASCII, it isn't a thing for UTF-16, it isn't a thing for any extended
ASCII scheme - ISO8859-X, it isn't a thing for SHIFT-JIS.

I am reasonably certain we are making that same assumption in other
places.

Fixes #1352
2022-10-09 15:24:01 +02:00
Fabian Boehm
396e276286 Decode multibyte escapes immediately
We forgot to decode (i.e. turn into nice wchar_t codepoints)
"byte_literal" escape sequences. This meant that e.g.

```fish
string match ö \Xc3\Xb6

math 5 \X2b 5
```

didn't work, but `math 5 \x2b 5` did, and would print the wonderful
error:

```
math: Error: Missing operator
'5 + 5'
   ^
```

So, instead, we decode eagerly.
2022-10-05 18:55:01 +02:00
Fabian Boehm
dcf52dbba5 fix path --null-out
Regression from 7bc4c9674b.

Appending `"\0"` to an std::string does nothing.

I blame C++.
2022-10-05 17:25:00 +02:00
Fabian Boehm
cb28b39b24 string shorten: Make max of 0 mean no shortening
This makes it easier to just slot in `string shorten` wherever,
without having to do a weird "if test $max -gt 0" check.
2022-10-04 18:44:21 +02:00
Mahmoud Al-Qudsi
3ebfba7f5b Test return builtin doesn't map negative numbers to zero
Prior to 1811a2d, the return value for negative return codes was UB and I'd
witnessed both expected cases like -256 mapping to a $status of 0 and unexpected
cases like a return value of -1 mapping to a $status of 0. As such, this doesn't
test just one fixed return value but the entire range from negative multiples of
256 all the way down (rather, up!) to -1.
2022-09-25 12:37:10 -05:00
Mahmoud Al-Qudsi
e9908d7d41 Clean up more mktemp usage residue
...for improved cross-platform support.

Following up on the work in c90ac7b. There was one more test that had mktemp in
the littlecheck "shebang" and this also removes a now-unnecessary `env` prefix.
2022-09-23 11:05:58 -05:00
Mahmoud Al-Qudsi
c90ac7bf7f Fix tests on macOS 10.10
All usages of `mktemp` must go through the (fish-only) `mktemp` test function
that abstracts over the differences across multiple platforms/flavors.

Tests can be easily run individually via `ninja -C build test_xxx` and there
isn't a good reason to randomly manually override $HOME and $XDG_CONFIG_HOME for
a test here and a test there.

If it's absolutely necessary, littlecheck.py should be extended to support a
`%temp` variable initialized to a temporary directory and that can be used
instead of calling out to the platform-provided `mktemp` via a subshell.
2022-09-22 17:39:28 -05:00
Fabian Boehm
88e578a9ed Remove superfluous CHECK lines
Oops
2022-09-21 18:37:38 +02:00
Fabian Boehm
3dded49b9b tests/checks/test: Attempt to fix on old Ubuntu
For unknown reasons, the i686 launchpad builders fail on this date,
but apparently not the others.

Let's just remove it, we've tested dates older than the epoch, this is
slightly redundant.
2022-09-21 18:20:05 +02:00
Mahmoud Al-Qudsi
ed67f2d221 Drop a now-incorrect check test from checks/git.fish
As discussed in #9221, a bug in the autocomplete that was fixed in 66391922
caused completions to be incorrectly suppressed. The dropped test/check was
inadvertently relying on the buggy behavior and expected a git invocation to
generate no completions but there are, in fact, completions now that the bug has
been resolved.

cc @faho: I'm not sure if you want to replace this with a different check that
actually doesn't yield any completions or if you're happy with it just being
dropped.
2022-09-20 21:56:54 -05:00
Fabian Boehm
4ffcbe3526 tests/path: Allow a little slack
This was 86400 on some systems but 82800 on mine. I think that's a
timezone thing?
2022-09-20 16:17:32 +02:00
Fabian Boehm
9493e7725f tests/test: Don't use seconds in the mtime
This fails on old Ubuntu with:

> touch: invalid date format ‘190112112040.39’

Because we don't actually need the seconds here, we just use minute
resolution. It's fine.

Also use `path mtime`, because that's a portable way to get the mtime.
2022-09-20 16:10:17 +02:00
Fabian Boehm
8b1da4b63d path: Actually use mtime instead of ctime
Fixes #9222
2022-09-20 16:10:17 +02:00
Mahmoud Al-Qudsi
472fc3ec10 [tests] Fix pre-epoch test workaround on non-Linux
I forgot `stat` is non-portable. There's no great way to portably get a
machine-readable representation of stat(2) for a file. I don't want to ship our
own lstat(2) wrapper executable just for this test and don't want to fork out to
python or perl for this either - I just wanted to get the tests to pass under
WSL :'(

Anyway, just give up and make it skip just for WSL. If another OS fails this
test in the future, the comments and existing workaround will make it easy to
figure out what the problem is and what needs to be done. We'll cross that
bridge when we get there.
2022-09-16 19:38:49 -05:00
Mahmoud Al-Qudsi
613ecfc7e4 Fix pre-epoch test workaround
It turns out that not all systems print an unsigned integer as the output of
`stat -c %Y xxx` and the leading `-` can be misinterpreted as a parameter to
`string match`.
2022-09-16 18:58:21 -05:00
Mahmoud Al-Qudsi
f97650bf9a Fix stale references to getch() 2022-09-16 18:26:49 -05:00
Mahmoud Al-Qudsi
f1266dd8f5 [tests] Add count to "Wacky Handler" text
This makes it easier to figure out where the failure is taking place when the
output mismatches and the contents of the buffer are printed.
2022-09-16 18:26:49 -05:00
Mahmoud Al-Qudsi
32f7f5bd32 [tests] Increase tmux-sleep duration when not under CI
The tmux-complete test would regularly fail for me under WSL (AMD TR 1950X)
without this small increase in sleep time.
2022-09-16 18:26:49 -05:00
Mahmoud Al-Qudsi
30cd330b98 Fix test.fish pre-epoch comparisons on WSL and others
There's no guarantee (nor requirement) that the filesystem support pre-epoch
modification dates. If it doesn't, the `test` tests were failing to get the
expected results.

Skip the test if it seems the fs doesn't support pre-epoch timestamps
(determined by pre-epoch mt of `oldest` evaluating to 0 or the unix epoch).
2022-09-16 16:24:00 -05:00
Mahmoud Al-Qudsi
d2f6c925e1 Add checks for incomplete escape sequences
Also codify in tests the current, case-sensitive behavior of \C vs \c
2022-09-16 15:44:33 -05:00
Maxime Bouillot
d50e9ffff3
Add the possibility to ignore arguments in alliases (#9199)
* Replace ";" with "\n" in alias-generated functions

This can let us add a "#" in our aliases to make
them ignore additional arguments.

* Update changelog about aliases that ignore arguments

* Update test for alias.fish

This is now compliant with the aliases that can
ignore arguments.
2022-09-11 09:55:11 +02:00
ridiculousfish
5cf0778207 Claim the tty unconditionally in reader_data_t::readline
When fish runs with job control enabled, it transfers ownership of the
tty to a child process, and then reclaims the tty after the process
exits. If job control is disabled then fish does not transfer or reclaim
the tty.

It may happen that the child process creates a pgroup and then transfers
the tty to it. In that case fish will not attempt to reclaim the tty, as
fish did not transfer it. Then when fish reads from stdin it will
receive SIGTTIN instead of data.

Fix this by unconditionally claiming the tty in readline().

Fixes #9181
2022-09-09 13:43:29 -07:00
Fabian Boehm
bc1a5ba033 Test division by zero with min
This would actually return any finite argument before!
2022-09-09 18:52:45 +02:00
Fabian Boehm
24fd26ae6e Fix error for vararg functions with zero arguments 2022-09-09 18:52:45 +02:00
Fabian Boehm
c284c4ca99 Add length also for too-many/few-args error 2022-09-09 18:52:45 +02:00
Fabian Boehm
a3ee7da812 math: Add length to missing operator error 2022-09-09 18:52:45 +02:00
Fabian Boehm
52e065e479 math: Add error length
Like we now do for syntax errors, this marks the extent of the error.

Currently for unknown functions only, would be cool for division too
2022-09-09 18:52:45 +02:00
Fabian Boehm
5edba044a3 math: Give a proper error for division by zero
This errored out *later* because the result was infinite or NaN, but
it didn't actually stop evaluation.

I'm not sure if there is a way to get floating point math to turn an
infinity back into something that doesn't depend on a literal
infinity, but division by zero conceptually isn't a thing we can
support.

There's entire branches of maths dedicated to figuring out what
dividing by "basically zero" means and we don't have to get into it.
2022-09-09 18:52:45 +02:00
Fabian Boehm
41c22d5e60 Add string shorten
This is essentially the inverse of `string pad`.
Where that adds characters to get up to the specified width,
this adds an ellipsis to a string if it goes over a specific maximum width.
The char can be given, but defaults to our ellipsis string.
("…" if the locale can handle it and "..." otherwise)

If the ellipsis string is empty, it just truncates.

For arguments given via argv, it goes line-by-line,
because otherwise length makes no sense.

If "--no-newline" is given, it adds an ellipsis instead and removes all subsequent lines.

Like pad and `length --visible`, it goes by visible width,
skipping recognized escape sequences, as those have no influence on width.

The default target width is the shortest of the given widths that is non-zero.

If the ellipsis is already wider than the target width,
we truncate instead. This is safer overall, so we don't e.g. move into a new line.
This is especially important given our default ellipsis might be width 3.
2022-09-09 18:49:57 +02:00
Johannes Altmanninger
3b30d92b62 Commit transient edit when closing pager
When selecting items in the pager, only the latest of those items is kept
in the edit history, as so-called transient edit.  Each new transient edit
evicts any old transient edit (via undo).

If the pager is closed by a command that performs another transient edit
(like history-token-search-backward) we thus inadvertently undo (= remove)
the token inserted by the pager.  Fix this by closing a transient edit
session when closing the pager.  Token search will start its own session.

Fixes #9160
2022-08-31 07:49:49 +02:00
Fabian Boehm
9e9c73e46a tests/signals.py: Kill leftover sleeps from python
This starts two sleep processes and expects them to be killed on
SIGHUP.

Unfortunately, if this ever fails the second run will also fail
because it'll see the old sleep still lying around (because it'll run
for 130 seconds).

So, what we do is:

1. Keep the pids for these specific sleeps
2. Check if any of them are still running (and only fail for them)
3. Kill them from python

Fixes #9152
2022-08-23 18:47:52 +02:00
Fabian Boehm
40733ca25b If relative path was used, use it
This was inadvertently changed in
ed78fd2a5f

Fixes #9143
2022-08-15 20:01:50 +02:00
Fabian Boehm
8d7416048d Don't skip caret for some errors
This checked specifically for "| and" and "a=b" and then just gave the
error without a caret at all.

E.g. for a /tmp/broken.fish that contains

```fish
echo foo

echo foo | and cat
```

This would print:

```
/tmp/broken.fish (line 3): The 'and' command can not be used in a pipeline
warning: Error while reading file /tmp/broken.fish
```

without any indication other than the line number as to the location
of the error.

Now we do

```
/tmp/broken.fish (line 3): The 'and' command can not be used in a pipeline
echo foo | and cat
           ^~^
warning: Error while reading file /tmp/broken.fish
```

Another nice one:

```
fish --no-config -c 'echo notprinted; echo foo; a=b'
```

failed to give the error message!

(Note: Is it really a "warning" if we failed to read the one file we
wer told to?)

We should check if we should either centralize these error messages
completely, or always pass them and remove this "code" system, because
it's only used in some cases.
2022-08-12 18:38:47 +02:00
Fabian Boehm
232ca25ff9 Add length to the parse_util syntax errors 2022-08-12 18:38:47 +02:00
Fabian Boehm
4b921cbc08 Clamp error carets to the end instead of refusing to print
This skipped printing a "^" line if the start or length of the error
was longer than the source.

That seems like the correc thing at first glance, however it means
that the caret line isn't skipped *if the file goes on*.

So, for example

```fish
echo "$abc["
```

by itself, in a file or via `fish -c`, would not print an error, but

```fish
echo "$abc["
true
```

would. That's not a great way to print errors.

So instead we just.. imagine the start was at most at the end.

The underlying issue why `echo "$abc["` causes this is that `wcstol`
didn't move the end pointer for the index value (because there is no
number there). I'd fix this, but apparently some of
our recursive variable calls absolutely rely on this position value.
2022-08-12 18:38:47 +02:00
Fabian Boehm
c3fb927c9a Add more tests
These were correct, but littlecheck escapes quotes!
2022-08-12 18:38:47 +02:00
Fabian Boehm
c1bf06d5b1 Print "^^" for a 2-wide error 2022-08-12 18:38:47 +02:00
Fabian Boehm
eaf92918e6 Fix error offset for command (foo)
This used the decorated statement offset when the expansion errors
refer to the command without decoration.
2022-08-12 18:38:47 +02:00
Fabian Boehm
a4fd3c194e Pass location of the *command* node without decorators
Fixes error location for unknown commands
2022-08-12 18:38:47 +02:00
Fabian Boehm
150409eabd Add acceptable errors to tests 2022-08-12 18:38:47 +02:00
Fabian Boehm
b2eea4b46f complete: Don't load completions if command isn't in $PATH
This stops us from loading the completions for e.g. `./foo` if there
is no `foo` in path.

This is because the completion scripts will call an unqualified `foo`,
and then error out.

This of course means if the script would work because it never calls
the command, we still don't load it.

Pathed completions via `complete --path` should be unaffected because
they aren't autoloaded anyway.

Workaround for #3117
Fixes #9133
2022-08-11 17:05:32 +02:00
Fabian Boehm
2191faf17e Fix tests
Turns out we checked one of the descriptions I had adjusted. Oops!
2022-08-10 18:02:12 +02:00
Fabian Boehm
37f7818bbb printf: Ignore any options
This was misguidedly "fixed" in
9e08609f85, which made printf error out
with any "-"-prefixed words as the first argument.

Note: This means currently `printf --help` doesn't print the help.
This also matches `echo`, and we currently don't have anything to make
a literal `--help` execute a builtin help except for keywords. Oh well.

Fixes #9132
2022-08-10 16:55:56 +02:00
Fabian Boehm
b89249de98 Reset the read byte limit to the default when unset
This used to be kept, so e.g. testing it with

    fish_read_limit=5 echo (string repeat -n 10 a)

would cause the prompt and such to error as well.

Also there was no good way to get back to the default value
afterwards.
2022-08-09 19:59:10 +02:00
Fabian Boehm
eac808a819
string repeat: Don't allocate repeated string all at once (#9124)
* string repeat: Don't allocate repeated string all at once

This used to allocate one string and fill it with the necessary
repetitions, which could be a very very large string.

Now, it instead uses one buffer and fills it to a chunk size,
and then writes that.

This fixes:

1. We no longer crash with too large max/count values. Before they
caused a bad_alloc because we tried to fill all RAM.
2. We no longer fill all RAM if given a big-but-not-too-big value. You
could've caused fish to eat *most* of your RAM here.
3. It can start writing almost immediately, instead of waiting
potentially minutes to start.

Performance is about the same to slightly faster overall.
2022-08-09 19:58:56 +02:00
Johannes Altmanninger
095c093af6 Fix "commandline --paging-mode" false negative when there is no room for pager, attempt 2
The previous fix was reverted because it broke another scenario.  Add tests
for both scenarios.

The first test exposes another problem: autosuggestions are sometimes not
recomputed after selecting the first completion with Tab Tab. Fix that too.
2022-07-31 07:14:56 +02:00
ridiculousfish
2410e27d10 Add a test and CHANGELOG fix for #9096 2022-07-30 10:14:19 -07:00
Michael Forster
6003edfb42 Add test for the default cursor selection mode
Also add documentation for the tests
2022-07-30 09:49:07 -07:00
Michael Forster
ef9994d55a Don't use Python f-strings in tests 2022-07-30 09:49:07 -07:00
Michael Forster
7d198fa404 Add an initial test for fish_cursor_selection_mode 2022-07-30 09:49:07 -07:00
Johannes Altmanninger
83893558f9 Make ESCAPE_NO_PRINTABLES behavior a bit less weird
Since the fix for #3892, this escaping style escapes

	\n to \\n

as well as

	\\ to \\\\
	\' to \\'

I believe these two are the only printable characters that are escaped with
ESCAPE_NO_PRINTABLES.
The rationale is probably to keep the encoding unambiguous and reversible.
However that doesn't justify escaping the single quote. Probably this was
an accident, so let's revert that part.

This has the nice effect that single quotes will no longer be escaped
when rendered in the completion pager (which is consistent with other
special characters). Try it:

    complete : -a "aaa\'\; aaaa\'\;" -f

Also this makes the error output of builtin bind consistent:

    $ bind -e --preset \;
    $ bind -e --preset \'
    $ bind \;
    bind: No binding found for sequence “;”
    $ bind \'
    bind: No binding found for sequence “'”

the last line is clearly better than the old version:

    bind: No binding found for sequence “\'”

In general, the fact that ESCAPE_NO_PRINTABLES escapes the (printable)
backslash is weird but I guess it's fine because it looks more consistent to
users, even though the result is an undocumented subset of the fish language.
2022-07-27 11:24:35 +02:00
Johannes Altmanninger
fe2f6f0c63 Fix Escape in pager not removing the inserted completion if search field was used
command_line_has_transient_edit tracks the actual command line, not the
pager search field. We accidentally reset it after modifying the search field
which causes unexpected behavior - the commandline added by the completion
pager remains even after I press Escape.
2022-07-26 15:29:52 +02:00
Fabian Boehm
ff497e25c0 tests: Rename a function
NetBSD actually has a /usr/bin/error by default, so we ended up
starting that.
2022-07-24 17:53:05 +02:00
Fabian Boehm
407a455cfd realpath: Use physical PWD
This was an inadvertent change from
cc632d6ae9.

Because we used wgetcwd directly before, we always got the "physical"
resolved $PWD.

There's an argument to be made to use the logical $PWD here as well
but I prefer not to make changes lik that in a random commit without
good reason.
2022-07-18 20:45:30 +02:00
Fabian Boehm
5dfb64b547
Add path mtime (#9057)
This can be used to print the modification time, like `stat` with some
options.

The reason is that `stat` has caused us a number of portability
headaches:

1. It's not available everywhere by default
2. The versions are quite different

For instance, with GNU stat it's `stat -c '%Y'`, with macOS it's `stat
-f %m`.

So now checking a cache file can be done just with builtins.
2022-07-18 20:39:01 +02:00
ridiculousfish
fa3ca60111 Add a tmux-sleep to tmux-history-search
This test was failing often on my local Mac; this sleep seems to make it
reliable again.
2022-07-16 17:46:12 -07:00
Aaron Gyes
77f6afa501 Add testcases for [ extensions
Some sanity checks for -ot, -nt, -ef

Try negative mtime values too, there was interesting behavior
there during development.
2022-07-16 12:40:36 -07:00
Fabian Boehm
d920610f96 Fix special readline functions after and/or
Here we needed to handle self-insert immediately, but we ended up
returning it.

Fixes #9051
2022-07-02 09:23:11 +02:00
Fabian Boehm
98ba66ed8e set_color: Print the given colors with --print-colors 2022-07-01 21:28:35 +02:00
Fabian Boehm
bd7934ccbf history: Refuse to merge in private mode
It makes *no* sense.

Fixes #9050.
2022-07-01 20:10:18 +02:00
Fabian Boehm
dde2d33098 set --show: Show the originally inherited value, if any
This adds a line to `set --show`s output like

```
$PATH: originally inherited as |/home/alfa/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/flatpak/exports/bin|
```

to help with debugging.

Note that this means keeping an additional copy of the original
environment around. At most this would be one ARG_MAX's worth, which
is about 2M.
2022-06-27 20:33:26 +02:00
Fabian Boehm
bfeebca75a tests/argparse: Use set -l
This skips history, which takes a lot of time here!
2022-06-27 17:50:40 +02:00