Commit Graph

98 Commits

Author SHA1 Message Date
Fabian Homborg
735105e33f bind tests: One more attempt to increase the timeouts
This is the last time I'm doing this before I rip these particular
tests out.

As far as I know there is no actual *problem* here, this is just
failing through a combination of macOS and Github Actions being slow
as molasses.

So it is wasting our time and therefore worse than not having these
tests at all, especially since they very rarely fail for good reasons.

We would leave some escape delay tests intact with generous timeouts, which would provide 90%
of the coverage with 10% of the hassle.
2021-05-03 12:13:18 +02:00
Fabian Homborg
ae561c3702 bind tests: Sleep shorter, more often
We still wait 5s, but with higher resolution.

This allows that test to succeed within 100ms, instead of within 1s.
2021-05-03 11:26:41 +02:00
Fabian Homborg
d8c3d667d7 bind tests: More slack
As always, increase one escape delay and wait for a bit to enter
insert mode
2021-05-03 11:26:27 +02:00
ridiculousfish
0c79a8d3af Correct time.sleep to just sleep in bind.py
time was not imported, so this was raising an exception.
2021-05-02 11:25:33 -07:00
Fabian Homborg
202e5e53d5 Handle exit in keybindings immediately
This simply checks if the parser requested exit after running any
binding scripts (in read_normal_chars).

I think this means we no longer need the `exit` bind function.

Fixes #7967.
2021-05-02 20:27:08 +02:00
ridiculousfish
fc0dd49842 Attempt to fix the bind test on MacOS
Wait for the command line to "catch up" to what is sent.
Use expect_str rather than hard-coded delays.
Fixes #7942
2021-04-22 13:15:40 -07:00
ridiculousfish
c570a14c04 Simplify event_queue_peeker_t
Make it an ordinary struct wrapping a vector, instead of a template.
This is in preparation for using it more widely, for matching bindings
as well as mouse CSI sequences.
Also add some mouse-disabling tests.
2021-04-17 16:43:27 -07:00
Fabian Homborg
333032f626 tests: Increase how long exit_nohang tries
This runs in 100ms increments, so there's not a lot of harm in trying
longer - it should take the same time everywhere it succeeded before.

But I've reproduced failures on FreeBSD 13 on sr.ht, so there's at
least one platform where a total time of 1 second isn't enough.

Now we do 50 tries, which is 5 seconds.
2021-04-14 18:55:11 +02:00
Fabian Homborg
ef96a6614b Update termsize before a sigwinch handler
This could have been one iteration off, e.g.

```fish
function on-winch --on-signal winch
    echo $LINES
end
```

Resize the terminal, it'll print e.g.

24

then run `echo $LINES` interactively, it might have a different answer.

This isn't beautiful, but it works. A better solution might be to make
the termsize vars electric and just always update them on read?
2021-04-14 17:27:53 +02:00
ridiculousfish
ed51e2baac Prevent hanging when restoring the foreground process group at exit
When fish starts, it notices which pgroup owns the tty, and then it
restores that pgroup's tty ownership when it exits. However if fish does
not own the tty, then (on Mac at least) the tcsetpgrp call triggers a
SIGSTOP and fish will hang while trying to exit.

The first change is to ignore SIGTTOU instead of defaulting it. This
prevents the hang; however it risks re-introducing #7060.

The second change somewhat mitigates the risk of the first: only do the
restore if the initial pgroup is different than fish's pgroup. This
prevents some useless calls which might potentially steal the tty from
another process (e.g. in #7060).
2021-04-05 17:44:14 -07:00
ridiculousfish
3cb105adbd Restore terminal modes after running key bindings with external commands
This concerns the behavior when running an external command from a key
binding. The history is:

Prior to 5f16a299a7, fish would run these external commands in shell
modes. This meant that fish would pick up any tty changes from external
commands (see #2114).

After 5f16a299a7, fish would save and restore its shell modes around
these external commands. This introduced a regression where anything the
user typed while a bound external command was executing would be echoed,
because external command mode has ECHO set in c_lflag. (This can be
reproed easily with `bind -q 'sleep 1'` and then pressing q and typing).
So 5f16a299a7 was reverted in fd9355966.

This commit partially reverts fd9355966. It has it both ways: external
commands are launched with shell modes, but/and shell modes are restored
after the external command completes. This allows commands to muck with
the tty, as long as they can handle getting shell modes; but it does not
enable ECHO mode so it fixes the regression found in #7770.

Fixes #7770. Fixes #2114 (for the third time!)

This partially reverts commit fd9355966e.
2021-03-10 22:36:33 -08:00
Fabian Homborg
fd9355966e Stop donating the terminal for bind functions
Unfortunately this causes input coming in while bind functions are
running to show up on screen.

Since the cure is worse than the disease let's just stop doing it.

My guess is this needs to *only* be done while running an external
command.

Fixes #7770
Reintroduces #2114

Partially reverts 5f16a299a7
2021-03-10 21:21:19 +01:00
Fabian Homborg
a7df92e187 Fix crash with set_color --print-colors --background normal
Found in conjunction with #7805.
2021-03-09 13:46:08 +01:00
Fabian Homborg
4762d52e52 output: A background is set if it's not a special non-color
For reasons unclear to me, fish enables bold mode unconditionally if
the background is set.

However, this called a background "set" if it wasn't exactly the
"normal" color, whereas set_color --print-colors would set a color
of *none*.

We have three special non-color colors:

- "normal"
- "reset"
- "none"

All of these specify some form of absence of background color, so all
of them should be checked.

Fixes #7805
2021-03-09 13:25:00 +01:00
Fabian Homborg
459ac2b566 Reset the readline loop state when setting the buffer
Fixes #7740.
2021-02-25 16:19:28 +01:00
Fabian Homborg
b154ad6a5c pexpects/fg: Don't use sleep on NetBSD
NetBSD's sleep quits when foregrounded sometimes. I'm not entirely
sure *why*, but this is reproducible with the default /bin/sh, so it's
not our fault.

Because this fails our tests, go back to using cat *there*, because we
can't use it on macOS - 4c9d01cab0.
2021-02-24 20:02:20 +01:00
Fabian Homborg
ca4836ff0d Only enable actual flow control on Linux
This fails on FreeBSD on sr.ht and NetBSD on my own VM, but it works manually.

It also fails on macOS but I have no way to confirm.

I think it might be a problem in pexpect's platform support?

Either way, the test is valuable so just skip it there and solve it later.
2021-02-15 17:30:50 +01:00
Fabian Homborg
d6a77cc6f7 Test flow control
This is a bit of an interesting pexpect test, but honestly pexpect
works quite well! I'm happy with it!
2021-02-15 17:30:50 +01:00
Fabian Homborg
a503371c57 termsize: Default to 80x24 when the terminal says 0 again
This was lost in
6bdbe732e40c2e325aa15fcf0f28ad0dedb3a551..c7160d7cb4970c2a03df34547f357721cb5e88db.

Note that we only print a term-support flog message for now, the
warning seems a bit much.

Fixes #7709.
2021-02-12 18:25:21 +01:00
Fabian Homborg
5152838417 tests: Move fg2.py into fg.py
There's no reason for this to be a separate file.
2021-02-07 19:52:32 +01:00
Fabian Homborg
4ac9924088 tests: Deactivate that one bind test that still keeps failing
This test has never failed for me in earnest, it's only when CI is too
slow that I've ever seen it fail.

So it's a net-negative and should be removed
2021-01-26 07:07:51 +01:00
Fabian Homborg
20741007c8 tests: Increase one more timeout
Alright, maybe it's the mode switch in this case.
2021-01-22 21:49:40 +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
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
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
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
8172ad4463 Add test for double-redirection crash
Fixes #7447
2020-12-06 14:02:08 +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
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
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
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
2318d037ac tests: Increase timeouts even more
Wow the github actions machines are *slow*
2020-11-09 19:10:24 +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
Fabian Homborg
69ab68d856 tests: Increase another timeout
Github Action's macOS builds are even more resource-starved (even tho
they use the same provider?) than
Travis, but Travis is unusable to us now, so....
2020-11-06 17:56:38 +01:00
Fabian Homborg
d334dc6643 Let cancel after an unambiguous completion was accepted undo it
In some cases the completion we come up with may be unexpected, e.g.
if you have files like

/etc/realfile

and

/etc/wrongfile

and enter "/etc/gile", it will accept "wrongfile" because "g" and
"ile" are in there - it's a substring insertion match.

The underlying cause was a typo, so it should be easy to go back.

So we do a bit of magic and let "cancel" undo, but only right after a
completion was accepted via complete or complete-and-search.

That means that just reflexively pressing escape would, by default, get you back to
the old token and let you fix your mistake.

We don't do this when the completion was accepted via the pager,
because 1. there's more of a chance to see the problem there and 2.
it's harder to redo in that case.

Fixes #7433.
2020-10-30 19:37:44 +01:00
Fabian Homborg
06bd1e9347 tests: Check that ctrl-z can be bound
We've heard news of this regressing, so let's add the test that should
have been there already (mea culpa!).

Because we now use POSIX_VDISABLE, this should also work in tandem
with ctrl-space (which sends NUL), but we can't test *that* because
some systems might not have POSIX_VDISABLE.
2020-10-14 19:26:13 +02:00
ridiculousfish
e9902159c2 Send fish_cancel event on control-C again
This adds support for sending fish_cancel, and a test for it.
Fixes #7384.
2020-10-06 17:49:55 -07:00
ridiculousfish
63cf3e972f Correct parameter order of pexpect.expect_prompt
Ensure that the increment= param is set via keyword, not via positional arg.
This mistake was masking a bug where the "^a b c" match was not being tested,
because it was being set as the value for increment!
2020-10-06 16:03:06 -07:00
ridiculousfish
9e1800cb96 Rework increment param in pexpect.expect_prompt
This switches the 'increment' param from "after" to "before." Instead
of expect_prompt saying if the next prompt will be incremented, each
call site says if it should have been incremented sinec the last prompt.
2020-10-06 14:22:35 -07:00
Fabian Homborg
689e96263e tests: Add yet another sleep 2020-09-27 09:22:45 +02:00