Commit Graph

1247 Commits

Author SHA1 Message Date
Aaron Gyes
6a7ba7921a Actually fix fg.py. 2021-11-03 23:33:02 -07:00
Aaron Gyes
b71f3f5359 Fix fg test.
Now to figure out why 'ninja test' seems to silently skip the
interactive tests here (pexpect is installed).
2021-11-03 23:28:48 -07:00
Aaron Gyes
aca3dc3ba3 Add missing test (wasn't one my system ran locally) 2021-11-03 23:05:24 -07:00
Aaron Gyes
fefb913857 Update tests for changed error output 2021-11-03 22:54:55 -07:00
Johannes Altmanninger
e40eba3585 Treat text following quoted command substitution as quoted
Commit ec3d3a481 (Support "$(cmd)" command substitution without line
splitting, 2021-07-02) started treating an input string like
"a$()b" as if it were "a"$()"b". Yet, we do not actually insert the
virtual quotes. Instead we just adapted the definition of when quotes
are closed - hence the changes to quote_end().

parse_util_locate_cmdsubst_range() is aware
of the changes to quote_end() but some of its
callers like parse_util_detect_errors_in_argument() and
highlighter_t::color_as_argument() are not.  They split strings at
command substitution boundaries without handling the special quoting
rules. (Only the expansion logic did it right.)

Fix this by handling the special quoting rules inside
parse_util_locate_cmdsubst_range(). This is a bit hacky since it
makes it harder for callers to process some substrings in between
command substitutions, but that's okay because current callers only
care about what's inside the command substitutions.

Fixes #8394
2021-10-30 18:02:10 +02:00
ridiculousfish
b9a95a48b4 Test that --on-job-exit functions run even if the job has already exited
If you define a function that you want to be called after a job has
exited, it should run immediately if that job has already exited.
2021-10-28 10:02:48 -07:00
Fabian Homborg
31d6abb177 Don't fire variable set event before entering a for-loop
Since #4376, for-loops would set the loop variable outside, so it
stays valid.

They did this by doing the equivalent of

```fish
set -l foo $foo
for foo in 1 2 3
```

And that first imaginary `set -l` would also fire a set-event.

Since there's no use for it and the variable isn't actually set, we
remove it.

Fixes #8384.
2021-10-28 16:32:58 +02:00
Fabian Homborg
2b8fe280e0 tests: Switch emoji used
widechar_width no longer classifies U+1F41F as widened-in-9, so the
width no longer changes.

Since we're interested in testing the change here, we need a different
emoji.

Just use 🥁, which was introduced in 9 as wide, and therefore widened
in 9.
2021-10-26 18:30:43 +02:00
Fabian Homborg
973739e329 Move CHECKS in loop-test to where they are matched 2021-10-26 17:38:40 +02:00
ridiculousfish
ec244c3975 Add tests for dynamically invoked break and continue 2021-10-25 12:43:30 -07:00
Johannes Altmanninger
ece89f43aa tests/test_env.sh: fix copy paste error so we export XDG_RUNTIME_DIR
fish might use XDG_RUNTIME_DIR for the uvar notifier fifo, so this
makes sure that tests are isolated.

Also set permissions to comply with the XDG basedir spec.
2021-10-23 18:59:15 +02:00
Aaron Gyes
901dbd71b0 fix build when path has spaces in it.
Now it works.
2021-10-22 02:27:19 -07:00
Aaron Gyes
f4377e1a26 necro working tests from 11a373f121 2021-10-21 23:50:42 -07:00
Fabian Homborg
144778dc28 Complete: Fix long-form of "-r" in complete output
This was never `--requires-param`, AFAICT.
2021-10-20 21:05:17 +02:00
Fabian Homborg
e6b75e5947 Add a test to check format strings in translations
This should prevent #8358 from happening again.

Note that, because it's not fixed yet, this test *will* fail.
2021-10-18 17:02:17 +02:00
Erik Serrander
049104e8df Adds sub-command clear-session to history command.
Issue #5791
This clears all history for the current session. Documentation and
autocompletion for the new subcommand is added.
2021-10-17 19:27:46 -07:00
Fabian Homborg
4ffabd44be Don't add expansion error offset twice
Like the $status commit, this would add the offset to already existing
errors, so

```fish
(foo)
(bar)

something
```

would see the "(foo)" error, store the correct error location, then
see the "(bar)" error, and *add the offset of (bar)* to the "(foo)"
error location.

Solve this by making a new error list and appending it to the existing
ones.

There's a few other ways to solve this, including:

- Stopping after the first error (we only display the first anyway, I
think?)
- Making it so the source location has an "absolute" flag that shows
the offset has already been added (but do we ever need to add two offsets?)

I went with the simpler fix.
2021-09-30 18:09:58 +02:00
Fabian Homborg
6774a514fa Don't set error offset for $status
This would break the location of any prior errors without doing
anything of value.

E.g.

```fish
echo foo | exec grep # this exec is not allowed!

$status

somethingelse # The error might be found here!
```

Would apply the offset of `$status` to the offset of `exec`, locating
the error for `exec` somewhere after $status!
2021-09-30 18:09:58 +02:00
ridiculousfish
4f466cb916 broken-symbolic-link test to enter a new directory
This was previously dependent on whatever directory we happened to be
in.
2021-09-24 17:35:45 -07:00
Fabian Homborg
3b74f6e0c6 tests/bind: Disable one flakey test
This one annoys the living fudge out of me, and I've never seen it
fail in earnest.
2021-09-24 20:41:09 +02:00
Fabian Homborg
38f20f445b tests/tmux: Do actually loop 25 times 2021-09-24 18:27:14 +02:00
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