Commit graph

493 commits

Author SHA1 Message Date
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