Commit Graph

981 Commits

Author SHA1 Message Date
ridiculousfish
7a0bddfcfa Teach string repeat to handle multiple arguments
Each argument in string repeat is handled independently, except that the
--no-newline option applies only to the last newline.

Fixes #5988
2021-01-11 17:00:06 -08:00
Fabian Homborg
1dd776ec99 echo: Don't interpret and print options
A weird interaction between grouped short options and our weird option
parsing that puts unknown options back:

```
echo "-n foo"
```

would see the `-n`, turn off printing newlines, interpret the " " as
another grouped short option, see that there is no short option for
space and put the entire token back on the arguments pile.

So it would print "-n foo" *without a newline*.

Fix this by keeping an old state of the options around and reverting
it when putting options back.

The alternative is *probably* to forbid the " " short option in
wgetopt, then check if an option group contains it and error out, but
this should only really be a problem in `echo` because that is,
AFAICT, the only thing that puts the options back.

Fixes #7614
2021-01-09 08:50:30 +01:00
Johannes Altmanninger
9f4255ed76 Add simple pexpect test for undo
This acts really strange, I haven't yet figured out why, but I guess it's
a start.
2021-01-07 23:53:31 +01:00
ridiculousfish
534bc66a43 Add a test for background procs in cmdsubs
This adds a test to ensure that if a long running background process is
launched from a command substitution, that process does not cause the
cmdsub to hang. That could easily happen if we just wait for the pipe to
close; this is verifying that we are also checking for the job to complete.
2021-01-07 11:38:52 -08:00
Johannes Altmanninger
7a53c40fd4 Allow to run individual interactive tests by setting FISH_PEXPECT_FILES
This command builds all test dependencies and runs the bind.py test:

	FISH_PEXPECT_FILES=../tests/pexpects/bind.py ninja test_interactive
2021-01-07 17:09:05 +01:00
Fabian Homborg
85ba2ed790 type: Add missing newline
Otherwise this would print

    # Defined interactivelyfunction foo

for interactively defined functions.
2021-01-03 17:48:25 +01:00
ridiculousfish
118f710e99 Allow fish_private_mode to change at runtime
Prior to this change, `fish_private_mode` worked by just suppressing
history outright. With this change, `fish_private_mode` can be toggled on
and off. Commands entered while `fish_private_mode` is set are stored but
in memory only; they are not written to disk.

Fixes #7590
Fixes #7589
2021-01-02 22:01:47 -08:00
Fabian Homborg
cf8219e3ce Exit if --no-execute is enabled don't interactively read from the terminal
Don't go into implicit interactive mode without ever executing
anything - not even `exit` or reacting to ctrl-d. That just renders
the shell useless and unquittable.
2021-01-01 21:22:52 +01:00
Fabian Homborg
164a5ebe81 tests: Remove unused colordiff function 2021-01-01 14:18:17 +01:00
Fabian Homborg
7ea8e20623
argparse: Make short flag names optional (#7585)
It was always a bit ridiculous that argparse required `X-longflag` if
that "X" short flag was never actually used anywhere.

Since the short letter is for getopt's benefit, we can hack around
this with our old friend: Unicode Private Use Areas.

We have a counter, starting at 0xE000 and going to 0xF8FF, that counts
up for all options that don't have a short flag and provides one. This
gives us up to 6400 long-only options.

6.4K should be enough for everybody.
2021-01-01 11:37:25 +01:00
Fabian Homborg
4c09012b0d tests: Don't rely on $HOME existing
Apparently the launchpad tests run with $HOME set to a nonexistent
directory. Since we just want *out*, let's just store the previous dir
and go back.
2020-12-29 12:48:11 +01:00
ridiculousfish
43505f7077 Allow ** glob segments to match zero directories
Prior to this change, a glob like `**/file.txt` would only match
`file.txt` in subdirectories; the `**` must match at least one directory.
This is historical behavior.

With this change we move a little closer to bash's implementation by
allowing a literal `**` segment to match in the current directory. That
is, `**/foo` will match both `foo` and `bar/foo`, while `b**/foo` will
only match `bar/foo`.

Fixes #7222.
2020-12-28 23:51:18 -08:00
ridiculousfish
6c08141682 Add a littlcheck glob test
We have some glob tests in fish_tests.cpp, but they are hard to follow.
Begin migrating them
2020-12-28 23:51:18 -08:00
Fabian Homborg
3c2cf6241b Add some error tests for cd
Makes work on #7577 easier.
2020-12-28 23:23:06 +01:00
Johannes Altmanninger
322ceb7ab4 builtin realpath: use absolute path also with -s/--no-symlinks
The old test needs to be changed because $XDG_DATA_HOME can be relative.

Fixes #7574
2020-12-24 08:53:08 +01:00
ridiculousfish
e43913a547 Stop expanding globs in command position when performing error checking
Before running a command, or before importing a command from bash history,
we perform error checking. As part of error checking we expand commands
including variables and globs. If the glob is very large, like `/**`, then
we could hang expanding it.

One fix would be to limit the amount of expansion from the glob, but
instead let's just not expand command globs when performing error checking.

Fixes #7407
2020-12-22 12:38:51 -08:00
ridiculousfish
36766ea3d7 Correct $status for certain pipeline-aborting failures
If we refused to launch a job because of a "pipeline aborting" error,
then it's the caller's responsibility to set $status.

Fixes #7540
2020-12-13 17:33:34 -08:00
Fabian Homborg
a57f7a8653 tests/pexpects/bind: Increase a timeout
Last attempt, if this keeps failing on CI (specifically macOS seems to
be affected), I'm removing the test as it's more noise than use.
2020-12-13 14:57:37 +01:00
Fabian Homborg
b7f47344b0 Print nicer "defined in" for functions defined on stdin/via source
This would tell you a function was "Defined in - @ line 1" for every
function defined via `source`.

Really, ideally we'd figure out where the *source* call was, but that'
much more complicated, so we just give a comprehensible message.
2020-12-11 23:09:16 +01:00
Fabian Homborg
425dabd6b1 Change fish_trace prefix to "->" instead of plusses
This matches what we do in --profile's output:

```
> source /home/alfa/.config/fish/config.fish
--> set -gx XDG_CACHE_HOME /home/alfa/.cache
--> set -gx XDG_CONFIG_HOME /home/alfa/.config
--> set -gx XDG_DATA_HOME /home/alfa/.local/share
```

instead of

```
+ source /home/alfa/.config/fish/config.fish
+++ set -gx XDG_CACHE_HOME /home/alfa/.cache
+++ set -gx XDG_CONFIG_HOME /home/alfa/.config
+++ set -gx XDG_DATA_HOME /home/alfa/.local/share
```
2020-12-11 21:24:33 +01:00
Fabian Homborg
78173cf541 tests/bind: Rationalize delays
This increases a 100ms timeout to 200ms, because we've hit it on
Github Actions:

```
 INPUT    3904.65 ms (Line 223): set -g fish_escape_delay_ms 100\n
OUTPUT      +1.74 ms (Line 224): \rprompt 25>
 INPUT      +0.71 ms (Line 230): echo abc def
 INPUT      +0.57 ms (Line 231): \x1b
 INPUT      +0.57 ms (Line 232): t\r
OUTPUT      +2.41 ms (Line 234): \r\ndef abc\r\n
OUTPUT      +1.63 ms (Line 234): \rprompt 26>
 INPUT      +0.75 ms (Line 239): echo ghi jkl
 INPUT      +0.57 ms (Line 240): \x1b
 INPUT    +134.98 ms (Line 242): t\r
```

In other places it decreases sleeps where we just wait for a timeout to elapse, in which case we don't need much longer than the timeout.
2020-12-10 16:25:57 +01:00
Fabian Homborg
ab5d7f80d0 Restyle codebase
And again clang-format does something I don't like:

-    if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0) return found;
+    if (found != end && std::strncmp(found->name, name, len) == 0 && found->name[len] == 0)
+        return found;

I *know* this is a bit of a long line. I would still quite like having
no brace-less multi-line if *ever*. Either put the body on the same
line, or add braces.

Blergh
2020-12-06 15:39:54 +01:00
Fabian Homborg
aa895645dd Add string to reserved keywords
Since `string match` now creates variables, wrapping `string`
necessarily breaks things, so we need to disallow it.

See #7459, #7509.
2020-12-06 15:39:49 +01:00
Fabian Homborg
8172ad4463 Add test for double-redirection crash
Fixes #7447
2020-12-06 14:02:08 +01:00
Fabian Homborg
02efce51a9 string match: Only import variables for the first matching argument
This makes it work the same whether it quits early (with "-q") or not,
and it's generally nice to nail this down.

See #7495.
2020-12-04 18:45:08 +01:00
Fabian Homborg
720982a3cb string: Quit early if --quiet is satisfied
E.g. if we do `string match -q`, and we find a match, nothing about
the input can change anything, so we quit early.

This is mainly useful for performance, but it also allows `string`
with `-q` to be used with infinite input (e.g. `yes`).

Alternative to #7495.
2020-12-01 18:55:01 +01:00
Johannes Altmanninger
7da93e2617 builtin functions: don't mix up multiple arguments
This regressed in 2e38cf2a which is contained in 2.6.0.

Fixes #7515
2020-11-29 06:35:02 +01:00
Fabian Homborg
5872f4522d math: Add --base option
Currently a bit limited, unfortunately printf's `%a` specifier is
absolutely unreadable.

So we add `hex` and `octal` with `0x` and `0` prefixes respectively,
and also take a number but currently only allow 16 and 8.

The output is truncated to integer, so scale values other than 0 are
invalid and 0 is implied.

The docs mention this may change.
2020-11-27 19:33:27 +01:00
ridiculousfish
a434ec0e19 Remove '--import' from regex string match tests
The '--import' flag was used for importing named capture groups, but it
was decided to always import them unconditionally. This flag was causing
the tests to fail.
2020-11-26 16:27:57 -08:00
Mahmoud Al-Qudsi
edb7897b4d Add tests for regex variable import 2020-11-26 14:41:31 -06:00
Fabian Homborg
a14e64ed6c math: Don't override errors with "unexpected token"
As always, we want to give the most specific error we can.

Fixes #7508
2020-11-26 12:41:19 +01:00
ridiculousfish
5f16a299a7 Use external mode for term when running key bindings
Prior to this fix, when key binding is a script command (i.e. not a
readline command), fish would run that key binding using fish's shell
tty modes. Switch to using the external tty modes. This re-fixes
issue #2214.
2020-11-23 19:36:39 -08:00
ridiculousfish
21e2b39fa8 Add a sleep to bind.py
With the upcoming fix to place the tty in external-proc mode, add a sleep
which resolves a race between emitting a newline and restoring it to shell
mode.
2020-11-23 19:36:39 -08:00
ridiculousfish
db514df95b Stop setting tty back to shell mode when a fg proc completes
Prior to this change, when a process resumes because it is brought back
to the foreground, we would reset the terminal attributes to shell mode.
This fixed #2114 but subtly introduced #7483.

This backs out 9fd9f70346, re-introducing #2114 and re-fixing #7483.
A followup fix will re-fix #2114; these are broken out separately for
bisecting purposes.

Fixes #7483.
2020-11-23 19:36:39 -08:00
Fabian Homborg
2e55e34544 Reformat 2020-11-22 14:39:48 +01:00
Fabian Homborg
61d322d403 Cleanup test setup a bit
Put the env setup into test_util, which does some additional work.

Also use some more builtins and stuff.
2020-11-15 09:17:23 +01:00
Fabian Homborg
78bb1a6fa6 Remove some unused functions from the test harness
This was from before `string` was a thing - `_quote` would be better
done as `string escape` and `_echo_var` would be `set --show`.
2020-11-15 09:17:23 +01:00
Fabian Homborg
e6cdd315d1 tests/generic: Check for a literal match
I *think* this might sometimes (on CI) be eating the prompt, so that the actual `prompt`
part of `expect_prompt` doesn't find anything.

On Github Actions we see things like:

```
Testing file pexpects/generic.py ... Failed to match pattern: prompt 5
generic.py:35: timeout from expect_prompt("echo .history.*")

[...]

OUTPUT      +1.08 ms (Line 31): \rprompt 4>
 INPUT      +0.35 ms (Line 34): echo $history[1]\n
OUTPUT      +1.58 ms (Line 35): echo $history[1]\r\necho $history[1]\r\n⏎                                                                              \r⏎ \r\rprompt 5>
```

so the prompt *is* printed, it's just not correctly matched.
2020-11-13 15:20:37 +01:00
Fabian Homborg
5e91e5127d Remove reference to Travis
I'm still salty about that exit.
2020-11-13 15:12:14 +01:00
Fabian Homborg
4c9d01cab0 Fix fg tests on macOS
Apparently on macOS SIGTSTP (from control-Z) causes `read()` to return
EINTR.

This means `cat | cat` will exit as soon as it's backgrounded and
brought back.

So instead we use `sleep`, which won't read(), and therefore is
impervious to these puny attacks.

See discussion in #7447.
2020-11-13 15:11:29 +01:00
Fabian Homborg
25823d2900 And another delay change
Monty Python this ain't.
2020-11-11 19:57:29 +01:00
Fabian Homborg
ae0c68ec7e Tests: Yet another delay change
Now this failed because the CI added 90ms of delay.

*sigh*
2020-11-11 19:20:55 +01:00
Fabian Homborg
eed70d719a tests: More slack
The classic mistake: Some of these have a bit of a delay, but it's supposed to
be *under* the timeout, so it needs to be *shorter* not longer to
increase the slack.
2020-11-09 19:56:53 +01:00
Fabian Homborg
a52bf1d078 tests: Use math for the prompt counter 2020-11-09 19:42:46 +01:00
Fabian Homborg
9b0bec59ae tests: Use python-level kill in job_summary tests
Also increase the `sleep` time.

This *might* help with Github Actions, I'm not entirely sure why this
is failing?
2020-11-09 19:42:19 +01:00
Fabian Homborg
fd66b66a86 tests: Retry interactive tests once
We used to have this, it helps with resource constrained CI systems
2020-11-09 19:26:27 +01:00
Fabian Homborg
2318d037ac tests: Increase timeouts even more
Wow the github actions machines are *slow*
2020-11-09 19:10:24 +01:00
Fabian Homborg
b0f338cf14 Fix error message in tests
Switching from the old debug() to flog causes a shift from

<E> fish:

to

error:

and in this one place we still test it.
2020-11-07 22:48:13 +01:00
Fabian Homborg
e73929b2c6 tests/bind: Increase another delay
I don't understand why, but somehow this waited 101ms and then acted
as if it was under 80ms?
2020-11-07 07:54:06 +01:00
Fabian Homborg
f58f2e14a3 tests/bind: Increase escape delay
We just had the following output on Github Actions:

 INPUT      +0.94 ms (Line 34): echo ghi jkl
 INPUT      +0.72 ms (Line 35): \x1b
 INPUT     +63.12 ms (Line 37): t\r

The default escape delay is 30ms, that had 60ms between an escape and
a tab, so it missed it.

So: We have to increase the delay for CI's benefit. Let's try with
80ms, because otherwise we'd have to bump up other timeouts and the
bind tests take long enough as it is.
2020-11-07 07:44:03 +01:00