Commit Graph

1376 Commits

Author SHA1 Message Date
ridiculousfish
0562e599a6 isolated-tmux to more reliably initialize and other fixes
Prior to this change, tmux based tests would call 'isolated-tmux' which would
initialize tmux on first call, an admitted "evil hack." Switch to requiring
an explicit call to 'isolated-tmux-start' which then defines 'isolated-tmux'
and other functions. Add some loop-until-prompt logic into
'isolated-tmux-start'. This improves reliability of the tmux tests on systems
under load; at least it makes the tests pass in the background on my Mac.

Remove the '$sleep' variable, to be replaced with 'tmux-sleep'.
2021-09-24 08:07:17 -07:00
Fabian Homborg
45714eb29d Add function scope to read as well
Fixes #8295.
2021-09-23 17:12:37 +02:00
Fabian Homborg
bb115c847e Handle backspaces for visible width
This makes it so we treat backspaces as width -1, but never go below a
0 total width when talking about *lines*, like in screen or string
length --visible.

Fixes #8277.
2021-09-23 12:58:35 +02:00
ridiculousfish
6db631ae88 Fix test driver on BSDs
FreeBSD at least has `realpath` without `--no-symlinks`, so the tests
cannot start. Fix this by  using the `pwd -P` trick.
2021-09-17 11:18:39 -07:00
Johannes Altmanninger
eae9ee7f35 builtin cd: print error about broken symlinks
When cd is passed a broken symlink, this changes the error message from
"no such directory" to "broken symbolic link".  This scenario probably
won't happen very often since completion won't suggest broken symlinks
but it can't hurt to give a good error.

Fish used to do this until 7ac5932.  This logic used to be in
path_get_cdpath, however, that is only used for highlighting, so we
don't need error messages there. Changing cd is enough.

Reword from "rotten" to "broken" since that's what file(1) uses.
Clean-up leftovers from old "rotten" code (nomen est omen).

See #8264
2021-09-17 00:43:12 +02:00
Mahmoud Al-Qudsi
93aaa1851e Merge branch 'ctest_redux'
This fixes issues building on Debian and with older versions of CMake.
See individual commits for details.
2021-09-13 23:17:14 -05:00
Fabian Homborg
a78d9d8e9a normalize_path: Squash leading slashes even without allow_leading
This currently changes builtin realpath with the "-s" option:

    builtin realpath -s ///tmp

previously would print "///tmp", now it prints "/tmp".

The only thing "allow_leading_double_slashes" does is allow *two*
slashes.

This is important for `path match`, to be introduced in #8265.
2021-09-09 18:41:11 +02:00
Mahmoud Al-Qudsi
e0476cf219 Hack around CMake < 3.9 reporting skipped tests as failed 2021-09-07 12:04:05 -05:00
Mahmoud Al-Qudsi
9151acc498 Split test_driver.sh into test_env.sh + test_driver.sh
This lets us run non-fish targets (such as `fish_tests`) under a clean
test environment without running into the fish-specific payload
configuration now carried out by `test_driver.sh` which expects a
`.fish` payload that it will run under a deterministically configured
instance of fish, running in an environment initialized by
`test_env.sh`.

This should fix the problem with in-tree builds leaving detritus behind
after a `make test` when `fish_tests` would be executed without
`test_driver.sh` - it is now executed under `test_env.sh` instead.
2021-09-07 11:33:56 -05:00
ridiculousfish
5eb5aaf9da tmux-prompt test to wait a bit to allow the first prompt to draw
The tmux-prompt test would sometimes fail because the first call was:

     isolated-tmux capture-pane -p

this would run a capture-pane which would race with starting fish
itself; occasionally the pane would be empty since fish has not yet
drawn a prompt. Add a loop to give fish time to draw the prompt.
2021-09-04 16:59:50 -07:00
ridiculousfish
9070ed8039 Correct the order of pkill arguments
On macOS, the tests would often fail because calls to `pkill` would "leak"
across tests: kill processes run by other tests. This is because on macOS,
the -P argument to pkill must come before the process name. On Linux it
doesn't matter.

This improves test reliability on Mac.
2021-09-04 13:34:52 -07:00
Fabian Homborg
23e6698dc8 cmake: Force color in the tests
For littlecheck/pexpect this just unconditionally enables color.

I have no idea what happens if you run cmake outside of a terminal
, but the worst that can happen is that *errors* have color
escapes in them.

If someone figures out how to get cmake to tell us if it's running in
a terminal, we can add a check.
2021-08-30 17:16:19 +02:00
Fabian Homborg
aa17ed51ce tests/checks/complete: Do $PWD stuff in the tempdir
This broke the tests on my machine, and doing

```fish
cd $dir
cd -
```

seems wrong in any case.
2021-08-30 17:07:11 +02:00
Fabian Homborg
d62e22dcc0 Correct a realpath test
This used the *logical* $PWD, but realpath would operate on the
physical $PWD if given ".", even with -s. This makes this test fail if the $PWD is
logically different from physical.
2021-08-29 23:10:50 +02:00
Johannes Altmanninger
77c434bc42 Extract setup and teardown for tmux tests
This was long overdue since the setup logic is much more complex than
the actual tests.

tmux-prompt.fish had extra logic to protect against XDG_CONFIG_HOME
with leading double double-dot.  I believe this is no longer necessary
with the new test driver.

We still use our own temp dir because we want to be able to run this
independently of the test driver, This can be useful for debugging
tests.  For example we can insert a "$tmux attach" command in a test,
and then run

	build/fish -C 'source tests/test_functions/isolated-tmux.fish' tests/checks/tmux-bind.fish

This allows to inspect the state of the test and debug interactively.
Attaching to the terminal doesn't work when running inside littlecheck
because littlecheck consumes our output and doesn't give us a terminal.
(Maybe there's an easy way to fix that?)
2021-08-29 20:22:16 +02:00
Johannes Altmanninger
bd79e753ff Fix detection of zombies in test
Due to the second column the old glob no longer worked.
2021-08-29 20:22:16 +02:00
Mahmoud Al-Qudsi
069d396ebc Merge branch 'ctest' 2021-08-29 13:03:16 -05:00
Mahmoud Al-Qudsi
9a071090dc Allow tests/checks/basic.fish to run without test driver
On request of a team member, this patches `basic.fish` to no longer
depend on being invoked by the test driver and started up in a $PWD that
points to a clean temporary directory.
2021-08-29 12:53:37 -05:00
Mahmoud Al-Qudsi
2157d91a5c Re-add explicit littlecheck HOME/XDG_CONFIG_HOME overrides on request
This was requested by a team member who would like for some tests to
remain invokable (in thier own $HOME) directly via littlecheck without
relying on the test driver to prep the environment.

A comment explaining the rationale is also added so this doesn't get
passed down as folklore "you need to include this for tests to run" even
though no one understands why.
2021-08-29 12:38:28 -05:00
Mahmoud Al-Qudsi
c52f372a8c Fix test function mktemp to avoid false errors
If called within a temporary directory that had an X in the path, it
would fail. This caused sporadic CI test failures.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
e96b6e157c Remove TMPDIR dependency from tests/
Tests are now executed in a test-specific temporary directory, so test
output on failure should be reproducible/reusable as-is without needing
to have TMPDIR defined (as it only exists by default under macOS).
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
1f4d16cb07 Add support for bubbling up skipped tests to cmake
This prevents tests that were skipped (e.g. because of a missing
REQUIRES) from being reported as successes in the CTest overall run
results list.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
ef00344c0e Fix tmux tests error on macOS w/ long TMPDIR 2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
efda4f5c39 Make zombie test smarter
Instead of trying to assert that there are no zombies when the test
starts (which often fails) and to prevent conflating existing or
irrelevant zombies with the ones we are interested in checking for,
have `ps` also emit the parent process id and filter its output to
include only children of the current fish instance.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
9796b95f48 Eliminate shared temporary directory for tests
Aside from the fact that the shared state could cause problems, tests
were randomly assuming it would be created where that wasn't the case.
In particular, `redirect.fish` and `basic.fish` were failing on only
macOS because `../test/temp` didn't exist yet - it would be created by
other tests later.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
c35113aef1 Remove now-extraneous re-init of XDG dirs in tests
test_driver.sh is guaranteed to take care of them.
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
77b332221a Fix complete.fish test
It depends on `mktemp -d TAG` returning a relative path, which isn't guaranteed to be the case (and
isn't the case when run by our test driver).
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
04a3065d73 Fix mktemp -d under macOS 10.10 2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
2962fbcf7a Add pexpect tests to new test driver 2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
aaac759d9a Make test a custom target again and add top-level test targets
Even though we are using CMake's ctest for testing, we still define our
own `make test` target rather than use its default for many reasons:

 * CMake doesn't run tests in-proc or even add each tests as an
   individual node in the ninja dependency tree, instead it just bundles
   all tests into a target called `test` that always just shells out to
   `ctest`, so there are no build-related benefits to not doing that
   ourselves.
 * CMake devs insist that it is appropriate for `make test` to never
   depend on `make all`, i.e. running `make test` does not require any
   of the binaries to be built before testing.
 * The only way to have a test depend on a binary is to add a fake test
   with a name like "build_fish" that executes CMake recursively to
   build the `fish` target.
 * It is not possible to set top-level CTest options/settings such as
   CTEST_PARALLEL_LEVEL from within the CMake configuration file.
 * Circling back to the point about individual tests not being actual
   Makefile targets, CMake does not offer any way to execute a named
   test via the `make`/`ninja`/whatever interface; the only way to
   manually invoke test `foo` is to to manually run `ctest` and specify
   a regex matching `foo` as an argument, e.g. `ctest -R ^foo$`... which
   is really crazy.

With this patch, it is now possible to execute any single test by name,
by invoking the build directly, e.g. to run the `universal.fish` check:
`cmake --build build --target universal.fish` or
`ninja -C build universal.fish`. Unfortunately, this is not integrated
into the Makefile wrapper, so `make universal.fish` won't work (although
this can potentially be hacked around).
2021-08-29 08:56:12 +02:00
Mahmoud Al-Qudsi
35975d83af Run each test fully independently in own environment 2021-08-29 08:56:12 +02:00
Fabian Homborg
4c3cb119fc Actually return when reading file failed
Fixes #8258.
2021-08-29 08:36:54 +02:00
Mahmoud Al-Qudsi
498e5fa9b0 [tests] Set permissions on tmux socket after creation 2021-08-28 22:55:53 +02:00
Fabian Homborg
70e3e0beac Also remove ephemeral item if command is effectively empty
Fixes #8232.

Note that this needed to have expect_prompt used in the pexpect test -
we might want to add a "catchup" there so you can just ignore the
prompt counter for a bit and pick it back up later.
2021-08-20 19:38:16 +02:00
ridiculousfish
2ca66cff53 Disable job control inside command substitutions
This disables job control inside command substitutions. Prior to this
change, a cmdsub might get its own process group. This caused it to fail
to cancel loops properly. For example:

    while true ; echo (sleep 5) ; end

could not be control-C cancelled, because the signal would go to sleep,
and so the loop would continue on. The simplest way to fix this is to
match other shells and not use job control in cmdsubs.

Related is #1362
2021-08-18 22:20:03 +08:00
Fabian Homborg
6c5c8e03c5 Move the numeric locale tests to a different file
This lets us check for locales once, and to have littlecheck mark the
test as skipped.
2021-08-17 15:36:07 +02:00
David Adam
a8fddf3d9b add tests for zero-index expressions
See 5326462116 / #8213.
2021-08-17 12:41:03 +08:00
Mahmoud Al-Qudsi
0a4f80ec41 Add more tests for literal zero indexes 2021-08-15 13:48:41 -05:00
Fabian Homborg
c4593828f4
commandline: Add --is-valid option (#8142)
* commandline: Add --is-valid option to query whether it's syntactically complete

This means querying when the commandline is in a state that it could
be executed. Because our `execute` bind function also inserts a
newline if it isn't.

One case that's not handled right now: `execute` also expands
abbreviations, those can technically make the commandline invalid
again.

Unfortunately we have no real way to *check* without doing the
replacement.

Also since abbreviations are only available in command position when
you _execute_ them the commandline will most likely be valid.

This is enough to make transient prompts work:

```fish
function reset-transient --on-event fish_postexec
    set -g TRANSIENT 0
end

function maybe_execute
    if commandline --is-valid
        set -g TRANSIENT 1
        commandline -f repaint
    else
        set -g TRANSIENT 0
    end
    commandline -f execute
end

bind \r maybe_execute
```

and then in `fish_prompt` react to $TRANSIENT being set to 1.
2021-08-14 11:29:22 +02:00
Fabian Homborg
eee38836cf set -q: Return 255 if no variable name was passed
Previously this strictly returned the number of unset variables. So if
no variable was given, it would return *true*, which is highly
suspect.
2021-08-14 10:55:21 +02:00
Fabian Homborg
b5e5732be1 Point wildcard error at a more specific help section
"Expansion" covers *all* the expansions, that's a bit of a handful.

Directly point people towards globbing.
2021-08-11 18:40:37 +02:00
Fabian Homborg
6c1ec98e92 prompt_pwd: full-dirs set to 0 means not even last component is safe
Alternative is to print an error.
2021-08-09 17:42:00 +02:00
Fabian Homborg
af2952dd2f Allow passing directories to prompt_pwd
This allows us to test it without cd-ing about the place.
2021-08-09 17:42:00 +02:00
Fabian Homborg
2087a3ca63 Let visible length work with CR and LF
Because we are, ultimately, interested in how many cells a string
occupies, we *have* to handle carriage return (`\r`) and line
feed (`\n`).

A carriage return sets the current tally to 0, and only the longest
tally is kept. The idea here is that the last position is the same as
the last position of the longest string. So:

abcdef\r123

ends up looking like

123def

which is the same width as abcdef, 6.

A line feed meanwhile means we flush the current tally and start a new
one. Every line is printed separately, even if it's given as one.

That's because, well, counting the width over multiple lines
doesn't *help*.

As a sidenote: This is necessarily imperfect, because, while we may
know the width of the terminal ($COLUMNS), we don't know the current
cursor position. So we can only give the width, and the user can then
figure something out on their own.

But for the common case of figuring out how wide the prompt is, this
should do.
2021-08-04 21:09:47 +02:00
Fabian Homborg
0059192f61 Allow erasing vars via function-scope
This triggered an assert because the remove code had no idea how to
find the function scope.

Oops!
2021-08-04 17:55:41 +02:00
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
Johannes Altmanninger
66709571ed fish_indent: handle tokens with trailing escaped newlines
Fixes #8197
2021-08-01 18:59:45 +02:00
Johannes Altmanninger
3a375c2399 reader: fix regressions when moving between lines
Fixes some regressions from 35ca42413 ("Simplify some parse_util functions").
The tmux tests are not beautiful but I find them easy to write.
Probably a pexpect test would also be enough here?
2021-08-01 17:50:44 +02:00
Fabian Homborg
dd3cdbcfc9 Fix crash if $PWD is used as for-loop variable
for PWD in foo; true; end

prints:

>..src/parse_execution.cpp:461: end_execution_reason_t parse_execution_context_t::run_for_statement(const ast::for_header_t&, const ast::job_list_t&): Assertion `retval == ENV_OK' failed.

because this used the wrong way to see if something is read-only.
2021-07-30 15:33:04 +02:00
Fabian Homborg
09b8471f5c Test numeric locale
This allows us to test that `test` takes numbers with decimal point even in comma-using locales,
to stop those pesky americans from breaking everything again.

(and yes, we use french to keep myself honest)
2021-07-29 17:20:20 +02:00
Fabian Homborg
b3cdf4afe1 Hardcode $PWD as read-only for set --show
Through a mechanism I don't entirely understand, $PWD is sometimes
writable (so that `cd` can change it) and sometimes not.

In this case we ended up with it writable, which is wrong.

See #8179.
2021-07-28 22:13:22 +02:00
Fabian Homborg
3db78232c6 Show if a var is read-only with set --show
Fixes #8179.
2021-07-28 21:13:03 +02:00
Fabian Homborg
48e696bbb4 Update commandline state before completion
Fixes #8175.
2021-07-27 19:03:35 +02:00
Fabian Homborg
29e9f4838a Run parse_util_detect_errors on -c commands
This didn't do all the syntax checks, so something like

    fish -c 'echo foo; and $status'

complained of a missing command `0` (i.e. $status), and

    fish -c 'echo foo | exec grep'

hit an assert!

So we do what read_ni does, parse each command into an ast, run
parse_util_detect_errors on it if it worked and then eval the ast.

It is possible to do this neater by modifying parser::eval, but I
can't find where.
2021-07-27 18:37:20 +02:00
Fabian Homborg
08209b3d9a Forbid $status as a command
This is slightly unclean. Even tho it would otherwise be syntactically
valid, using $status as a command is very very very likely to be an
error, like

    if not $status

We have reports of this surprisingly regularly, including #2773.

Because $status can only ever be a value from 0 to 255, it is also
very unlikely to be an actual command, and that command is very
unlikely to do what you want.

So we simply point the user towards the "conditions" help section,
that should explain things.
2021-07-27 18:37:20 +02:00
Fabian Homborg
d32e1c12be tinyexpr: Check for nan in ncr
Turns out this takes ages.

Fixes #8170
2021-07-26 18:40:50 +02:00
Johannes Altmanninger
a2b30053dc Teach fish_indent about our feature flags
So it can handle syntax changes that call for different formatting.
2021-07-23 22:58:51 +02:00
Johannes Altmanninger
cc32b4f2a7 Make '&' only background if followed by a separating character
This is opt-in through a new feature flag "ampersand-nobg-in-token".

When this flag and "qmark-noglob" are enabled, this command no longer
needs quoting:

	curl https://example.com/thing?foo=bar&duran=duran

Compared to the previous approach e1570a4 ("Let '&' only separate as
the first char of a word"), this has some advantages:

1. "&&" and "&>" are no longer affected. They are still special, even
   if used between tokens without spaces, like "echo bar&>foo".
   Maybe this is not really *better*, but it avoids risking to annoy
   users by breaking the old variant.

2. "&" is still special if at the end of a token, like in "sleep 1&".

Word movement is not affected by the semantics change, so Alt-F and
friends still stop at every "&".
2021-07-23 22:58:51 +02:00
Fabian Homborg
859edc9c2c Implicitly use $PWD in $CDPATH in completions and highlighting
We already do for the actual cd-ing itself.

Missed in #4484.

Fixes #8161.
2021-07-23 17:22:06 +02:00
ridiculousfish
ce371e1881 Put back support for undocumented -I option to commandline
This allows operating on a user-specified commandline instead of the
true contents. This was inadvertently removed in a32248277f.
2021-07-21 15:35:22 -07:00
Fabian Homborg
3359e5d2e9
Let "return" exit a script (#8148)
Currently, if a "return" is given outside of a function, we'd just
throw an error.

That always struck me as a bit weird, given that scripts can also
return a value.

So simply let "return" outside also exit the script, kinda like "exit"
does.

However, unlike "exit" it doesn't quit an interactive shell - it seems
weird to have "return" do that as well. It sets $status, so it can be
used to quickly set that, in case you want to test something.
2021-07-21 22:33:39 +02:00
ridiculousfish
a32248277f Make commandline state thread safe
Today the reader exposes its internals directly, e.g. to the commandline
builtin. This is of course not thread safe. For example in concurrent
execution, running `commandline` twice in separate threads would cause a
race and likely a crash.

Fix this by factoring all the commandline state into a new type
'commandline_state_t'. Make it a singleton (there is only one command
line
after all) and protect it with a lock.

No user visible change here.
2021-07-21 11:51:46 -07:00
Fabian Homborg
e9a793532e Stop cd "" from crashing
Fixes #8147.
2021-07-17 19:03:15 +02:00
Fabian Homborg
f3f6e4a982 string: Add "--groups-only" to match
This adds a simple way of picking bits from a string that might be a
bit nicer than having to resort to a full `replace`.

Fixes #6056
2021-07-16 20:27:54 +02:00
Fabian Homborg
e013422143 Deduplicate $fish_user_paths automatically
In the variable handler, we just go through the entire thing and keep
every element once.

If there's a duplicate, we set it again, which calls the handler
again.

This takes a bit of time, to be paid on each startup. On my system,
with 100 already deduplicated elements, that's about 4ms (compared to
~17ms for adding them to $PATH).

It's also semantically more complicated - now this variable
specifically is deduplicated? Do we just want "unique" variables that
can't have duplicates?

However: This entirely removes the pathological case of appending to
$fish_user_paths in config.fish (which should be an FAQ entry!), and the implementation is quite simple.
2021-07-14 16:37:30 +02:00
Johannes Altmanninger
405ef31f72 Increase tmux-prompt test timeout in CI
This failed on Ubuntu and Mac.
2021-07-14 08:46:03 +02:00
Johannes Altmanninger
0ab6735450 Support $(cmd) command substitution as alternative to (cmd)
For consistency with "$(cmd)" and with other shells.
2021-07-13 21:33:42 +02:00
Johannes Altmanninger
ec3d3a481b Support "$(cmd)" command substitution without line splitting
This adds a hack to the parser. Given a command

	echo "x$()y z"

we virtually insert double quotes before and after the command
substitution, so the command internally looks like

	echo "x"$()"y z"

This hack allows to reuse the existing logic for handling (recursive)
command substitutions.

This makes the quoting syntax more complex; external highlighters
should consider adding this if possible.

The upside (more Bash compatibility) seems worth it.

Closes #159
2021-07-13 21:33:42 +02:00
Johannes Altmanninger
e50805646e completions/git: define function before use 2021-07-12 23:42:01 +02:00
Johannes Altmanninger
e3d8b315ed Avoid global and user git config leaking into git tests 2021-07-12 23:42:01 +02:00
Fabian Homborg
c8a2837647 Tests: Skip cancel tests on CI
This apparently doesn't work at all under Github Actions with tsan, so let's skip it.

If anyone feels the need to dig deeper into this, have at it. I find
this distracting.
2021-07-12 18:54:40 +02:00
Fabian Homborg
7789651b8a Tests: Increase timeouts even more in CI
Have I ever mentioned I hate this?
2021-07-12 18:45:46 +02:00
Fabian Homborg
e212064978 Tests: Increase timeouts
Yet again, fails on Github Actions with tsan.
2021-07-12 18:16:18 +02:00
ridiculousfish
179073ce62 Clear the control-C cancel flag earlier, allowing event handlers to run
When the user presses control-C, fish marks a cancellation signal which
prevents fish script from running, allowing it to properly unwind.
Prior to this commit, the signal was cleared in the reader. However this
missed the case where a binding would set $fish_bind_mode which would
trigger event handlers: the event handlers would be skipped because of
the cancellation flag was still set. This is similar to #6937.

Let's clear the flag earlier, as soon as we it's set, in inputter_t.
Fixes #8125.
2021-07-11 18:04:44 -07:00
Tair Sabyrgaliyev
8f7ea1f5b6 fix 'socket file name too long' error
In some setups (eg. macports) $tmpdir can expand to more than
100 symbols and tests fail with 'socket file name too long'
errors.

Using relative path to socket file fixes the issue.
2021-07-11 09:28:51 +02:00
Fabian Homborg
0e1f5108ae
string: Allow collect --allow-empty to avoid empty ellision (#8054)
* string: Allow `collect --no-empty` to avoid empty ellision

Currently we still have that issue where

    test -n (thing | string collect)

can return true if `thing` doesn't print anything, because the
collected argument will still be removed.

So, what we do is allow `--no-empty` to be used, in which case we
print one empty argument.

This means

    test -n (thing | string collect -n)

can now be safely used.

"no-empty" isn't the best name for this flag, but string's design
really incentivizes reusing names, and it's not *terrible*.

* Switch to `--allow-empty`

`--no-empty` does the exact opposite for `string split` and split0.

Since `-a`/`--allow-empty` already exists, use it.
2021-07-09 21:20:58 +02:00
ridiculousfish
b395b33776 Migrate remaining calls from debug_safe to FLOGF_SAFE
This removes debug_level and remaining debug bits.

We also simplify some of the exec errors, reducing them to a single
line.
2021-07-05 15:47:56 -07:00
ridiculousfish
92d50414c4 Fix the tmux-prompt test
The tmux-prompt test was failing when run more than once, because
XDG_DATA_HOME has a leading double-dot, causing the uvars file to
leak across sessions. Descend more deeply into our tmpdir to isolate
our XDG_DATA_HOME.
2021-07-04 18:11:49 -07:00
Johannes Altmanninger
62d8f7277b Revert "Avoid excessive polling of universal variable file"
This reverts commit b56b230076.
which somehow made us miss repaints on uvar notifications.

The commit was a workaround for a polling bug which was later properly
fixed by 7c5b8b855 ("Use the uvar notifier pipe timestamp to avoid
excessive polling"), so it's no longer necessary.

Add a system test. If I had a better understanding of the bug I could
probably write a better test.

Fixes #8088
2021-07-03 14:31:37 +02:00
Johannes Altmanninger
874fc439dd Remove stale path validation logic
We used to warn about PATH and CDPATH that are not valid directories,
but only if they contain colons.
However, the warning was a false positive because we would split
those values by colons anyway. So there is nothing left we want to
warn about.

Fixes #8095
2021-07-03 08:45:47 +02:00
Fabian Homborg
a3eea4325e Skip some tests on OpenBSD
sigint2 would hang (probably because of different semantics in signal
delivery?)

wcstod isn't implemented correctly, so math can't do hex numbers.

OpenBSD only passes the filename as argv[0] and doesn't give us another feature I know of, so status fish-path can't work.
2021-06-24 20:46:03 +02:00
Fabian Homborg
66bc6ce77d Try to fix tests for Solaris' ps 2021-06-24 18:19:28 +02:00
Fabian Homborg
49bac252f6 Fix some tests for OpenIndiana
Slightly different output and status - false returns 255, ls doesn't
say it's "ls" in the error.
2021-06-24 18:17:10 +02:00
Johannes Altmanninger
48c1550f61 Point to builtins begin/end when a failed command starts with "{"
Closes #6415
2021-06-23 21:47:40 +02:00
Fabian Homborg
392e48d242 Fix fish_add_path tests
Whoopsie!

I forgot to adjust them for $PATH scope - it now prints a `-g` when
setting $PATH verbosely.
2021-06-23 21:30:10 +02:00
Fabian Homborg
7059eaa4ab Revert "Disallow escaped characters in variable expansion"
This reverts commit 555af37616.
2021-06-10 16:46:17 +02:00
Fabian Homborg
046db09f90
Try to set LC_CTYPE to something UTF-8 capable (#8031)
* Try to set LC_CTYPE to something UTF-8 capable

When fish is started with LC_CTYPE=C (even just effectively, often via
LC_ALL=C!), it's basically broken. There's no way to handle non-ASCII
characters with a C locale unless we want to write our
locale-independent replacements for all of the system functions.

Since we're not going to do that, let's try to find *some locale* for
LC_CTYPE.

We already do that in __fish_setlocale, but that's

- a bit of a weird thing that reads unstandardized system
  configuration files
- allows setting locale to C explicitly

So it's still easily possible to end up in a broken configuration.

Now, the issue with this is that there is (AFAICT) no portable way to
get a list of all allowed locales and C.UTF-8 is not standardized, so
we have no one locale to fall back on and are forced to try a few. The
list we have here is quite arbitrary, but it's a start.

Python does something similar and only tries C.UTF-8, C.utf8 and
"UTF-8".

Once C.UTF-8 is (hopefully) standardized, that will just start
working (tm).

Note that we do not *export* the fixed LC_CTYPE variable, so external
programs still have to deal with the C locale, but we have no real
business messing with the user's environment.

To turn it off: $fish_allow_singlebyte_locale, if set to something true (like "1"),
will re-run the locale initialization and skip the bit where we force
LC_CTYPE to be utf8-capable.

This is mainly used in our tests, but might also be useful if people
are trying to do something weird.
2021-06-06 09:28:32 +02:00
ridiculousfish
c5ec4ef5f9 Reverts noshebang test fixes
The hope is that the noshebang test was fixed on old glibc
through e74b9d53df. Revert the previous optimistic attempts to
fix these through adding sleeps and subshells.

This reverts commit b3da0bd5a2.
This reverts commit 8a86d3452f.
2021-05-31 13:42:26 -07:00
Fabian Homborg
b3da0bd5a2 tests/noshebang: Add some longer sleeps
This still fails on launchpad. Last try, then I'm removing this - it's
not really expected that this particular bit would change a lot.
2021-05-30 17:19:04 +02:00
Fabian Homborg
8a86d3452f tests/noshebang: Do redirections in a new shell process
This is an attempt to solve the test failures on Launchpad's CI.

I'm assuming when we do a redirection like

    foo > file

and then try to execute `file` immediately afterwards, we either
haven't written it soon enough or closed the file, so we get a "text
file busy" error.

So, when we do that in a new fish the file should be closed once it
quits.

See #8021.
2021-05-30 11:08:33 +02:00
Fabian Homborg
7511de8d8d tests/noshebang: Sleep before executing a file we just wrote to
When you try to execute a file directly after you've written to it,
you might, on some systems, get a "text file busy" error.

So we unfortunately have to sleep to avoid it.

See #8021 for where this was added,
537b3f6cb1 for the same problem.
2021-05-26 17:14:15 +02:00
ridiculousfish
08950b1077 Revert "Bravely set job control to full at startup"
Now that `$last_pid` is never fish's pid, we no longer need to force
jobs to run in their own pgroup. Restore the job control behavior to
what it was prior, so that signals may be delivered properly in
non-interactive mode.

This reverts commit 3255999794
2021-05-25 15:28:53 -07:00
ridiculousfish
33f3c03dae Allow on-job-exit handlers to be added for any pid in the job
Prior to this change, a function with an on-job-exit event handler must be
added with the pgid of the job. But sometimes the pgid of the job is fish
itself (if job control is disabled) and the previous commit made last_pid
an actual pid from the job, instead of its pgroup.

Switch on-job-exit to accept any pid from the job (except fish itself).
This allows it to be used directly with $last_pid, except that it now
works if job control is off. This is implemented by "resolving" the pid to
the internal job id at the point the event handler is added.

Also switch to passing the last pid of the job, rather than its pgroup.
This aligns better with $last_pid.
2021-05-25 15:28:53 -07:00
Fabian Homborg
2b0b0fe042 tests/bind: Skip on Github macOS
This just fails too much to be of any use.
2021-05-23 19:46:04 +02:00
ridiculousfish
504a969a24 Separate on-job-exit and and on-process-exit events
It is possible to run a function when a process exits via `function
--on-process-exit`, or when a job exits via `function --on-job-exits`.
Internally these were distinguished by the pid in the event: if it was
positive, then it was a process exit. If negative, it represents a pgid
and is a job exit. If zero, it fires for both jobs and processes, which is
pretty weird.

Switch to tracking these explicitly. Separate out the --on-process-exit
and --on-job-exit event types into separate types. Stop negating pgids as
well.
2021-05-19 11:29:08 -07:00
ridiculousfish
6d00ad1045 Ensure that on-process-exit events fire for reaped jobs
This ensures that if a job exits before we have set up the
on-process-exit handler, the handler will still fire.

Fixes #7210
2021-05-17 15:28:32 -07:00
ridiculousfish
962b0f8b90 Pass $status to process-exit event handlers in all cases
Previously, an event handler would receive -1 if the process exited due
to a signal. Instead pass the same value as $status.
2021-05-17 15:25:27 -07:00
Karolina Gontarek
31f3c16857 Resolve relative paths in command names for complete -p
Fixes #6001
2021-05-16 21:52:38 +02:00
ridiculousfish
5de63c9cbb Reimplement builtin_wait using wait handles
This switches builtin_wait from waiting on jobs in the active job list, to
waiting on the wait handles. The wait handles may be either derived from
the job list itself, or from saved wait handles from jobs that exited in
the background.

Fixes #7210
2021-05-15 21:48:15 -07:00
ridiculousfish
f85f6a0127 Enforce that history items must end with trailing newlines
This helps prevent seeing partially written items from other sessions,
in preparation to reducing the amount of flocking done.
2021-05-10 14:23:07 -07:00
ridiculousfish
555af37616 Disallow escaped characters in variable expansion
Prior to this fix, an escaped character like \x41 (hex for ascii A)
was interpreted the same was as A, so that $\x41 would be the same
as $A. Fix this by inserting an INTERNAL_SEPARATOR before these escapes,
so that we no longer treat it as part of the variable name.

This also affects brackets; don't treat echo $foo\1331\135 the same as
echo $foo[1].

Fixes #7969
2021-05-05 16:23:06 -07:00
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
Johannes Altmanninger
c30a7cdfde Enable tmux-complete test in the CI
Just add some extra sleep time so it hopefully also works when the
CI system is overloaded. This succeeded >60 times in the CI, without
a single failure.

In case it legitimately fails again, we should provide simple steps
to reproduce the failure interactively (using "tmux attach").

The uvar issue only triggered because two fish are started - one is
running the tmux-complete script, the other one is running inside tmux.
We could reduce the complexity of this test by writing it in a
different language, like sh or python.
2021-05-01 22:51:35 +02:00
Johannes Altmanninger
b56b230076 Avoid excessive polling of universal variable file
Reproducible at least on Linux, where the "named pipe" universal
variable notifier is used:

	rm -rf build/test/xdg_config
	XDG_CONFIG_HOME=build/test/xdg_config ./build/fish -c "xterm -e ./build/fish"

The child fish reacts to keyboard input with a noticeable initial
delay.  This is because the universal variable file is polled over
a million times, even when I immediately press Control-D. This polling
prevents readb() from handling keyboard input.
Before commit 939aba02d ("Refactor input_common.cpp:readb"), readb()
reacted to keyboard input even when there were universal variable
notifications.  Restore this behavior, but make sure to call the
universal variable notifier after the new "prepare_to_select" logic.
Maybe the problem is in the notifier but the old behavior was sane.

Fixes the problems described in
7a556ec6f2 (commitcomment-49773677)

Adding "-d uvars-file" to the reproducesr shows that we are checking
the uvar file repeatedly:

	uvar-file: universal log sync
	uvar-file: universal log sync elided based on fast stat()
	uvar-file: universal log no modifications
2021-05-01 22:51:35 +02:00
Fabian Homborg
5ddb1adac1 Only use DATADIR in $fish_function_path if no-config is used
This only uses the functions fish ships with, but still doesn't allow
any *customization*, which is the point of no-config.

This makes it a lot more usable, given that the actual normal prompt
and things are there.

This still doesn't set any colors, because we don't run
__fish_config_interactive because we don't read config.fish (any
config.fish), because that would run the snippets.
2021-05-01 18:59:25 +02:00
Johannes Altmanninger
9d7f6db792 fish_indent: preserve escaped newlines around variable assignments
In many cases we currently discard escaped newlines, since they
are often unnecessary (when used around &|;). Escaped newlines
are useful for structuring argument lists. Allow them for variable
assignments since they are similar.

Closes #7955
2021-04-27 00:13:48 +02:00
Johannes Altmanninger
15e265f209 Don't read user configuration in tmux-complete test
As discussed in 7a556ec6f2 (commitcomment-49671741)
2021-04-25 13:32:14 +02:00
Fabian Homborg
3cccb77b52 Make test error when number is invalid nicer
This would print the default "Argument is invalid" error string, which
is *true* but not super obvious, because `test` doesn't always perform
numeric conversion, and that's the bit that failed here.
2021-04-24 11:18:58 +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
f4bcfd9085 Correct behavior of string match variable import with multiple arguments
This refactors the behavior of string match with capture groups to
correctly handle multiple arguments. Now the variable capture applies to
the first match, as documented. Fixes #7938.
2021-04-20 15:15:52 -07:00
ridiculousfish
abd59c50b0 Add a test for invalid regex variable names
Also apply some mild refactoring.
2021-04-20 15:15:52 -07:00
Fabian Homborg
c95a223f5e Better errors when calling a command in a command substitution fails 2021-04-19 16:47:17 +02:00
Fabian Homborg
04f1254c94 Disable tmux tests for now
These are just broken at the moment
2021-04-19 16:46:50 +02:00
ridiculousfish
e8a6d31aea Correct behavior of string match and unmatched capture groups
string match is documented as setting an unset variable if a capture group
is unmatched in an otherwise matched regex, and if the `--all` flag is not
provided. However prior to this fix, it instead set a variable containing
the empty string as a single value. Correct the implementation to match
the documentation.

Note that if the `--all` flag is provided we continue to set empty
strings, which is documented.
2021-04-18 21:04:25 -07:00
ridiculousfish
1aa8200b96 Minor cleanup of builtin_string regex
Mark some classes as final and remove some unnecessary variables.
Add a test in preparation for the next fix.
2021-04-18 20:39:14 -07:00
Fabian Homborg
0111eafbbc tmux tests: Actually use absolute $XDG paths
Erasing $XDG_CONFIG_HOME here means it falls back on the default,
which is ~/.config/, which means it reads user configuration!
2021-04-18 21:09:48 +02:00
ridiculousfish
7a556ec6f2 Additional work on tmux-complete test
This removes the relative XDG paths, which could have potentially
confused tmux, and also starts the window with the correct size
instead of adjusting the size afterwards.
2021-04-17 16:43:28 -07:00
ridiculousfish
f7cef13b9b Partially fix the tmux-complete test
The autosuggestion was creeping in, causing us to sometimes show file-1
and sometimes just file-. Allow the race through a regular expression.
2021-04-17 16:43:28 -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
3b87547411 Fix skipping locale tests on Github Actions 2021-04-16 09:01:41 +02:00
Fabian Homborg
fff158fd2b tests: Disable locale.fish on Github Actions
Sometimes hangs with tsan.

Works around #7934.
2021-04-15 17:26:08 +02: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
Fabian Homborg
56af5d0702 Revert "git prompt: Show stagedstate without dirtystate"
After further thinking, showing this now, by default, without a nice way to turn it off isn't great.

This reverts commit 573fed7798.
2021-04-13 19:10:04 +02:00
Fabian Homborg
573fed7798 git prompt: Show stagedstate without dirtystate
I have *no idea* why this was coupled, especially since dirtystate can
be expensive, staged state should not be.
2021-04-13 16:44:46 +02:00
Fabian Homborg
71166274a2 git prompt: Respect status_order even without informative status
Fixes #7926.

Also switches the default status order for non-informative to the informative one:

stagedstate invalidstate dirtystate untrackedfiles stashstate

instead of

dirty staged stash untracked
2021-04-13 16:44:46 +02:00
David Adam
a918cabf5e feature flags: default stderr-nocaret to on 2021-04-12 22:18:48 +08:00
Fabian Homborg
7210261513 complete: Obey --force-files without an option
Things like

```fish
complete command -n '__fish_seen_subcommand_from subcommand'
--force-files
```

would not be obeyed because we only checked force-files when there was
an option.

Fixes #7920.
2021-04-10 21:58:40 +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
36ad116b34 Properly report errors when builtin output fails
This correctly sets $status when a builtin succeeds but its output fails;
for example if the output is redirected to a file and that write fails.

Fixes #7857
2021-04-03 16:11:25 -07:00
Fabian Homborg
ed9268f99c
math: Make function parentheses optional (#7877)
* math: Make function parentheses optional

It's a bit annoying to use parentheses here because that requires
quoting or escaping.

This allows the parens to be omitted, so

math sin pi

is the same as

math 'sin(pi)'

Function calls have the lowest precedence, so

math sin 2 + 6

is the same as

math 'sin(2 + 6)'

* Add more tests

* Add a note to the docs

* even moar docs

Moar docca

* moar tests

Call me Nikola Testla
2021-03-30 17:21:28 +02:00
Fabian Homborg
18e332772d functions: Add "--no-details" flag and use it in funced
This inhibits the function path comment which is annoying in `funced`.

Fixes #7879.
2021-03-30 16:54:26 +02:00
Fabian Homborg
e1d19cf571 Don't touch $SHLVL if not interactive
It's not super clear what $SHLVL is useful for, but the current
definition is essentially
"number of shells in the parent processes + 1"

which isn't *super useful*?

Bash's behavior here is a bit weird in that it increments $SHLVL
basically always, but since it auto-execs the last process it will
decrement it again, so in practice it's often not incremented.

E.g.

```
> echo $SHLVL
1
> bash -c 'echo $SHLVL; bash'
2
>> echo $SHLVL
2
```

Both bashes here end up having the same $SHLVL because this is
equivalent to `echo $SHLVL; exec bash`. Running `echo $SHLVL` and then
`bash -c 'echo $SHLVL'` in an interactive bash will have a different
result (1 and 2) because that doesn't *exec* the inner bash.

That's not something we want to get into, so what we do is increment
$SHLVL in every interactive fish. Non-interactive fish will simply
import the existing value.

That means if you had e.g. a bash that runs a fish script that ends up
opening a new fish session, you would have a $SHLVL of *2* - one for the
bash, and one for the inner fish.

We key this off is_interactive_session() (which can also be enabled
via `fish -i`) because it's easy and because `fish -i` is asking for
fish to be, in some form, "interactive".

That means most of the time $SHLVL will be "how many shells am I deep,
how often do I have to `exit`", except for when you specifically asked
for a fish to be "interactive". If that's a problem, we can rethink it.

Fixes #7864.
2021-03-29 17:44:13 +02:00
Ilan Cosman
c762c62464 Add max and min math functions 2021-03-28 13:22:44 -07:00
Fabian Homborg
4e4852c40a history: Improve bash import check
- Check for special characters *before* attempting to parse
- Also ignore lines with `{` and `*`
- Also skip lines with `<<` because that might be a heredoc (or a
- `<<<` herestring)

Fixes #7874.
2021-03-28 20:30:37 +02:00
ridiculousfish
b44f40547b Rationalize exit codes for failed execs
This cleans up some exit code processing. Previously a failed exec
would produce exit code 125 unconditionally, while a failed posix_spawn
would produce exit code 1 (!).

With this change, fish reports exit code 126 for not-executable, and 127
for file-not-found. This matches bash.
2021-03-27 21:37:46 -07:00
ridiculousfish
694e112a9b Do not implicitly pass .fish files to /bin/sh
This expands the heuristic introduced in #7802 to prevent implicitly
passing files ending in .fish to /bin/sh.
2021-03-27 19:17:18 -07:00
ridiculousfish
eb71e4555f Clean up and relnote shebangless script support
This adds a test for shebangless support from #7802, cleans up some of
its tricks, and includes it in the changelog.
2021-03-27 16:08:42 -07:00
Fabian Homborg
3255999794 Bravely set job control to full at startup
We have no idea why this was even a thing. For now simply set it to
"all"/"full" (why these two names? no idea) at startup and allow
changing it later.

Settting it *immediately* when defining the variable sets it too soon
because we don't have the interactive signal handlers
enabled (including the one for SIGTTOU), so let's first settle for
this little piece of awkwardness.

This needs widespread testing, so we merge it early, immediately after
the release.

Fixes #5036
Fixes #5832
Fixes #7721

(and probably numerous others)
2021-03-26 19:32:14 +01:00
Fabian Homborg
cbd8f5f63e math: Add log2
This was already in the documentation as an example, now it is
actually working.

Fixes #7734
2021-03-26 19:30:38 +01:00
Johannes Altmanninger
4f00ccfd16 Disable flaky tmux test on GitHub Actions
It still failed with the long timeout. No idea why.
2021-03-26 07:36:55 +01:00
Johannes Altmanninger
76af09a507 Give tmux tests more slack
They never fail me locally, but I saw two failures in GitHub Actions
in the past days (regular builds, not just TSan).
2021-03-23 20:54:23 +01:00
Mahmoud Al-Qudsi
c55865f76e Change use of tmux's resize-window to resize-pane
I believe they are both equivalent for our particular purpose, since we
only care about enforcing the size fish sees.

`resize-window` was only introduced in tmux 2.9, which isn't available
at least on Ubuntu 18.04 LTS (currently using tmux 2.6) and probably
many others.

(Clever idea to use tmux here!)
2021-03-23 00:39:17 -05:00
Fabian Homborg
56135a3231 Test string replace transforms
Just to make sure it works everywhere.
2021-03-21 10:03:35 +01:00
Karolina Gontarek
dcc1659266 Fix typo 2021-03-21 09:26:38 +01:00
Johannes Altmanninger
7fea321b3e
Use the correct case in completion pager (#7744)
Consider

	$ complete -c foo -a 'aab aaB' -f
	$ foo A<TAB>

since 28d67c8 we would insert the common prefix AND show the pager.
Due to case-insensitive comparison, "b/B" was considered to be part
of the prefix. Since the prefix is added to each pager item [1]
we get wrong results. Fix this by removing the insensitive comparison
between completions - I don't think it was of much use anyway.
Commandline tokens are still matched case-insensitively, this is
just about completions.

Test this by running interactive fish inside tmux (pexpect's terminal
emulation not have enough capabilities).  Also add tests for recent
interactive regressions #7526 and #7738.

Closes #3978

[1]: b38a23a would solve this differently by giving every pager item
its own prefix, but was reverted since it needs more fixes.
2021-03-21 09:25:29 +01:00
Fabian Homborg
d79f864072 Add a note for help thing to the missing doc error message
This should cover most cases - the user didn't install the docs and is
trying to view the man page via __fish_print_help, so we don't have a
way to show anything.

But `help thing` will fall back to the online version of the docs,
which should work if there's an internet connection.

See #7824.
2021-03-19 17:39:36 +01:00
Fabian Homborg
02699d1acc Reject empty variable names
This allowed `set "" foo`, which is bogus and results in an unusable variable.
2021-03-18 19:36:57 +01:00
Johannes Altmanninger
efcfec0ba1 fixup! Show an error when "builtin -h" fails to find a man page 2021-03-15 23:14:17 +01: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
600c0d5b3f tests: Remove unnecessary status fish-path
This is broken on OpenBSD because it apparently doesn't have a /proc
we can query, so it just gives "fish".

Since it's unnecessary in this context just skip it.
2021-03-10 18:04:04 +01:00
Fabian Homborg
daa3cc17c4 Fix crash in string pad
Try:

    string pad -w 8 he \eh
2021-03-09 18:36:02 +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
Ilya Grigoriev
762f3aa0ce
Rewrite the real file if history file is a symlink (#7754)
* Rewrite the real file if history file is a symlink

When the history file is a symbolic link, `fish` used to overwrite
the link with a real file whenever it saved history. This makes
it follow the symlink and overwrite the real file instead.

The same issue was fixed for the `fish_variables` file in 622f2868e
from https://github.com/fish-shell/fish-shell/pull/7728.
This makes `fish_history` behave in the same way. The implementation
is nearly identical.

Since the tests for the two issues are so similar, I combined them
together and slightly expanded the older test.

This also addresses https://github.com/fish-shell/fish-shell/issues/7553.

* Add user-facing error when history renaming fails

Currently, when history file renaming fails, no message is shown to the
user. This happens, for instance, if the history file is a symlink
pointing to another filesystem.

This copies code (with a bit of variation, after reviewer comments) from

589eb34571/src/env_universal_common.cpp (L486-L491)

into `history.cpp`, so that a message is shown to the user.

* fixup! Rewrite the real file if history file is a symlink
2021-03-08 17:46:17 +01:00
Fabian Homborg
56e1109609 Add test for caller-exit events
This was a bit fiddly!
2021-03-07 10:22:35 +01:00
Mahmoud Al-Qudsi
8a07db8e8f Revert "Revert "Speed up check-all-fish-files when executed locally""
This reverts commit e240d81ff8 and
introduces a more compatible method of finding newly added fish scripts
to syntax check.

`find -newer` is the original and is supported by everything under the
sun (including FreeBSD, NetBSD, Solaris, OpenIndiana, macOS 10.10, WSL,
and more), and if not, the tests will succeed anyway. `find -mnewer` was
added later around the time `find -cnewer` and co (which checks the
creation date rather than the modification date) was introduced, but
apparently the GNU version of coreutils never introduced the `-mnewer`
alias for `-newer`.

Yes, this is hacky and yes it would be ideal if the build system is the
one that picked which tests to run rather than the test itself picking.
But let's not pretend that our tests are idealogically ideal or pure
right now and until we fix the mess that is our CMake test integration
(e.g. use ctest and configure each test to be run separately with
configurable payloads, etc) eight seconds is still eight seconds, and
again, the CI isn't affected.
2021-03-06 17:13:20 -06:00
Fabian Homborg
e240d81ff8 Revert "Speed up check-all-fish-files when executed locally"
My find (GNU findutils 4.8.0) prints

> find: unknown predicate `-mnewer'

So we would have to test for support.

Also this is *super* hacky - tests aren't supposed to keep files
around, this is something you would do in the build system.

This reverts commit ddd0e28b4f.
2021-03-06 09:36:56 +01:00
Mahmoud Al-Qudsi
a536ab810a Don't set check-all-fish-files timestamp in case of error
I'm not sure if this is necessary or if littlecheck would abort before
the for loop completed and `touch` was executed.
2021-03-05 22:50:26 -06:00
Mahmoud Al-Qudsi
ddd0e28b4f Speed up check-all-fish-files when executed locally
Only check fish files that have been modified since the last time they
were checked. (This continues with the assumption that we are testing
for broken /usr/share fish scripts and not breakage of the fish parser,
which is covered by all the other tests.)

This saves 8 seconds on an NVMe disk under WSL. Won't affect integrity
of CI runs, which start with a blank slate each time.
2021-03-05 22:40:40 -06:00
Fabian Homborg
8bb2ca95c8 checks/git: Give grep a literal tab
Apparently the grep on FreeBSD doesn't do \s or \t. Since we're
looking for an actual tab, just give it an actual tab.

See https://builds.sr.ht/~faho/job/448496.
2021-03-04 16:25:41 +01:00
Fabian Homborg
d85bdf120f fish_add_path: Handle moving multiple arguments correctly
This `set -e` had a cartesian product that caused it to remove the
indexes separately, so the later indexes were off - removing the first
and then the second ends up removing the first and then the
old-*third* which is now the second.

Just quote the expansion so it runs in one go.

Fixes #7776
2021-03-04 16:10:27 +01:00
Fabian Homborg
c96a07dc96 Revert "Prevent redirecting internal processes to file descriptors above 2"
FDs are inherited, and redirecting those is harmless, and forbidding
that is worse than allowing all.

Fixes #7769.

This reverts commit 11a373f121.
2021-03-03 22:26:33 +01:00
Fabian Homborg
119b978cbc type: Add --quiet back
It's supposed to be *deprecated*, not removed. The documentation even
specifically calls it out.

Fixes #7766
2021-03-02 14:53:02 +01:00
Ilya Grigoriev
a04ba04588 Fix git.fish test failing because of an alias
I have an alias `adda=add :/` in my globabl `.gitconfig`, which
made the test fail. This is the fix.
2021-03-01 10:02:03 +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
ridiculousfish
11a373f121 Prevent redirecting internal processes to file descriptors above 2
The user may write for example:

    echo foo >&5

and fish would try to output to file descriptor 5, within the fish process
itself. This has unpredictable effects and isn't useful. Make this an
error.

Note that the reverse is "allowed" but ignored:

    echo foo 5>&1

this conceptually dup2s stdout to fd 5, but since no builtin writes to fd
5 we ignore it.
2021-02-20 16:16:45 -08:00
Ilya Grigoriev
622f2868e1 Fix set -U when fish_variables is a symlink
Previously, `set -U` would overwrite the symlink with a
regular file.

Fixes https://github.com/fish-shell/fish-shell/issues/7466
2021-02-20 14:24:11 -08:00
Johannes Altmanninger
c0af8dae20 fish_indent: fix extra indent of continuation lines inside blocks
fish_indent used to increment the indentation level whenever we saw an escaped
newline.  This broke because of recent changes to parse_util_compute_indents().
Since parse_util_compute_indents() function already indents continuations
there is not much to do for fish_indent - we can simply query the indentation
level of the newline.  Reshuffle the code since we need to pass the offset
of the newline. Maybe this can even be simplified further.

Fixes #7720
2021-02-16 18:39:03 +01:00
Fabian Homborg
b7090c93e6 Fix bind tests
I wasn't aware we printed the fallback bindings anywhere, sorry!

Fixes #7724.
2021-02-16 16:45:59 +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
c27fb9b802 source: Escape filenames in errors
Otherwise this would look weird if you had, say, a tab in there.

See #7716.

(note that this doesn't handle e.g. zero-width-joiners, because those
aren't currently escaped. we might want to add an escape mode for
unprintable characters, but for combining codepoints that's tricky!)
2021-02-15 17:08:26 +01:00
Ethel Morgan
5a0aa7824f Saturate exit codes to 255 for all builtins
After commit 6dd6a57c60, 3 remaining
builtins were affected by uint8_t overflow: `exit`, `return`, and
`functions --query`.

This commit:
- Moves the overflow check from `builtin_set_query` to `builtin_run`.
- Removes a conflicting int -> uint8_t conversion in `builtin_return`.
- Adds tests for the 3 remaining affected builtins.
- Simplifies the wording for the documentation for `set --query`.
- Does not change documentation for `functions --query`, because it does
  not state the exit code in its API.
- Updates the CHANGELOG to reflect the change to all builtins.
2021-02-13 08:41:51 +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
ridiculousfish
84d59accfc builtins to allow stdin to be closed
Prior to this fix, if stdin were explicitly closed, then builtins would
silently fail. For example:

    count <&-

would just fail with status 1. Remove this limitation and allow each
builtin to handle a closed stdin how it sees fit.
2021-02-10 17:43:10 -08:00
Ethel Morgan
6dd6a57c60 Saturate return value in builtin_set_query
builtin_set_query returns the number of missing variables. Because the
return value passed to the shell is an 8-bit unsigned integer, if the
number of missing variables is a multiple of 256, it would overflow to 0.

This commit saturates the return value at 255 if there are more than 255
missing variables.
2021-02-08 20:38:56 +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
ridiculousfish
f0d07f9b1c Fix git test when run from git
Prior to this change, the checks/git.fish test would fail if run from a
git interactive rebase (such as via `git rebase -i --exec 'ninja test'`),
because git itself would inject stuff into the environment. Teach the git
test how to clean up its environment first before running.
2021-02-05 17:58:02 -08:00
Fabian Homborg
b5305ce3d3 Handle backslashes properly in locate_brackets_of_type
This needs to be rewritten, I'm pretty sure we have like 6 of these
kinds of ad-hoc "is this quoted" things lying around.

But for now, at least don't just check if the *previous* character was
a backslash.

Fixes #7685.
2021-02-05 22:03:13 +01:00
Fabian Homborg
594d51e7eb Add a separate --profile-startup option to profile startup
This goes to a separate file because that makes option parsing easier
and allows profiling both at the same time.

The "normal" profile now contains only the profile data of the actual
run, which is much more useful - you can now profile a function by
running

   fish -C 'source /path/to/thing' --profile /tmp/thefunction.prof -c 'thefunction'

and won't need to filter out extraneous information.
2021-01-29 20:46:34 +01:00
Johannes Altmanninger
062f24d91b builtin set: make slice index range optional, like in slice expansion
Expansion parses slices like "$PATH[1..2]", but so does "set" when assigning
"set PATH[1..2] . .".  Commit be06f842a ("Allow to omit indices in index
range expansions") forgot the latter.
2021-01-28 07:19:38 +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
978559fdfa type: Add a few more tests 2021-01-24 15:57:23 +01:00
Fabian Homborg
baa9b21a6f type: Only print function path with "--path"
Fixes #7653.
2021-01-24 15:31:39 +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
Fabian Homborg
e0455d13e7 tests/git: Start an interactive fish
This makes the fish_git_prompt variable handlers kick in, meaning we
see the informative chars.

The big question here is what happens if there's a non-UTF-8 locale in
the test.

Theoretically we set LC_CTYPE, but.....
2021-01-19 19:16:17 +01:00
Fabian Homborg
fa9c233065 Add a simple git test
Just checks two completions and the prompt for now, but shows what is possible.

Work on #4249.
2021-01-16 13:30:04 +01:00
Fabian Homborg
932074f06c escape_string_script: Escape DEL as \x7f
This used to print a literal DEL character in the output for `bind`,
which wouldn't actually show up and made it hard to figure out what
the key was.

So we just escape it back to how we actually used it - `\x7f`.

Fixes #7631.
2021-01-16 12:49:49 +01:00
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
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
Sean Wei
ca0f5686ff Fix typo 2020-10-31 13:27:05 +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
a84d57b02b math: Actually report closing paren error
This was typically overridden by "too many/few arguments", but it's
actually incorrect:

    sin(55

has the correct number of arguments to `sin`, but it's lacking
the closing `)`.
2020-10-26 18:13:43 +01:00
Mahmoud Al-Qudsi
9fb6a4ea9d Re-use xdg_ directories in test_util 2020-10-25 23:07:46 -05:00