Commit Graph

630 Commits

Author SHA1 Message Date
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
slama
b758f84976 wait for processes by their name
- You can now specify the process name instead of process ids and wait for jobs.
- Refactor the code of wait command
2018-03-25 02:21:15 +09:00
Mahmoud Al-Qudsi
c0535b4e13 Fix $pid -> $fish_pid in signals.expect
This was a expect variable, not a fish one.
2018-03-24 12:15:58 -05:00
Mahmoud Al-Qudsi
6d80ab8d74 Rename $pid (née %self) to $fish_pid 2018-03-24 11:54:27 -05:00
Mahmoud Al-Qudsi
2951fadc6b Fix parameter expansion tests on Travis macOS 2018-03-12 07:50:37 -05:00
Mahmoud Al-Qudsi
1e5d7d98a8 Add tests for new parameter expansion features 2018-03-12 07:04:05 -05:00
Mahmoud Al-Qudsi
efb894fdae Fix read tests to reflect updated arguments 2018-03-09 12:19:20 -06:00
Mahmoud Al-Qudsi
b38ac1e35d Fix wait test with no process expansion 2018-03-09 10:50:43 -06:00
Fabian Homborg
2d08b5ee8a [math] Add tests for runtime errors
And fix "isinfinite" - it's called "isinf".
2018-03-07 18:13:26 +01:00
ridiculousfish
c7f16439bf Add support for ! as an analog to 'not'
! and not are effectively interchangeable now.
Mark them both as operators for syntax highlighting.
2018-03-05 14:04:49 -08:00
ridiculousfish
357d3b8c6d Rework 'and' and 'or' to be "job decorators"
This promotes "and" and "or" from a type of statement to "job
decorators," as a possible prefix on a job. The point is to rationalize
how they interact with && and ||.

In the new world 'and' and 'or' apply to a entire job conjunction, i.e.
they have "lower precedence." Example:

if [ $age -ge 0 ] && [ $age -le 18 ]
   or [ $age -ge 75 ] && [ $age -le 100 ]
   echo "Child or senior"
end
2018-03-05 13:41:36 -08:00
ridiculousfish
e1dafeab01 Add && and || support to the conditions of if and while
This updates the "boolean tail" feature of the if and while conditions
to know about job_conjunction, thereby respecting && and ||
2018-03-05 13:39:36 -08:00
ridiculousfish
8e9670ccd5 Implement execution of && and ||
This adds support for basic constructs. if and while is not yet
supported.
2018-03-05 12:20:56 -08:00
Mahmoud Al-Qudsi
9502ea8de3 Add tests for jobs -q 2018-03-04 15:33:36 -06:00
Fabian Homborg
0da8022081 [math] Fail without arguments
See #4768.
2018-03-01 22:27:24 +01:00
Fabian Homborg
f60e1549a9 [math] Better error for 2 + 2 4
This now reports "TOO_MANY_ARGS" instead of no error (and triggering
an assertion).

We might want to add a new error type or report the missing operator
before, but this is okay for now.
2018-03-01 13:09:35 +01:00
Fabian Homborg
6a38eb4f7d [math] Better error for 2 -
Instead of the catch-all, report too few arguments.
2018-03-01 13:09:35 +01:00
Fabian Homborg
20af969aba [math] Adjust tests for new error reporting
This shows how it's still weird - "2 - " and "max()" return the same
error.
2018-03-01 13:09:35 +01:00
ridiculousfish
973533e374 Teach alias about wrap argument injection
Update the alias function to pass arguments to 'wraps'. For example
alias gco='git checkout' now works like it ought to.
2018-02-27 14:12:44 -08:00
ridiculousfish
bb7b649132 Wrapping completions to allow injecting arguments
This enables some limited use of arguments for wrapping completions. The
simplest example is that complete gco -w 'git checkout' now works like
you would want: `gco <tab>` now invokes git's completions with the
`checkout` argument prepended.

Fixes #1976
2018-02-27 14:12:44 -08:00
Fabian Homborg
69f68d31df Reserve some builtin names
`argparse`, `read`, `set`, `status`, `test` and `[` now can't be used
as function names anymore.

This is because (except for `test` and `[`) there is no way to wrap these properly, so any
function called that will be broken anyway.

For `test` (and `[`), there is nothing that can be added and there
have been confused users who created a function that then broke
everything.

Fixes #3000.
2018-02-25 21:29:24 +01:00
slama
26ea8dc362 add tests for a pipe at the end of the line 2018-02-18 13:01:38 -08:00
ridiculousfish
c3f1961e36 Stop copying out function definition when executing a function
This switches function execution from the function's source code to
its stored node and pstree. This means we no longer have to re-parse
the function every time we execute it.
2018-02-12 10:55:00 -08:00
Fabian Homborg
aa31fb92f2 Skip interactive tests on macOS on Travis
These just add noise since Travis' macOS machines are apparently
hopelessly overloaded.

Fixes my sanity.
2018-02-06 18:54:27 +01:00
Fabian Homborg
56604f598e [Tests] Add more slack to the bind tests
Some of these were failing on Travis quite often, and this is probably
the result of too tight a window.

E.g. one emacs test (transpose words, default timeout, short delay)
waited 250ms to enter something else, with a timeout of 300ms. That
meant a window of 50ms.
2018-01-16 18:11:46 +01:00
Fabian Homborg
d67b4d6ca7 Fix {,,,} tests
There was an additional line in the output
2018-01-07 15:00:44 +01:00
Fabian Homborg
aa58cae601 Don't count successive "," as literal in brace expansion
This was highly surprising.

Fixes #3002.
2018-01-07 15:00:44 +01:00
Fabian Homborg
55ebf4430f Make literal "{}" expand to itself
This caused major annoyances with e.g. `find -exec`, and it's utterly
useless - "{}" expands to nothing, so why have it at all?

Fixes #1109.
2018-01-07 15:00:44 +01:00
ridiculousfish
9907a8df4d Fix test hang when running under ninja
The psub tests create a fifo and launch a background job to write to it.
However fifos have this obnoxious behavior where opening the file blocks
until both sides are ready. In one of the tests we don't actually read
from the fifo we create, so the background job hangs, and the tests
never complete. Fix this by just reading from the fifo.
2017-12-21 15:48:48 -08:00
Fabian Homborg
4096a7fda9 Revert "Fix "Unknown argument -s" error in fish_vi_key_bindings"
Unfortunately this made tests on travis fail - for some reason I still need to figure out.

This reverts commit 5acbd32c2e.
2017-12-22 00:44:18 +01:00
Fabian Homborg
5acbd32c2e Fix "Unknown argument -s" error in fish_vi_key_bindings
This was caused by it prepending "-s" to argv always,
and later checking $argv[1].

As it turns out, that is kinda superfluous, so we can just add "-s" to
the `bind` calls.

Also adjust the tests so the vi-bindings are enabled via the function,
which would have caught this.

Fixes #4494.
2017-12-21 16:17:21 +01:00
ridiculousfish
67a6f756f2 Add some math tests for invalid inputs 2017-12-18 23:01:16 -08:00
ridiculousfish
81dd4a4536 [math] Remove more bare variable support
Prior to this fix, a "bare variable" in math like 'x + 1' would be
looked up in the environment, i.e. equivalent to '$x + 1'. This appears
to have been done for performance. However this breaks the orthogonality
of fish; performance is not a sufficient justification to give math this
level of built-in power, especially because the performance of math is
not a bottleneck. The implementation is also ugly.

Remove this feature so that variables must be prefixed with the dollar
sign and undergo normal variable expansion. Reading 'git grep' output
does not show any uses of this in fish functions or completions.

Also added to changelog.

Fixes #4393
2017-12-17 12:40:09 -08:00
slama
c7a682ed05 add wait command 2017-11-16 10:48:21 -08:00
David Adam
d5e5878f6d Update tests to match behaviour from 848db48af5 2017-10-31 20:09:45 +08:00
David Adam
b34b0cf1e3 Restore previous output of status current-{filename,function}
Closes #4499.

Partial reversion of 30368d5526.
2017-10-31 18:10:46 +08:00
Aaron Gyes
a9283803d4 Revert "Non-exported vars: rename SHLVL to shlvl"
Duh, of course it is exported.

This reverts commit 5fc17dcc82.
2017-10-15 04:37:34 -07:00
Aaron Gyes
5fc17dcc82 Non-exported vars: rename SHLVL to shlvl
Fixes #4414
2017-10-15 04:33:27 -07:00
Aaron Gyes
7be8a1707c Rename FISH_READ_BYTE_LIMIT to fish_read_limit
Fixes #4414
2017-10-14 08:33:02 -07:00
Mahmoud Al-Qudsi
101ada83cb Fix unit tests for read to stdout behavior 2017-10-10 08:34:50 +02:00
Mahmoud Al-Qudsi
e99f137356 Merge branch 'master' into history-glob-search 2017-10-10 08:16:21 +02:00
David Adam
472e186c2b Rename FISH_HISTORY to fish_history
Work on #4414.
2017-09-24 14:07:45 +08:00
Kurtis Rader
65dcd06ca1 mplement history search glob searches
Instead of treating the search term as a literal string to be matched
treat it as a glob. This allows the user to get a more useful set of
results by using the `*` glob character in the search term.

Partial fix for #3136
2017-09-15 13:43:45 -07:00
Kurtis Rader
ee1d310651 Implement history search --reverse (#4375)
* Implement `history search --reverse`

It should be possible to have `history search` output ordered oldest to
newest like nearly every other shell including bash, ksh, zsh, and csh.
We can't make this the default because too many people expect the
current behavior. This simply makes it possible for people to define
their own abbreviations or functions that provide behavior they are
likely used to if they are transitioning to fish from another shell.

This also fixes a bug in the `history` function with respect to how it
handles the `-n` / `--max` flag.

Fixes #4354

* Fix comment for format_history_record()
2017-09-14 15:44:17 -07:00
Kurtis Rader
905766fca2 Hoist for loop control var to enclosing scope (#4376)
* Hoist `for` loop control var to enclosing scope

It should be possible to reference the last value assigned to a `for`
loop control var when the loop terminates. This makes it easier to detect
if we broke out of the loop among other things.  This change makes fish
`for` loops behave like most other shells.

Fixes #1935

* Remove redundant line
2017-09-08 21:14:26 -07:00
Kurtis Rader
99d2a344c7 Fix indexing of $history
cherry-picked from krader1961/fish-shell commit b69df4fe72

Fixes #4353 (regression in indexing of history contents) and introduces
new unit tests to catch bad $history indexing in the future.
2017-08-25 20:28:45 -05:00
Kurtis Rader
c95b9f06e1 Implement support for bare vars by math
This change allows you to type `math x + 3` rather than `math $x + 3`.

Another step to resolving issue #3157.
2017-08-23 20:41:45 -07:00
Kurtis Rader
d10decabda Make builtin math the default implementation
Remove our `math` function that wraps `bc`. Our math builtin is now good
enough that it can be the default implementation.

Another step in resolving #3157.
2017-08-23 17:32:49 -07:00
Kurtis Rader
ba53242b26 Report error when using read-only var in for loop
Using a read-only variable like `status` as a for loop control variable
has never worked. But without this change you simply get non-sensical
behavior that leaves you scratching your head in puzzlement. This change
replaces the non-sensical behavior with an explicit error message.

Fixes #4342
2017-08-20 12:02:45 -07:00
Kurtis Rader
704517e237 Fix set --local when var is not in local scope
Fixes #4321
2017-08-19 21:39:21 -07:00
Kurtis Rader
f872f25f5b change env_var_t to a vector of strings
Internally fish should store vars as a vector of elements. The current
flat string representation is a holdover from when the code was written
in C.

Fixes #4200
2017-08-18 16:24:30 -07:00
Georgy Yakovlev
58425ed463 Do not redirect to / in status.in/err test. 2017-08-17 10:22:30 -07:00
Kurtis Rader
ea45541d53 fix set --show of semi-empty var
A semi-empty var is one with a single empty string element. The
`env_var_t::empty()` method returns true for such vars but we want
`set --show` to report that it has a single empty element.
2017-08-16 13:39:48 -07:00
peoro
5ceac038b1 Improved warning message when exiting with jobs still active
Fixes #4303
2017-08-14 18:18:09 -07:00
Kurtis Rader
728a4634a1 replace var_entry_t with env_var_t
This is a step to storing fish vars as actual vectors rather than flat
strings.
2017-08-14 18:18:09 -07:00
Kurtis Rader
67de733b9b implement set --append and set --prepend
Fixes #1326
2017-08-04 17:23:24 -07:00
Kurtis Rader
cddc4cfb1d fix set --show output
I realized I was printing individual var entries using zero based
indexing (like C++) when the indexes should be one based.
2017-08-04 17:08:25 -07:00
Kurtis Rader
9028104536 use new logmsg and set --show in tests 2017-08-04 13:36:51 -07:00
Kurtis Rader
2f1e70dc1b use new logmsg and set --show in tests 2017-08-04 13:33:47 -07:00
Kurtis Rader
a4ed0837a1 use new logmsg and set --show in tests 2017-08-04 12:51:48 -07:00
Kurtis Rader
e198ed0b2d use new logmsg and set --show in tests 2017-08-04 12:04:32 -07:00
Kurtis Rader
abc9be0250 use new logmsg and set --show in tests 2017-08-04 12:01:16 -07:00
Kurtis Rader
82ff27387a use new logmsg and set --show in tests 2017-08-04 11:41:51 -07:00
Kurtis Rader
03fa5dad12 use new logmsg and set --show in tests 2017-08-04 11:39:43 -07:00
Kurtis Rader
0c69e99d8b use new logmsg and set --show in tests 2017-08-04 11:02:11 -07:00
Kurtis Rader
26472593aa remove the now unused show test util function 2017-08-03 22:02:06 -07:00
Kurtis Rader
10fae1836e use new logmsg and set --show in tests 2017-08-03 22:02:06 -07:00
Kurtis Rader
864dbaeb43 use new logmsg and set --show in tests 2017-08-03 21:37:02 -07:00
Kurtis Rader
7619e62b70 use new logmsg and set --show in tests
Also modify `logmsg` to output additional separator lines to make the
demarcation between tests even clearer.
2017-08-03 21:25:20 -07:00
Kurtis Rader
ecf06f2eb4 use new logmsg and set --show in tests 2017-08-03 20:56:14 -07:00
Kurtis Rader
4197420f39 implement limits on command substitution output
This makes command substitutions impose the same limit on the amount
of data they accept as the `read` builtin. It does not limit output of
external commands or builtins in other contexts.

Fixes #3822
2017-08-03 17:40:25 -07:00
Kurtis Rader
e825415917 implement set --show
This adds a new capability to the `set` command. It is similar to
running `set` with no other arguments but provides far more detail about
each variable. Such as whether it is set in each of the local, global,
and universal scopes. And the values in each scope. You can also ask for
specific variables to be shown.

Fixes #4265
2017-08-03 15:49:52 -07:00
Kurtis Rader
b4ce749c69 the | tee /dev/stderr trick doesn't work on linux 2017-08-03 15:44:58 -07:00
Kurtis Rader
17dff8c569 rewrite abbr function
Rewrite the `abbr` function to store each abbreviation in a separate
variable. This greatly improves the efficiency. For the common case
it is 5x faster. For pathological cases it is upwards of 100x faster.
Most people should be able to unconditionally define abbreviations in
their config.fish without a noticable slow down.

Fixes #4048
2017-08-03 14:35:06 -07:00
Fabian Homborg
b1866b18dc Implement read --delimiter
This takes a string that is then split upon like `string split`.

Unlike $IFS, the string is used as one piece, not a set of characters.

There is still a fallback to IFS if no delimiter is given, that
behaves exactly as before.

Fixes #4156.
2017-07-28 12:15:46 +02:00
Kurtis Rader
0745f7dbe7 remove some uses of $IFS
This is a step towards resolving issue #4156. It replaces uses of `$IFS`
with other solutions.
2017-07-25 12:44:26 -07:00
Kurtis Rader
8e87d595b7 remove some uses of $IFS
This is a step towards resolving issue #4156. It replaces uses of `$IFS`
with other solutions.
2017-07-24 20:45:43 -07:00
Kurtis Rader
6f46f6b45a refactor set builtin
This completes the refactoring of the `set` builtin. It also removes a
seemingly never used feature of the `set` command. It also eliminates all
the lint warnings about this module.

Fixes #4236
2017-07-24 16:28:58 -07:00
Kurtis Rader
4f7a01af44 fix argparse handling of short flag only specs
@faho noticed that option specs which don't have a long flag name are
not handled correctly. This fixes that and adds unit tests.

Fixes #4232
2017-07-21 15:57:32 -07:00
Kurtis Rader
72968bec42 change how argparse handles boolean flags
When reporting whether a boolean flag was seen report the actual flags
rather than a summary count. For example, if you have option spec `h/help`
and we parse `-h --help -h` don't do the equivalent of `set _flag_h 3`
do `set _flag_h -h --help -h`.

Partial fix for #4226
2017-07-20 18:26:04 -07:00
Fabian Homborg
427b8f5c52 Comment and test that we shouldn't copy for blocks
Seems important.
2017-07-20 18:25:18 -07:00
Fabian Homborg
f2a6ae20e5 Test copying local-exported vars 2017-07-20 18:25:18 -07:00
Fabian Homborg
9ca6cb9fc8 Test that exported vars remain exported
I.e. the fix for #2611.
2017-07-20 18:25:18 -07:00
Kurtis Rader
4a7aa98e93 modify read to require at least one var
Fixes #4220
2017-07-20 13:07:30 -07:00
Kurtis Rader
2c77b24ced modify show test helper to work around BSD quirk
The BSD `seq` command handles `seq 0` weird.
2017-07-20 12:44:19 -07:00
Kurtis Rader
bb344bbd8f replace another custom show with the util func
Replace the `show_ary` function with the `show` test utility function.
2017-07-19 22:42:52 -07:00
Kurtis Rader
dc33c1afe1 change show test utility function
Due to how various tests show the status of variables I decided to
modify the `show` test utility function I recently added.
2017-07-19 22:28:24 -07:00
Kurtis Rader
4e1303823b add ability for argparse to validate args
Fixes #4211
2017-07-18 14:42:50 -07:00
Kurtis Rader
8f22def8f7 return to psub --file being the default
The recent change to switch `psub` to use `argparse` caused it to use
a fifo by default because it inadvertently fixed a long standing bug in
the fish script. This changes the behavior back to `psub --file` being
the default behavior and introduces a `--fifo` flag. It also updates the
documentation to make it clearer when and why `--fifo` mode should not
be used.

Fixes #4222
2017-07-17 14:33:51 -07:00
Kurtis Rader
3e226f0a5e implement a new implicit int option spec
While updating the `history` function to use `argparse` I realized it is
useful to define an option that can be used in three ways. First by
using the short flag; e.g., `-n NNN`. Second by using the long flag;
e.g., `--max NNN`. Third, as an implicit int flag; e.g., `-NNN`. This
use case is now supported by a spec of the form `n#max`.
2017-07-16 18:27:41 -07:00
Kurtis Rader
c22df3b823 update history to use argparse 2017-07-16 15:13:39 -07:00
Kurtis Rader
5dc78dd858 fix regression involving read from scripts
Fixes #4206
2017-07-15 21:21:24 -07:00
Kurtis Rader
f2c8e73891 add more alias unit tests
A recent regression to the `alias` command points out the need for more
unit tests of its behavior. I also decided to use it as an opportunity
to normalize the output of just `alias` to list aliases.
2017-07-15 17:36:36 -07:00
Kurtis Rader
98449fec51 fix math regression
The previous change to use `argparse` for parity with every other
builtin and function introduced a regression. Invocations that start
with a negative number can fail because the negative value looks like an
invalid flag.
2017-07-14 16:03:31 -07:00
Kurtis Rader
63d601610d implement -nnn style flags in argparse
This implements support for numeric flags without an associated short or
long flag name. This pattern is used by many commands. For example `head
-3 /a/file` to emit the first three lines of the file.

Fixes #4214
2017-07-13 20:36:59 -07:00
Kurtis Rader
c149f4f301 add argparse unit tests and fix some bugs
This implements some unit tests for the new `argparse` command and fixes
a couple of bugs those tests brought to light.

Fixes #4190
2017-07-12 22:38:32 -07:00
Kurtis Rader
a4dc2b872b implement fish_opt helper command
This implements a `fish_opt` command that provides a way for people
to create option specs for the `argparse` command as an alternative to
creating such strings by hand.

Fixes #4190
2017-07-12 22:38:32 -07:00
Kurtis Rader
80df9053b3 count -h should report 1
The count command should not treat any flag specially. Not even `-h` and
`--help`. It should simply return a count of the number of arguments it
received.

Fixes #4189
2017-07-05 17:24:34 -07:00