Commit graph

627 commits

Author SHA1 Message Date
Fabian Homborg
8c9359fdd4 src/builtin_argparse: Add --ignore-unknown flag
This keeps all unknown options in $argv, so

```fish
argparse -i a/alpha -- -a banana -o val -w
```

results in $_flag_a set to banana, and $argv set to `-o val -w`.

This allows users to use multiple argparse passes, or to simply avoid
specifying all options e.g. in completions - `systemctl` has 46 of
them, most not having any effect on the completions.

Fixes #5367.
2019-04-29 15:57:56 +02:00
Fabian Homborg
af0e08e9f1 argparse: Use the current function name by default
This makes the `--name` option usually unnecessary.

See #5835.
2019-04-27 15:55:49 +02:00
Fabian Homborg
009ecfd7e6 src/tokenizer: Add ":@" to the list of non-path-component chars
This makes kill-path-component stop there.

Fixes #5841.
2019-04-26 19:16:21 +02:00
Fabian Homborg
22ce8c23c6 builtin_complete: Allow complete -C something
This is a long-standing issue with how `complete --do-complete` does
its argument parsing: It takes an optional argument, so it has to be
attached to the token like `complete --do-complete=foo` or (worse)
`complete -Cfoo`.

But since `complete` doesn't take any bare arguments otherwise (it
would error with "too many arguments" if you did `complete -C foo`) we
can just take one free argument as the argument to `--do-complete`.

It's more of a command than an option anyway, since it entirely
changes what the `complete` call _does_.
2019-04-26 15:02:29 +02:00
Mahmoud Al-Qudsi
82ef2d19a5 Reduce timeout for jobs regression test
We've been moving away from full second timeouts, they were piling up.
2019-04-19 19:08:16 -05:00
David Adam
4ddfd73079 add tests for #5824 2019-04-19 14:08:16 +08:00
David Adam
d0735882a3 add tests for the not-quite-fixed #5812 2019-04-18 21:12:25 +08:00
Mahmoud Al-Qudsi
2dfc85245f Add regression tests for eval 2019-04-13 17:28:16 -05:00
Mahmoud Al-Qudsi
47a61a3202 Test: validate $status is preserved on calling into a function 2019-04-13 17:21:13 -05:00
Mahmoud Al-Qudsi
ab37dfaf78 Add tests for evaluaton of empty blocks and functions 2019-04-13 17:21:13 -05:00
Mahmoud Al-Qudsi
87f6856954 Fix tests expecting non-zero status after empty function call 2019-04-13 17:21:13 -05:00
Aaron Gyes
014ab7935e Test expansion syntax errors.
If there is a better way to do stuff that will stop execution than
fish -c for our tests, please let me know.
2019-04-11 21:59:23 -07:00
Mahmoud Al-Qudsi
da20d197b4 Add regression test for eval scope (#4443) 2019-04-11 10:40:22 -05:00
David Adam
d6a4694d9f tests: add test for invalid variable name in for loop
Work on #5800.
2019-04-09 20:10:57 +08:00
ridiculousfish
35b3f7fee8 Reduce loop count of pipeline test
Make the test run faster
2019-04-07 15:00:13 -07:00
ridiculousfish
f5bb8639d6 More aggressively inherit pgrps from parent jobs
Prior to this fix, a job would only inherit a pgrp from its parent if the
first command were external. There seems to be no reason for this
restriction and this causes tcsetgrp() churn, potentially cuasing SIGTTIN.
Switch to unconditionally inheriting a pgrp from parents.

This should fix most of #5765, the only remaining question is
tcsetpgrp from builtins.
2019-04-07 13:35:00 -07:00
ridiculousfish
4d62af7d40 Add pipeline tests
This adds a pipeline test covering the fix in the prior commit,
related to #5675. Note #5675 is NOT fully fixed by this.
2019-04-07 09:20:32 -07:00
Mahmoud Al-Qudsi
2e6264558c Fix remaining realpath test issue with symlinks
Pursuant to 0be7903859, there still
remained one issue with the test when run from within a symlinked
directory after fish gained support for cding into symlinks.

This change should make the test function OK both when the tests are run
out of a PWD containing a symlink in its hierarchy and when run
otherwise.
2019-04-04 22:25:45 -05:00
ridiculousfish
e2ed6baf43 Make the output/errput test more robust by sorting output 2019-04-03 16:50:13 -07:00
ridiculousfish
7231d86676 Fix the tests
Remove 'pwd-resolved-to-itself' message
2019-03-28 20:18:45 -07:00
Mahmoud Al-Qudsi
0be7903859 Drop realpath test built on assumption PWD cannot be a symlink
The final test in `realpath.in` was based on the no-longer-valid
assumption that $PWD cannot be a symlink. Since the recent changes in
fish 3.0 to allow `cd`ing into "virtual" directories preserving symlinks
as-is, when `make test` was  run from a path that contained a symlink
component, this test would fail the `pwd-resolved-to-itself` check.

As the test is not designed to initialize then cd into an absolute path
guaranteed to not be symbolic, so this final check is just wrong.
2019-03-28 19:05:33 -05:00
Mahmoud Al-Qudsi
f8b2e818ed Remove legacy generic process/job exit events 2019-03-28 18:55:36 -05:00
Mahmoud Al-Qudsi
0c5015d467 Correct the reversed diff output for all tests
This has been driving nuts for years. The output of the diff emitted
when a test fails was always reversed, because the diff tool is called
with `${difftool} ${new} ${old}` so all the `-` and `+` contexts are
reversed, and the highlights are all screwed up.

The output of a `make test` run should show what has changed from the
baseline/expected, not how the expected differs from the actual. When
considered from both the perspective of intentional changes to the test
outputs and failed test outputs, it is desirable to see how the test
output has changed from the previously expected, and not the other way
around.

(If you were used to the previous behavior, I apologize. But it was
wrong.)
2019-03-28 18:23:32 -05:00
Fabian Homborg
88d2d54276 Stop printing help summary on error
This now displays

- the error message

- a (significantly shorter) backtrace

- A call to open `help $cmd` if necessary

See #5434.
Fixes #3404.
2019-03-26 19:24:48 +01:00
Fabian Homborg
7095de628c Remove "called on standard input" message
This was printed basically everywhere.

The user knows what they executed on standard input.

A good example:

```fish
set c (subme 513)
```

used to print

```
fish: Too much data emitted by command substitution so it was discarded

    set -l x (string repeat -n $argv x)
             ^
in function 'subme'
	called on standard input
	with parameter list '513'
in command substitution
	called on standard input
```

and now it is

```
fish: Too much data emitted by command substitution so it was discarded

    set -l x (string repeat -n $argv x)
             ^
in function 'subme' with arguments '513'
in command substitution
```

See #5434.
2019-03-26 17:38:41 +01:00
Fabian Homborg
71a2337c5f Remove stray newlines in test
Sorry!
2019-03-26 17:18:25 +01:00
Fabian Homborg
39a601927f Remove useless empty lines from stack traces
This printed things like

```
in function 'f'
        called on standard input

in function 'd'
        called on standard input

in function 'b'
        called on standard input

in function 'a'
        called on standard input

```

As a first step, it removes the empty lines so it's now

```
in function 'f'
        called on standard input
in function 'd'
        called on standard input
in function 'b'
        called on standard input
in function 'a'
        called on standard input
```

See #5434.
2019-03-26 16:47:42 +01:00
Fabian Homborg
b86200938f Always use "." for cd
Nobody doesn't want to use $PWD to cd, so if $CDPATH does not include
it that was a mistake.

Bash also appends "." here.

Fixes #4484.
2019-03-26 10:11:36 +01:00
ridiculousfish
5eade35257 Stop buffering deferred function processes
If a function process is deferred, allow it to be unbuffered.
This permits certain simple cases where functions are piped to external
commands to execute without buffering.

This is a somewhat-hacky stopgap measure that can't really be extended
to more general concurrent processes. However it is overall an improvement
in user experience that might help flush out some bugs too.
2019-03-24 21:23:26 -07:00
Fabian Homborg
0bde698f81 printf: Don't die on incomplete conversions
POSIX dictates here that incomplete conversions, like in

    printf %d\n 15.2

or

    printf %d 14g

are still printed along with any error.

This seems alright, as it allows users to silence stderr to accept incomplete conversions.

This commit implements it, but what's a bit weird is the ordering between stdout and stderr,
causing the error to be printed _after_, like

    15
    14
    15.1: value not completely converted
    14,2: value not completely converted

but that seems like a general issue with how we buffer the streams.

(I know that nonfatal_error is a copy of most of fatal_error - I tried
differently, and va_* is weird)

Fixes #5532.
2019-03-17 17:00:55 +01:00
Aaron Gyes
6e525cc5d9 wcsfilecmp: sort - after everything else
Before this change, - was sorted with other punctuation before
A-Z. Now, it sorts above the rest of the characters.

This has a practical effect on completions, where when there are
both -s and --long with the same description, the short option
is now before the long option in the pager, which is what is now
selected when navigating `foo -<TAB>`. The long options can be
picked out with `foo --<TAB>`. Before, short options which
duplicated a long option literally could not be selected by
any means from the pager.

Fixes #5634
2019-03-16 01:31:56 -07:00
Aaron Gyes
74a22ff426 wcsfilecmp: punctuation [\]^_` after A-Z.
This tweaks wcsfilecmp such that certain punctuation characters will
come after A-Z.

A big win with `set <TAB>` - the __prefixed fish junk now comes
after the stuff users should care about.
2019-03-16 01:18:16 -07:00
Fabian Homborg
864bb1f7a6 Add string-replace-fewer-backslashes feature
This disables an extra round of escaping in the `string replace -r`
replacement string.

Currently, to add a backslash to an a or b (to "escape" it):

    string replace -ra '([ab])' '\\\\\\\$1' a

7 backslashes!

This removes one of the layers, so now 3 or 4 works (each one escaped
for the single-quotes, so pcre receives two, which it reads as one literal):

    string replace -ra '([ab])' '\\\\$1' a

This is backwards-incompatible as replacement strings will change
meaning, so we put it behind a feature flag.

The name is kinda crappy, though.

Fixes #5474.
2019-03-15 15:18:19 +01:00
Fabian Homborg
e7a964fdfa [count] Allow counting lines from stdin
As a simple replacement for `wc -l`.

This counts both lines on stdin _and_ arguments.

So if "file" has three lines, then `count a b c < file` will print 6.

And since it counts newlines, like wc, `echo -n foo | count` prints 0.
2019-03-15 14:31:36 +01:00
Fabian Homborg
47ff060b89 string: Fix split0 return status
It turns out that `string split0` didn't actually ever do any
splitting. The arg_iterator_t already split stdin on NUL, and split0 just
performed an additional search that could never succeed (since
arguments from argv already can't contain NUL).

Let the arg_iterator_t not perform any splitting if asked, and then
let split0 split in 0.

One slight wart is that split0 ignores a trailing NUL, which normal
split doesn't.

Fixes #5701.
2019-02-26 20:03:40 +01:00
zabereer
2c8abdf5cb add $pipestatus support 2019-02-24 21:46:52 -08:00
ridiculousfish
003998c921 Event blocks just block all events
In a galaxy far, far away, event_blockage_t was intended to block only cetain
events. But it always just blocked everything. Eliminate the event block
mask.
2019-02-23 13:02:07 -08:00
ridiculousfish
f015f930f1 Enhance the signal test 2019-02-23 12:41:01 -08:00
ridiculousfish
6bddf2c83b Add basic signal test 2019-02-23 11:57:19 -08:00
ridiculousfish
59cb2d02a8 Only inherit a PWD if it resolves to "."
Fixes #5647
2019-02-18 13:20:40 -08:00
Fabian Homborg
1c3fe7dc66 tests/expansion: Use rm instead of unlink
unlink(1) is apparently not always installed everywhere.

Since there is no real difference, just use rm.
2019-02-18 15:39:58 +01:00
Fabian Homborg
2614deb138 tests/invocation: Use ggrep if available
We use grep -o here to filter output, but that's not available on
OpenIndiana.

It does offer "ggrep" though, which is GNU grep.
2019-02-13 13:49:53 +01:00
Fabian Homborg
c1d042051c Disable directory redirect test
On some systems, this sometimes uses unicode quotation marks.

Not on mine, but on Travis it does.

The only other workaround I can think of is setting locale to C, but
that implies not being able to test anything unicode-related in the
entire invocation tests.

So for now disable this test.
2019-02-13 13:33:30 +01:00
Fabian Homborg
84593e1519 tests/invocation: Remove local
Instead this runs the `test_file` function in a subshell, which is the
POSIXy way of doing this.

Overly magic? Sure. Standard? Indeed.
2019-02-13 13:29:31 +01:00
Fabian Homborg
1ee57e9244 tests/realpath.in: We want to delete $PWD, darnit!
Illumos/OpenIndiana/SunOS/Solaris has an rm/rmdir that tries to
protect the user by not allowing them to delete $PWD.

Normally, this would be a good thing as deleting $PWD is a stupid
thing to do. Except in this case, we absolutely need to do that.

So instead we weasel around it by invoking an sh to cd out of the
directory to then invoke an `rmdir` to delete it. That should throw
off any attempts at protection (we could also have tried $PWD/. or
similar, but that's possibly still protected against).

This is the last failing test on
Illumos/OpenIndiana/SunOS/Solaris/afunnyquip, so:

Fixes #5472.
2019-02-13 13:05:50 +01:00
Fabian Homborg
c62d95e428 tests: Move directory redirection test to invocation
This tested #1728, where redirecting a directory (`begin; something;
end < .`) would cause `status` to misbehave.

Unfortunately, on Illumos/OpenIndiana/SunOS, this returns a different
error (EINVAL instead of EISDIR), so we can't check that with our test harness, because
we can't redirect it.

Since it's not important that this gives the same error across
systems (and indeed we provide no way of intercepting the error!),
use an invocation test instead, because that allows different output per-uname.

See #5472.
2019-02-13 13:05:50 +01:00
Fabian Homborg
ca5b7c0ec4 math: Allow --scale=max 2019-02-13 12:54:58 +01:00
Mrmaxmeier
6e9250425a src/exec: fix assertion on failed exec redirection
Minimal reproducer: `fish -c "exec cat<x"`
2019-02-12 20:52:03 -08:00
Fabian Homborg
fb7a6e5f34 Add builtin -q
Used to query for a builtin's existence, like `type -q` and `functions
-q` can be used to query for a things and a functions existence respectively.
2019-02-12 20:34:19 +01:00
Aaron Gyes
038fea1a47 Fix builtin $var expansion
A special case added for #1252 needed adjustment.

Fixes #5639
2019-02-10 14:45:03 -08:00
ridiculousfish
1701e2c558 Revert "add $pipestatus support"
This reverts commit ec290209db.
2019-02-10 13:46:58 -08:00
zabereer
ec290209db add $pipestatus support 2019-02-10 13:30:40 -08:00
Fabian Homborg
7c8b444927 Reduce default escape delay
300ms was waaay too long, and even 100ms wasn't necessary.

Emacs' evil mode uses 10ms (0.01s), so let's stay a tad higher in case
some terminals are slow.

If anyone really wants to be able to type alt+h with escape, let them
raise the timeout.

Fixes #3904.
2019-02-07 12:19:36 +01:00
ridiculousfish
6f682c8405 Fill io_buffer via background thread
This is a large change to how io_buffers are filled. The essential problem
comes about with code like (example):

    echo ( /bin/pwd )

The output of /bin/pwd must go to fish, not the tty. To arrange for this,
fish does the following:

1. Invoke pipe() to create a pipe.
2. Add an io_bufferfill_t redirection that owns the write end of the pipe.
3. After fork (or equiv), call dup2() to replace pwd's stdout with this  pipe.

Now when /bin/pwd writes, it will send output to the read end of the pipe.
But who reads it?

Prior to this fix, fish would do the following in a loop:

1. select() on the pipe with a 10 msec timeout
2. waitpid(WNOHANG) on the pwd proc

This polling is ugly and confusing and is what is replaced here.

With this new change, fish now reads from the pipe via a background thread:

1. Spawn a background pthread, which select()s on the pipe's read end with
a long (100 msec) timeout.
2. In the foreground, waitpid() (allowing hanging) on the pwd proc.

The big win here is a major simplification of job_t::continue_job() since
it no longer has to worry about filling buffers. This will make things
easier for concurrent execution.

It may not be obvious why the background thread still needs a poll (100 msec).
The answer is for cases where the write end of the fd escapes, in particular
background processes invoked inside command substitutions. psub is perhaps
the only important case of this (other shells typically just hang here).
2019-02-03 01:58:49 -08:00
Fabian Homborg
ff89c61afa functions -q: Return false without an argument
This erroneously listed functions and returned true.
2019-02-01 18:34:45 +01:00
Aaron Gyes
276d00e0cf Fix invocation tests.
6b16975359 broke tests. My bad.
2019-01-28 20:44:07 -08:00
David Adam
d8d9cfdc10 interactive tests: exit quietly if expect not available
It seems that 44cfe3e34 inadvertently included the requirement for the
expect tests to pass; revert this to its original sense.
2019-01-28 21:51:57 +08:00
Fabian Homborg
02628d1b02 default_command_not_found_handler: Join arguments
Without it, this would print the error multiple times, like

    Unknown command: echs
    Unknown command: 1
    Unknown command: 2
    Unknown command: 3

Fixes #5588.
2019-01-26 21:21:20 +01:00
Fabian Homborg
8079345207 tests/invocation.sh: Use a formatting string with printf
Using printf like

    printf "The message"

is unsafe, because if the message contains any formatting characters,
they'll be interpreted.

In this case it's not all that important because the message contains
only filenames of our tests and static strings, but still.
2019-01-23 22:53:53 +01:00
Aaron Gyes
4e391abe3c tests/invocation.sh: use printf to omit the newline again 2019-01-23 13:39:16 -08:00
Fabian Homborg
a17e6fa4e8 tests/invocation: Remove one more echo -n
This one was purely cosmetic in the runner output.
2019-01-23 22:14:21 +01:00
ridiculousfish
24f251e044 Correctly remove the test directory again in cd test 2019-01-22 14:07:25 -08:00
ridiculousfish
91a9c98974 Correctly inherit a virtual PWD
PWD is not set in fish vars because it is read only.
Use getenv() to fetch it, allowing fish to inherit a virtual PWD.

Fixes #5525
2019-01-22 13:34:04 -08:00
ridiculousfish
1680b741b2 Make while loops evaluate to the last executed command status
A while loop now evaluates to the last executed command in the body, or
zero if the loop body is empty. This matches POSIX semantics.

Add a bunch of tricky tests.

See #4982
2019-01-20 16:37:20 -08:00
Fabian Homborg
3847d2e9d1 Also set the read-only flag for non-electric vars
For some reason, we have two places where a variable can be read-only:

- By key in env.cpp:is_read_only(), which is checked via set*

- By flag on the actual env_var_t, which is checked e.g. in
  parse_execution

The latter didn't happen for non-electric variables like hostname,
because they used the default constructor, because they were
constructed via operator[] (or some such C++-iness).

This caused for-loops to crash on an assert if they used a
non-electric read-only var like $hostname or $SHLVL.

Instead, we explicitly set the flag.

We might want to remove one of the two read-only checks, or something?

Fixes #5548.
2019-01-18 19:27:41 +01:00
Fabian Homborg
34ed958f72 Test that things can't wrap themselves
This is a test belonging to the previous commit, 58b696bed.

See #5541.
2019-01-17 16:46:15 +01:00
Fabian Homborg
de32665939 tests/invocation: Disable set -e
There's just waaayy too many things that could go wrong with it, so it
annoys more than it helps, especially since we don't get any
indication what failed.

E.g. on FreeBSD, the test failed without a usable message just because
`tput` couldn't find an attribute (so colors were unset).
2019-01-16 12:01:00 +01:00
Fabian Homborg
6c1a2c1f30 tests: Don't use mktemp -u
This works around a bug on FreeBSD 11.
2019-01-16 12:01:00 +01:00
Mahmoud Al-Qudsi
03cdf89bfd Add tests for $status after while in various scenarios
Includes a regression test for #5513 and asserts the behavior defined in
\#4982.
2019-01-13 18:58:48 -06:00
Fabian Homborg
5612f47e33 Revert "Revert "tests/invocation.sh: Port to sh (from bash)""
The one thing I was missing:

`echo -n` isn't POSIX. In practice, it appears the only shell to encounter this
is macOS' crusty old bash in sh-mode. Just replace it with `touch`.

This reverts commit fc5e8f9fec.
2019-01-08 22:57:56 +01:00
Fabian Homborg
fc5e8f9fec Revert "tests/invocation.sh: Port to sh (from bash)"
This reverts commit 9aa8740c36, which broke on macOS.

If anyone wants to try, feel free to do so!
2019-01-07 21:27:32 +01:00
Fabian Homborg
9aa8740c36 tests/invocation.sh: Port to sh (from bash)
This makes the script worse, but it's good enough.

The required changes are:

- `shopt -s nullglob`, which we simply don't use (we have one glob, but that's
  guaranteed to match because we ship the files)

- One array, which we replace with a direct use of the glob (plus it
  used `echo` again?)

- The `function` word, which I'm still annoyed is even a thing!

- Variable indirection (`color=${!color_var}` - instead we pass the
  value directly - which makes the script uglier!)

- One array, which we replace with a function

- A use of `type -t`, replaced with `command -v`

- A use of `${var:begin:end}` substring expansion, replaced with trickery.

- `set -o pipefail` is replaced with a function

Note that checkbashisms still complains about `command -v`, because
we're not using it with "-p". But we _want_ to check the current
$PATH, and `command -v` is POSIX.

This still uses `local`, which technically isn't in POSIX.

The tests now appear to pass in:

- bash

- dash

- zsh

- mksh

- busybox
2019-01-07 18:47:40 +01:00
David Adam
2c01e67a74 histfile tests: tweak expect commands to avoid crash on 32-bit platforms
Rather than killing the process with close, read EOF after sending the
"exit" command and wait for OS cleanup (per the expect examples).

Not cleaning up with wait caused expect to crash on all 32-bit platforms
including i586 and armv7l with "alloc: invalid block: 0xbf993ccb: 3d 3b".

64-bit platforms were not affected, for reasons that are not clear.
2019-01-05 16:03:15 +08:00
Fabian Homborg
3a885d5e82 tests/cd: cd back before cleaning up
Otherwise this'd run afoul of OpenIndiana's "no removing $PWD" rule. Spoilsports!

See #5472.
2019-01-03 23:21:26 +01:00
Fabian Homborg
f3e87b7996 tests/psub: Don't use grep -o and diff -q
These aren't available on OpenIndiana.

`grep -o` is easily changed to `string`, `diff -q` imitated with
`comm` and `test`.

See #5472.
2019-01-03 11:05:03 +01:00
Fabian Homborg
ea6631641f tests/read.expect: Skip /dev/stdin if it doesn't exist
Fixes a failing test on alpine/musl.
2019-01-01 14:52:26 +01:00
Fabian Homborg
7afd7a1985 tests/histfile Remove history --save
This might crash on arch on sr.ht?
2019-01-01 14:52:26 +01:00
Fabian Homborg
8b5fa6f572 tests/test9: Guard locale
Musl!
2019-01-01 14:52:26 +01:00
Fabian Homborg
a84d22b926 tests/printf: Skip locale test on musl
It does not provide a `locale`, so we can't list the locales.
2019-01-01 14:52:26 +01:00
Fabian Homborg
ba8748877a tests/functions: Don't compare diff output
Turns out busybox diff (used on alpine) defaults to unified output,
which we can't use because that prints filenames, and those are
tempfiles made by psub.

Instead, we use builtins to print the first line and compare the others.
2019-01-01 14:52:26 +01:00
Fabian Homborg
54438f8dc1 tests/invocation: Check for tput 2019-01-01 14:52:26 +01:00
Fabian Homborg
e7221a21ef tests/invocation: Disable bad-switch test
This isn't all that important, and it breaks on musl just because the message is different.
Just skip it for now, until we figure out how to better test this.
2019-01-01 14:52:26 +01:00
Fabian Homborg
e83c0b1a53 tests/read: Set TERM=xterm explicitly 2019-01-01 14:52:26 +01:00
Fabian Homborg
b7369213e2 tests/interactive: Scope variables correctly
This `set TERM`. Which, if $TERM is inherited, is already exported,
but not if it isn't.

This is the case on sr.ht's arch images, so we failed without a TERM variable.
2019-01-01 14:52:26 +01:00
Fabian Homborg
1074a59d75 tests/invocation: Set colors after $TERM
builds.sr.ht doesn't set $TERM, so this failed.
2019-01-01 14:52:26 +01:00
Mahmoud Al-Qudsi
131f0f2de5 Speed up wait.expect test
(This is being committed to a branch on the main repository so I can
verify that Travis is able to run this OK.)
2018-12-31 19:36:08 -06:00
Aaron Gyes
1adcd2d591 builtin_test: don't exit 1 for eval errors, add tests for big args
Return STATUS_INVALID_ARGS when failing due to evaluation errors,
so we can tell the difference between an error and falseness.

Add a test for the ERANGE error
2018-12-15 22:05:19 -08:00
Fabian Homborg
4cf3e62643 Move bare source test to expect
This previously used /dev/tty to make sure we have `source` connected
to a terminal. Only as it turns out, FreeBSD doesn't have that (https://builds.sr.ht/~faho/job/15308).

So instead, let's just use the expect tests since stdin there is by
definition a terminal.
2018-12-11 18:23:37 +01:00
ridiculousfish
5012fb0e36 Add 'round' function to builtin math 2018-12-01 13:25:00 -08:00
Aaron Gyes
5615351f27 Revert "Update tests"
This reverts commit 36367e4882.
2018-11-28 06:27:21 -08:00
Aaron Gyes
36367e4882 Update tests
Fish is always executed as ../test/root/bin/fish in these expect tests
2018-11-27 11:59:44 -08:00
Fabian Homborg
a1c481c06a source: Actually check if stdin is a tty, not just redirected
This broke fishtape, which did

    somestuff | fish -c "source"

Because `source` didn't have a redirection, it refused to read from
stdin.

So, to keep the common issue of `source (command that does not print)`
from seeminly stopping fish, we instead actually check if stdin is a terminal.
2018-11-26 23:48:19 +01:00
ridiculousfish
d6a5792ce2 Allow nested square brackets again
Code like echo $list[$var[1]] was producing an error because of
nested square brackets. Allow these brackets again.

Fixes #5362
2018-11-22 17:57:27 -08:00
Aaron Gyes
fc9d8eec72 history expect tests: fix the tests.
The colors happening for the interactive tests didn't match the
expected output. For `history search` commands we test, have them
pipe through `cat` so the fishscript does not use a pager or try
to colorize.
2018-11-20 05:26:54 -08:00
Fabian Homborg
7367e545f2 Revert "wrealpath: Fail for file/something"
Apparently macOS realpath is broken.

This reverts commit ca1c499069.
2018-11-19 09:12:26 +01:00
Fabian Homborg
1ab84ac62a Test setting readonly variables 2018-11-18 22:33:02 +01:00
Fabian Homborg
ca1c499069 wrealpath: Fail for file/something
This incorrectly allowed "file/something" if file existed (as a file), because it
checked "afile".

Fixes #5352.
2018-11-18 20:30:21 +01:00
Aaron Gyes
b00b1af152 Improve realpath error reporting, fix a crasher
realpath() will return NULL and sets errno if it fails.
We asserted that realpath(".") does not fail. We also didn't really
check that it was successful. Made sure we'll get a perror telling
us about what went wrong if something like this happens again.

Updated tests and added test case

Fixes #5351
2018-11-18 09:35:58 -08:00
Mahmoud Al-Qudsi
31d17f4559 Rename string escape --style=pcre2 to string escape --style=regex 2018-11-16 20:22:06 -06:00
Mahmoud Al-Qudsi
e160cde606 Implement PCRE2 escaping
Closes #5309.
2018-11-15 12:00:56 -06:00
David Adam
ae581c7dbc fix tests
Broken in 5bd0472682.
2018-11-13 21:54:41 +08:00
Fabian Homborg
460bc00698 Fix string escape var and url styles
Turns out I broke these in my zeal to remove wcs2string.

This reverts commit 583d771b10.

Fixes #5322.
2018-11-07 12:48:11 +01:00
ridiculousfish
182d7ce732 Teach cd completions about logical paths
Prior to this fix, cding into a symlink and then completing .. would complete
from the physical directory instead of the logical directory, which could not
actually be cd'd to. Teach cd completiond to use the logical directory.
2018-11-03 13:30:55 -07:00
ridiculousfish
9454397e4c Correctly split path environment variables about colons
As noted in #5271
2018-10-27 15:20:32 -07:00
ridiculousfish
47890389e1 Merge branch 'uvar_path_support'
Support for --path and --unpath in universal variables.
Closes  #5271
2018-10-27 01:24:27 -07:00
ridiculousfish
5899694233 Allow setting universal path variables
Support for path and unpath in universal variables.
Fixes #5271
2018-10-27 01:05:00 -07:00
Fabian Homborg
afc82ff23e Math: Truncate integers (scale == 0)
Fixes #5251.
2018-10-24 18:53:33 +02:00
Fabian Homborg
1d5e715008 source: Return error instead of implicitly reading from tty
For things like

    source $undefined

or
    source (nooutput)

it was quite annoying that it read from tty.

Instead we now require a "-" as the filename to read from the tty.

This does not apply to reading from stdin if it's redirected, so

    something | source

still works.

Fixes #2633.
2018-10-22 21:22:27 +02:00
ridiculousfish
f4d666f56c Allow user to set and unset path property of variables
This adds flags --path and --unpath to builtin set, analogous to
--export and --unexport. These flags change whether a variable is
marked as a path variable.

Universal variables cannot yet be path variables.
2018-10-19 17:39:21 -07:00
ridiculousfish
5947aa0171 Join variables by their delimiter in quoted expansion
This switches quoted expansion like "$foo" to use foo's delimiter instead of
space. The delimiter is space for normal variables and colonf or path variables.
Expansions like "$PATH" will now expand using ':'.
2018-10-19 17:35:36 -07:00
ridiculousfish
3f3b3a7006 Export arrays as colon delimited, and support path-style variables
This commit begins to bake in a notion of path-style variables.

Prior to this fix, fish would export arrays as ASCII record separator
delimited, except for a whitelist (PATH, CDPATH, MANPATH). This is
surprising and awkward for other programs to deal with, and there's no way
to get similar behavior for other variables like GOPATH or LD_LIBRARY_PATH.

This commit does the following:

1. Exports all arrays as colon delimited strings, instead of RS.

2. Introduces a notion of "path variable." A path variable will be
"colon-delimited" which means it gets colon-separated in quoted expansion,
and automatically splits on colons. In this commit we only do the exporting
part.

Colons are not escaped in exporting; this is deliberate to support uses
like

    `set -x PYTHONPATH "/foo:/bar"`

which ought to work (and already do, we don't want  to make a compat break
here).
2018-10-19 17:29:39 -07:00
ridiculousfish
d73c487d60 Restore %self to refer to the fish pid
This brings back the %self argument. Like the original %self it only expands
if the argument is literally %self.
2018-10-19 16:17:25 -07:00
Mahmoud Al-Qudsi
0e62dedb26 Correct misdetection of [001] as literal zero index
The control flow in expand.cpp is a bit more complicated than it seemed
at first blush. Ref #4862.
2018-10-15 14:11:37 -05:00
ridiculousfish
0f0bb1e10f Don't resolve symlinks with cd
This switches fish to a "virtual" PWD, where it no longer uses getcwd to
discover its PWD but instead synthesizes it based on normalizing cd against
the $PWD variable.

Both pwd and $PWD contain the virtual path. pwd is taught about -P to
return the physical path, and -L the logical path (which is the default).

Fixes #3350
2018-10-06 17:03:18 -07:00
Mahmoud Al-Qudsi
264d8270a7 Emit an error message on literal zero indices
Mostly resolves #4862, though there remains the lingering question of
whether or not to emit a warning to /dev/tty or stderr when a
non-literal-zero index evaluates to zero.
2018-10-01 20:58:26 -05:00
Fabian Homborg
444f9f8715 Add separation of "preset" bindings
This allows for marking certain bindings as part of a preset, which allows us to

- only erase those when switching presets
- go back to the preset binding when erasing a user binding
- only show user customization if requested
- make bare bind statements in config.fish work (!!!11elf!!!)

Fixes #5191.
Fixes #3699.
2018-09-30 16:54:56 +02:00
Fabian Homborg
3ba74b3195 [string] Match everything with an empty pattern and -e
I.e. `string match --entire "" -- banana` used to match nothing, now
it matches everything.

Fixes #4971.
2018-09-16 13:03:15 +02:00
Fabian Homborg
9be7288fab expansion: Only clamp ranges when not forcing direction
This caused `$var[2..-1]` to still expand to $var[1] if only one
element was given.

Fixup for #4965.

Fixes #5187.
2018-09-15 11:07:29 +02:00
Fabian Homborg
9c2dff76cb Remove some of the wait tests
This cuts the time down to about half. It's still the longest part of
the test suite, but that's probably unavoidable.
2018-09-15 11:07:29 +02:00
ridiculousfish
8e2d207869 Report duration of each test 2018-09-03 14:13:31 -07:00
ridiculousfish
865a4647ae Allow variables in commands
Syntax highlighting for these coming in next commit.

Fixes #154
2018-09-01 12:00:56 -07:00
Chris
1d68b52cbc Add till/repeat/reverse jump bindings
- Add support for:
  - Jumping to the character before a target.
  - Repeating the previous jump (same direction, same precision).
  - Repeating the previous jump in the reverse order.
- Enhance vi bindings.
2018-08-18 14:42:29 -07:00
ridiculousfish
fa66ac8d8c Acquire tty if interactive when running builtins
When running a builtin, if we are an interactive shell and stdin is a tty,
then acquire ownership of the terminal via tcgetpgrp() before running the
builtin, and set it back after.

Fixes #4540
2018-08-12 03:41:56 -07:00
ridiculousfish
d2bee105c9 Default math scale to 6
This changes the behavior of builtin math to floating point by default.
If the result of a computation is an integer, then it will be printed as an
integer; otherwise it will be printed as a floating point decimal with up to
'scale' digits past the decimal point (default is 6, matching printf).
Trailing zeros are trimmed. Values are rounded following printf semantics.

Fixes #4478
2018-08-04 15:32:09 -07:00
ridiculousfish
9d1fc1045e Implement 'functions -d' to set function description
This was documented, but didn't actually work.

Fixes #5105
2018-07-22 11:28:05 -07:00
ridiculousfish
73c747d162 Add string join0
string join0 joins its arguments using NUL byte, which complements
string split0. For example it allows piping a variable through sort -z.
2018-07-01 15:56:34 -07:00
ridiculousfish
d34a300818 Add string split0
This adds a new string command split0, which splits on zero bytes.
split0 has superpowers because its output is not further split on
newlines when used in command substitutions.
2018-07-01 15:56:33 -07:00
Fabian Homborg
81a987c39c Fix range expansion with negative ends
If just one of the range ends is negative, this now forces direction away from it.

I.e. if the beginning is negative, we go in reverse.
If the end is negative, we go forwards.

This fixes cases like

    $var[2..-1]

if $var only has one element.
2018-06-25 17:52:56 +02:00
Fabian Homborg
ca897807eb Add some tests for string and NUL 2018-05-28 12:10:40 +02:00
Mahmoud Al-Qudsi
7d33372d20 Fix __fish_complete_suffix behavior per __fish_complete_directories test 2018-05-20 14:35:52 -05:00
Fabian Homborg
c053065e91 Fix wait tests
This was probably the result of a botched merge.

Unfortunately these tests take quite a while, so maybe we should
remove some?
2018-05-11 16:58:55 +02:00
Fabian Homborg
7c5297e785
Merge branch 'master' into issue_4848 2018-05-11 16:06:27 +02:00
ridiculousfish
98d736f916 Teach fish_indent about escaped newlines
Correctly indents code like:

   alpha | \
     # comment
     beta
2018-05-07 21:40:53 -07:00
ridiculousfish
762c31be87 Feature flag support for ? wildcard
This partially reverts 6e56637cf0 and #4520
by bringing back the ? wildcard, guarded by the qmark-noglob feature flag.
2018-05-06 11:20:15 -07:00
ridiculousfish
dc8d603f98 Add a qmark-noglob feature flag
This adds a feature flag for controlling whether question marks are globs.
It is not yet hooked up.
2018-05-06 11:20:15 -07:00
ridiculousfish
902af26253 Bring back caret redirections under a feature flag
This partially reverts 5b489ca30f, with
carets acting as redirections unless the stderr-nocaret flag is set.
This flag is off by default but may be enabled on the command line:

fish --features stderr-nocaret
2018-05-06 11:20:14 -07:00
ridiculousfish
8a96f283ba Allow setting feature flags on the command line
This introduces a new command line option --features which can be used for
enabling or disabling features for a particular fish session.

Examples:
  fish --features stderr-nocaret
  fish --features 3.0,no-stderr-nocaret
  fish --features all

Note that the feature set cannot be changed in an existing session.
2018-05-06 11:20:14 -07:00
ridiculousfish
782cae2d21 Add status subcomannds: features and test-feature
This teaches the status command to work with features.
'status features' will show a table listing all known features and whether
they are currently on or off.
`status test-feature` will test an individual feature, setting the exit status to
0 if the feature is on, 1 if off, 2 if unknown.
2018-05-06 11:20:14 -07:00
Mahmoud Al-Qudsi
c2cfc65cf2 Correct read behavior for unset values and update tests accordingly
`read` with IFS empty was expected to set all parameters after the first
n filled variables to an empty string, but that was inconsistent with
the behavior of `read` everywhere else.

I'm not sure why fish differed from the spec with regards to the
behavior in the event of an empty IFS: we eschew IFS where possible, yet
here we adopt non-standard behavior splitting on every (unicode)
character instead of not splitting at all with IFS empty. We still do
that, but now the unset variables are treated as they normally would be,
i.e. cleared and not set to an empty string (which is what an empty
value between two IFS separators would contain).
2018-04-17 21:34:22 -05:00
Mahmoud Al-Qudsi
7ec761fc75 Revert "Fix wait test with no process expansion"
This reverts commit b38ac1e35d as wait now
supports process expansion (via the wait wrapper).
2018-04-14 21:42:57 -05:00
Fabian Homborg
ea49c14c62 Fix read to stdout output appearing first
echo banana (read)

will output whatever read reads _first_ because it uses a direct
write_loop().

This also removes some duplicate code.
2018-04-10 21:45:28 +02:00
Peter Ammon
5b489ca30f Remove caret redirection
This removes the caret as a shorthand for redirecting stderr.

Note that stderr may be redirected to a file via 2>/some/path...
and may be redirected with a pipe via 2>|.

Fixes #4394
2018-04-01 13:48:21 -07:00
Mahmoud Al-Qudsi
95e5af7814 fixup! Handle set -e result ENV_NOT_FOUND in tests 2018-03-31 22:25:38 -05:00
Mahmoud Al-Qudsi
95712125c9 Handle set -e result ENV_NOT_FOUND in tests 2018-03-31 22:21:22 -05:00
ridiculousfish
6e56637cf0 Remove support for the ? wildcard
Fixes #4520
2018-03-31 16:54:50 -07:00
ridiculousfish
4b079e16e5 Execute the conditions of if and while statements outside of their block
Variables set in if and while conditions are in the enclosing block, not
the if/while statement block. For example:

    if set -l var (somecommand) ; end
    echo $var

will now work as expected.

Fixes #4820. Fixes #1212.
2018-03-31 14:57:24 -07:00
ridiculousfish
669eafb55f Stop exporting empty variables as ENV_NULL
Localize the encoding of empty variables as ENV_NULL into the universal
variables component, and ensure they are not exported as ENV_NULL.

Fixes #4846
2018-03-24 23:42:09 -07:00
slama
233738d50a forget to set error message to the test with wait command in fish script. 2018-03-25 14:24:23 +09:00
slama
bb1956fd8d fix the problem that wait command doesn't work correctly in fish script. 2018-03-25 14:22:27 +09:00
slama
d078e47adc fix bug with test of wait command 2018-03-25 12:22:09 +09:00