Commit Graph

212 Commits

Author SHA1 Message Date
ridiculousfish
e395a0eb69 Migrate PATH-completion logic from complete.cpp to expand.cpp
Prior to this fix, when completing a command that doesn't have a /, we
would prepend each component of PATH and then expand the whole thing. So
any special characters in the PATH would be interpreted when performing
tab completion.

With this fix, we pull the PATH resolution out of complete.cpp and
migrate it to expand.cpp. This unifies nicely with the CDPATH resolution
already in that file. This requires introducing a new expand flag
EXPAND_SPECIAL_FOR_COMMAND, which is analogous to EXPAND_SPECIAL_CD
(which is renamed to EXPAND_SPECIAL_FOR_CD). This flag tells expand to
resolve paths against PATH instead of the working directory.

Fixes #952
2016-04-07 20:15:32 -07:00
Aaron Gyes
790c7f80c7 Implement an --invert/-v for string match, like grep -v.
Only lines that do not match the pattern are shown.
2016-04-08 10:49:29 +08:00
Kurtis Rader
02f18cae0a fix setting of $argv for source w/no args
Fixes #139
2016-04-06 13:04:44 -07:00
Kurtis Rader
4ff8e6e781 change how redirections are formatted
Modify `fish_indent` to emit redirections without a space before the target of
the redirection; e.g., "2>&1" rather than "2>& 1" as the former is clearer to
humans.

Fixes #2899
2016-04-05 19:29:23 -07:00
Kurtis Rader
c2f1df1d4a fix handling of non-ASCII chars in C locale
The relevant standards allow the mbtowc/mbrtowc functions to reject
non-ASCII characters (i.e., chars with the high bit set) when the locale
is C or POSIX.  The BSD libraries (e.g., on OS X) don't do this but
the GNU libraries (e.g., on Linux) do. Like most programs we need the
C/POSIX locales to allow arbitrary bytes. So explicitly check if we're
in a single-byte locale (which would also include ISO-8859 variants)
and simply pass-thru the chars without encoding or decoding.

Fixes #2802.
2016-03-20 18:47:38 -07:00
Kurtis Rader
8b67a1b26f make testing on local servers hermetic
I noticed while fixing issue #2702 that the fish program being tested
was sourcing config.fish files outside of the current build. This also
happens when Travis CI runs the tests but isn't an issue there because
of how Travis is configured to execute the tests.

I also noticed that running `make test` was polluting my personal fish
history; which will become a bigger problem if and when the fishd universal
var file is moved from $XDG_CONFIG_HOME to $XDG_DATA_HOME.

This change makes it possible for an individual to run the tests on
their local machine secure in the knowledge that only the config.fish and
related files from their git repository will be used and doing so won't
pollute their personal fish history.

Resolves #469
2016-02-25 17:16:36 -08:00
Michael Steed
5b0996fd80 make fish compatible with pcre2 10.21
pcre2_substitute() now sets the output buffer length to PCRE2_UNSET (~0)
if the output buffer is determined to be too small. This change keeps
track of the buffer size separately where pcre2 can't touch it.

A better fix would be to let pcre2 tell fish what size buffer it needs.
This can be done with PCRE2_SUBSTITUTE_OVERFLOW_LENGTH, but this
requires pcre2 10.21 or later (released January 12), which may be too
new to introduce as a dependency at this point.

Fixes #2743
2016-02-21 19:32:08 -08:00
Kurtis Rader
83d3c9fc04 fix flakey test
I've run this more than twenty times through Travis CI (by adding/removing
a comment line). Without this tweak the longest sequence seems to be
around six successful runs.
2016-02-16 11:40:40 -08:00
Andreas Nordal
62b76b26b4 Reinstate failglob behaviour for most commands
Expand globs to zero arguments (nullglob) only for set, for and count.

The warning about failing globs, and setting the accompanying $status,
now happens regardless of mode, interactive or not.

It is assumed that the above commands are the common cases where
nullglob behaviour is desirable.
More importantly, doing this with `set` is a real feature enabler,
since the resulting empty array can be passed on to any command.

The previous behaviour was actually all nullglob (since commit
cab115c8b9), but this was undocumented;
the failglob warning was still printed in interactive mode,
and the documentation was bragging about failglob behaviour.
2016-02-15 13:13:28 -08:00
ridiculousfish
4c5aa8860a Update bind.expect for travis-CI
Travis-CI runs with clang ASAN enabled, which makes fish slow enough
that certain timing tests fail. Sleep a little so that fish can
catch up.
2016-02-04 16:33:02 -08:00
ridiculousfish
25ad8866c9 Merge change for lengthened and configurable escape key timeout 2016-02-04 13:56:49 -08:00
Kurtis Rader
2646d51a0b change default escape timeout
This changes the default escape timeout for the default keybindings (emacs
mode) to 300ms and the default for vi keybindings to 10ms.

I couldn't resist fixing a few nits in the fish_vi_key_bindings.fish file
since I was touching it to set the escape timeout.
2016-02-04 13:39:19 -08:00
Kurtis Rader
4e465ee04c make travis-ci happy again 2016-02-04 13:38:55 -08:00
ridiculousfish
1b8face1a3 Fix t-binding test for new escape behavior 2016-02-02 18:13:08 -08:00
ridiculousfish
b4a44deb7b Merge branch 'fix-jump' of git://github.com/cpick/fish-shell into cpick-fix-jump 2016-02-02 17:00:27 -08:00
Kurtis Rader
11785c2bf4 make bind unit tests more robust on travis-ci
My previous commit failed in the travis-ci environment despite passing on my
local computer. This appears to be due to expect timing out looking for the
expected input. See if increasing the expect timeout slightly fixes the
problem.
2016-01-17 19:14:54 -08:00
Kurtis Rader
4b9fece9f4 allow configuring the escape delay timeout
Introduce a "fish_escape_delay_ms" variable to allow the user to configure the
delay used when seeing a bare escape before assuming no other characters will
be received that might match a bound character sequence. This is primarily
useful for vi mode so that a bare escape character (i.e., keystroke) can
switch to vi "insert" to "normal" mode in a timely fashion.
2016-01-17 17:45:30 -08:00
Fabian Homborg
ed1919b266 abbr: Ensure we don't split on "=" if the given separator is " "
This fails on e.g. an abbr that uses `env a=b`, like the included test demonstrates.

Unfortunately it decreases the speed again (2s vs 2.2s vs 4s original),
but correctness is more important.
2016-01-14 16:58:29 +01:00
Fabian Homborg
fdb2559425 abbr tests: Don't expect quoted "--*"
This doesn't seem necessary given we already prefix it with "--".

If this is backed out, the part about using string escape also needs to be removed.
2016-01-14 16:58:29 +01:00
Kevin Ballard
1dac0041d5 Stop unescaping strings with commandline -b
The fix for #2075 inadvertently started unescaping the strings emitted
from `commandline -b`. Only strings emitted with the `-o` flag are
supposed to be unescaped.

Fixes #2210.
2016-01-10 17:25:22 -08:00
Kurtis Rader
6969cfab3d fix unit tests related to the escape timeout 2015-12-23 21:41:48 -08:00
ridiculousfish
594b460ba2 Allow and/or statements to attach to the if/while header
For example:

  if false; or true; echo hello; end

will output 'hello' now.

Fixes #1428
2015-12-19 14:49:07 -08:00
ridiculousfish
0a6f62358b Write tests for new if/and/or behavior (#1428)
They fail for now.
2015-12-19 11:32:57 -08:00
Eugene Sharygin
5db811253e psub: add -s, --suffix 2015-11-14 13:15:30 +01:00
David Adam
d3bcee9e2e tests: try longer timeout in case setting fish_key_bindings is taking too long 2015-10-30 13:31:02 +08:00
ridiculousfish
d5f3a09ce9 Make 'set -ql' search up to function scope
Previously 'set -ql' would only look for variables in the
immediate local scope. This was not very useful. It's also
arguably surprising, since a 'set -l' in a function, followed
by a 'set -ql' in a child block, would fail. There was also no
way to check for a function-scoped variable, since omitting the
scope would also pull in global variables.

We could revisit this and introduce an explicit function scope.

Fixes #2502
2015-10-23 15:15:39 -07:00
David Adam
55abe105ea tests/bind.expect: re-enable but at human typing speed only
The interactive bind tests work if the keys are treated like there is a
human pressing them.

This reverts commit 0006d23df8.
2015-10-18 21:12:12 +08:00
Fabian Homborg
0006d23df8 Disable the bind test for now
This isn't pretty, but it fails for, as far as I can see, no _real_
reason.

It doesn't seem to be possible to trigger the failure in real usage, no
matter how fast you press the ESC key followed by something else.

So now this is known and constant travis emails don't help it in any way.
2015-10-18 14:14:22 +02:00
David Adam
0b3406bdc0 tests/string.in: add tests for string builtin 2015-10-09 11:27:18 +08:00
Fabian Homborg
b85a8bbbfe Rename sgrep to __fish_sgrep
Makes it harder to cause issues with aliases, see fish-shell#2245
2015-09-09 20:55:04 +02:00
Chris Pick
ab6d9ad521 Test vi-mode 't' binding
Test 't' binding that contains non-zero arity function (forward-jump) followed
by another function (and).
This demonstrates the problem in #2357.
2015-09-03 15:15:46 -04:00
ridiculousfish
2109af0987 Implement lowercase-r replace in fish_vi_mode
Fixes #1595
2015-07-20 00:29:08 -07:00
ridiculousfish
4621e763b6 Fix wildcard expansion in directories without read permissions
When performing wildcard expansion with a literal path segment,
instead of enumerating the files in the directory, simply apply the
path segment as if we found the directory and continue on. This
enables us to expand strings that contain unreadable directory
components (common with $HOME) and also improves performance, since
we don't waste time enumerating directories unnecessarily. Adds
a test too.

Fixes #2099
2015-06-20 12:32:30 -07:00
ridiculousfish
d018ef39e1 Add abbreviation tests 2015-06-14 14:13:57 -07:00
ridiculousfish
f3560b8e62 Correctly un-export an env var when it is shadowed
Prior to this fix, if you exported a variable in one scope
and then unexported it in the next, it would remain exported.
Example:

    set -gx VAR 1
    function foo; set -l VAR; env; end
    foo

Here 'VAR' would be exported to 'env' because we failed to
notice that the env var is shadowed by an unexported variable.
This occurred at env var computation time, not in env_set!

Fixes #2132
2015-06-12 16:05:59 -07:00
ridiculousfish
286c60bc9d Correctly handle mixing named arguments with function name
Before this fix, `function -a arg1 name1` would produce a
function named 'arg1'. After this fix, it will produce a
function named 'name'. See #2068 for more.
2015-05-17 14:17:01 -07:00
ridiculousfish
534fd1a59e Pass the character index, not the character, to parse_util_expand_variable_error
Fixes #2067
2015-05-15 17:56:12 -07:00
ridiculousfish
3ca518255e Treat comments ending in backslashes as not continuing onto the next line
Fixes #1255
2015-05-02 18:22:20 -07:00
ridiculousfish
f30872a7b5 Recalculate exported variables when universal variable is erased
Fixes #2046
2015-04-29 17:28:49 -07:00
ridiculousfish
c3ef23b10f Support for a "pending item" in history.
Before running a command, we add the command to history, so
that if the command causes us to exit it's still captured in
history. But that command should not be considered part of
history when expanding the history within the command itself.
For example, `echo $history[1]` should be the previously
run command, not `echo $history[1]` itself.

Fixes #2028
2015-04-20 02:04:17 -07:00
ridiculousfish
9f8cec7f9e Add a test for issue #1987 2015-04-05 23:47:04 -07:00
ridiculousfish
d7ba6e4a1d Properly fire events for universal variable changes
Fixes #1929
2015-02-03 16:13:02 -08:00
ridiculousfish
7164769d33 Introduce tests for #1892 2015-01-17 15:22:37 -08:00
ridiculousfish
d4eded2376 Make octal/hex escapes in printf and echo output literal bytes
Fixes #1894
2015-01-15 11:21:07 -08:00
ridiculousfish
e045eabad6 Add tests to verify pipes do not conflict with fd redirections 2015-01-04 14:18:06 -08:00
ridiculousfish
a21db45cee Improve indentation of blocks inside if/while headers
Fixes #1665
2014-12-23 16:30:39 -08:00
ridiculousfish
6fa9a18a2b Correct path in fish_indent tests 2014-12-23 15:51:18 -08:00
ridiculousfish
da2e2c2e99 Implement tests for fish_indent 2014-12-23 15:46:47 -08:00
ridiculousfish
96589920d5 Allow running specific high-level tests by passing the name to test.fish
Example:
  tests/test.fish expansion
This will run the tests in expansion.in only
2014-12-23 12:20:44 -08:00
Kevin Ballard
94a3203c74 Disable localizations during tests 2014-11-25 01:44:58 -08:00
Kevin Ballard
184110c2e7 Revert "tests/status.in: fix test for locale, fall back to default strings"
This reverts commit 3b3fde1c5e.
2014-11-25 00:51:39 -08:00
David Adam
3b3fde1c5e tests/status.in: fix test for locale, fall back to default strings 2014-11-25 16:00:04 +08:00
Kevin Ballard
83df5ea660 Define a common mktemp for tests
GNU and BSD `mktemp` handle options differently, and it's a useful
utility for tests. As such, define a common `mktemp` function wrapper
for the test suite.

It might actually be nice to expand this for more flags and support it
globally, but that may result in confusion for any users of BSD mktemp
that expect to be running /bin/mktemp.
2014-11-24 01:51:07 -08:00
Kevin Ballard
e13d423b68 Tweak test runner to set up environment better
Update the test runners so they set up their own environment in
test_util.fish. This simplifies the Makefile and paves the way for
adding utility functions for use in the tests themselves.
2014-11-24 01:51:07 -08:00
ridiculousfish
c33a3862cc Disable printf %a test since it has different output on FreeBSD
Fixes #1139
2014-11-02 00:27:52 -07:00
ridiculousfish
6cc64fc9e3 BOM test should only run in UTF-8 locales 2014-11-02 00:14:16 -07:00
ridiculousfish
4b6639f697 Allow # within string tokens
This means that # must be the first character of the string
to start a comment, in line with other shells

Fixes #953
2014-11-01 21:06:16 -07:00
ridiculousfish
fa588db148 Fix to swallow BOMs in sourced files
Fixes #1518
2014-11-01 16:25:28 -07:00
ridiculousfish
a177eb8c16 Fix expansion tests on OS X 2014-10-30 21:51:23 -07:00
David Adam
ab7af98ded expand: expand tilde to canonical paths
Work on #1133.
2014-10-26 08:50:28 +08:00
ridiculousfish
9e32b330aa Unescape strings in keyword detection.
This allows keywords to be quoted. However, they may not contain
variable or process expansions, etc. Fixes #1398
2014-10-15 12:49:02 -07:00
ridiculousfish
1927ebbc5d Improve error reporting for unclosed blocks 2014-10-14 00:41:39 -07:00
ridiculousfish
c0b8e81b02 Change how arrays and environment variables interact.
Prior to this change, inherited environment variables
would be split on colons, becoming an array. This change
eliminates that behavior. Now environment variables are
always split on the record separator character (ASCII 0x1e),
with the exception of a short whitelist of PATH, MANPATH,
CDPATH. Likewise, exported variables are also exported
delimited by rs, with the exception of the above whitelist.

Fixes #1374, also see #1656
2014-10-12 15:01:44 -07:00
Kevin Ballard
a13e067b85 Fix test breakage from 14724401f
We can't use $PATHS to test the :-splitting because the global config
file adds extra paths based on /etc/paths and /etc/paths.d.

Ideally fish would have a way to suppress behavior like that, but for
the time being it doesn't.
2014-10-07 19:37:13 -07:00
David Adam
14724401ff env.cpp: correctly check variable_can_be_array
Closes #1746.
2014-10-08 09:53:29 +08:00
Kevin Ballard
33a76e1f8e Update psub for the new --inherit-variable flag
Also do some minor formatting cleanup, make psub return 1 when executed
outside of a command substitution, and make it respect $TMPDIR.
2014-10-02 18:41:39 -07:00
Kevin Ballard
cfc06203e7 Add new functions flag -V/--inherit-variable
--inherit-variable takes a variable name and snapshots its current
value. When the function is executed, it will have a local variable with
this value already defined. Printing the function source will include
synthesized `set -l` lines for the values.

This is primarily useful for functions that are created on the fly, such
as in `psub`.
2014-10-02 18:41:39 -07:00
Kevin Ballard
ae7b6156ac Rewrite fishscript testrunner for better output
Update the fishscript testrunner to use the same output style as the
interactive testrunner.
2014-10-02 12:33:42 -07:00
Kevin Ballard
3616dd5889 Base status -b off the parser execution stack
Instead of globally marking the state as "in block" when evaluating
blocks/functions, update the "in block" status when pushing/popping
blocks on the parser stack.

Fixes #1729.

On a side note, `status -b` is actually pretty useless, because it
always returns 0 inside of a function (even without this patch).
2014-09-30 20:58:45 -07:00
Kevin Ballard
51527612d3 Don't leave is_block in bad state after bad redirection
Fixes #1728.
2014-09-30 17:06:56 -07:00
Kevin Ballard
c4a453fb22 Try to fix the Travis test failures
It seems expect prioritizes the first pattern in the list, instead of
the pattern that matches earliest in the buffer. That seems pretty
stupid, but let's try moving the prompt pattern to the end and see if
that fixes the Travis failures.
2014-09-23 23:20:02 -07:00
Kevin Ballard
1563501868 Fix missing "1 test failed" line
Also tweak colored output to reset before the newline instead of after,
so travis behaves better (for some reason reset causes travis to display
the line in black).
2014-09-23 22:50:28 -07:00
Kevin Ballard
5f82f721d2 Rejigger test suite
Split test_interactive off from test_fishscript and add a new target
test_high_level that tests both.

Add some Makefile magic so the tests can be run serially without using
sub-make, which gets rid of a little noise from the make output.

Rewrite interactive tests to look better.
2014-09-23 22:39:23 -07:00
Kevin Ballard
a4059d3e60 Support wide characters in printf %c 2014-09-21 23:22:43 -07:00
Kevin Ballard
b480c8ce79 Allow U+F8FF to be typed
U+F8FF is the last character in the private use area, but it's also the
codepoint used for the Apple symbol (), which is typeable on US
keyboards in OS X, and so should actually work.
2014-09-21 21:03:44 -07:00
Kevin Ballard
a012aedb31 Fix incorrect error on read with 1-character input
When `read` is given a single character of input (including the
newline), it was bailing as if it had been given no input. This is
incorrect.
2014-09-21 20:00:26 -07:00
Kevin Ballard
c64f38f0bf Add extra logging for interactive test failures 2014-09-21 19:42:39 -07:00
Kevin Ballard
8f8c4cdd17 Implement new read --null flag
The `--null` flag to `read` makes it split incoming lines on NUL instead
of newlines. This is intended for processing the output of a command
that uses NUL separators (such as `find -print0`).

Fixes #1694.
2014-09-21 19:27:26 -07:00
Kevin Ballard
a069aec11d Squelch spurious set PATH errors in test 2014-09-20 00:35:51 -07:00
Kevin Ballard
8a3cf144f2 Don't include child directories of $PATH in completions
Directories are completed like commands, because of implicit cd.
However, directories found inside $PATH entries should not be completed,
as implicit cd doesn't work there. Similarly, directories should not be
completed after the `command` builtin.

Fixes #1695.
2014-09-20 00:31:33 -07:00
Kevin Ballard
940f264ee6 Decrement SHLVL when running exec
`exec` removes fish from the shell "stack", so SHLVL needs to be
decremented to match. This means `exec fish` will result in the same
SHLVL in the new fish instance.

Also tweak the SHLVL logic to interpret an environment SHLVL of "3foo"
as garbage instead of as the value "3".

Fixes #1693.
2014-09-19 17:38:54 -07:00
Kevin Ballard
51c2005ea2 Tweak interactive debug output 2014-09-19 16:22:37 -07:00
Kevin Ballard
510ff6a689 Dump interactive logs on travis test failure
As far as I know we can't access the build artifacts from Travis, so we
can't check the interactive logs after a test failure. Add an
environment variable that causes the test runner to dump the logs
itself, and set that variable for Travis.
2014-09-19 14:52:02 -07:00
Kevin Ballard
0a32d96b27 Reset fish_bind_mode when changing fish_key_bindings
Also avoid resetting bindings if fish_key_bindings is "modified" without
actually changing.

Fixes #1638.
2014-09-18 15:46:17 -07:00
Kevin Ballard
22fd8e65ad Disable fish_title on interactive tests
This was apparently what was interfering with the tests working on
Linux.

Tweak .travis.yml to install expect so the tests run on Linux.
2014-09-08 00:16:42 -07:00
Kevin Ballard
190712d4b0 Add a test harness for interactive behavior
Add a test harness that uses `expect` to drive Fish to test interactive
behavior.

Include some tests for `read`.
2014-09-07 23:56:59 -07:00
Kevin Ballard
efb1467e4e Cleanup fish tests a bit
Split `make test` into two targets `make test_low_level` and `make
test_fishscript`, primarily so fishscript tests can be rechecked quickly
after edits.

Reformat the test.fish file and update some of the code to be a little
more straightforward (e.g. `if not cmd` instead of `if cmd; else`).
2014-09-07 23:50:44 -07:00
Joseph Tannhuber
4acea72700 New -n option for read builtin
Usage: read -n nchars
Reads maximum of nchars characters. If nchars <= 0, there's no limit.
2014-09-03 22:48:37 -07:00
Kevin Ballard
1c4223889b Fix test output for complete -e tests
GNU sort behaves stupidly when LC_ALL is not C. This caused the test
output to be sorted wrong.
2014-09-02 15:52:56 -07:00
Kevin Ballard
90a4fd34d2 Add tests for the various complete -e changes 2014-09-02 15:30:58 -07:00
Kevin Ballard
7fce9e2411 Trim trailing newline on cmdsubst when IFS=''
When $IFS is empty, command substitution no longer splits on newlines.
However we still want to trim off a single trailing newline, as most
commands will emit a trailing newline and it makes it harder to work
with their output.
2014-08-29 12:48:45 -07:00
Kevin Ballard
130619d6b0 Fix $SHLVL
Due to being read-only, SHLVL wasn't being incremented properly for
recursive invocations of fish.
2014-08-29 12:22:35 -07:00
ridiculousfish
0b7735d279 Merge pull request #1630 from kballard/expand_variables_in_quoted_strings
Fix various expansions issues with variables
2014-08-23 16:13:25 -07:00
ridiculousfish
033373f078 Merge branch 'make_type_better' of github.com:kballard/fish-shell into kballard-make_type_better 2014-08-21 21:36:39 -07:00
Kevin Ballard
2974025010 Fix error span for invalid slice indexes
The span now properly points at the token that was invalid, rather than
the start of the slice.

Also fix the span for `()[1]` and `()[d]`, which were previously
reporting no source location at all.
2014-08-21 01:10:07 -07:00
Kevin Ballard
cc49042294 Parse slices even for empty variables
When a variable is parsed as being empty, parse out the slice and
validate the indexes anyway, behaving for slicing purposes as if the
variable had a single empty value.

Besides providing errors when expected, this also fixes the following:

    set -l foo
    echo "$foo[1]"

This used to print "[1]", now it properly prints nothing.
2014-08-20 22:09:32 -07:00
Kevin Ballard
3981b644d6 Fix double expansions ($$foo)
Double expansions of variables had the following issues:

* `"$$foo"` threw an error no matter what the value of `$foo` was.
* `set -l foo ''; echo $$foo` threw an error because of the expansion of
  `$foo` to `''`.

With this change, double expansion always works properly. When
double-expanding a multi-valued variable, in a double-quoted string the
first word of the inner expansion is used for the outer expansion, and
outside of a quoted string every word is used for the double-expansion
in each of the arguments.

    > set -l foo bar baz
    > set -l bar one two
    > set -l baz three four
    > echo "$$foo"
    one two baz
    > echo $$foo
    one two three four
2014-08-20 21:45:07 -07:00
ridiculousfish
52ae5f885e Improve history robustness against corrupt files
Fixes #1581
2014-07-29 14:42:03 -07:00
Kevin Ballard
973dd6ffbd read: Support arrays, character splitting
Enhance the `read` builtin to support creating an array with the --array
flag. With --array, only a single variable name is allowed and the
entire input is tokenized and placed into that variable as an array.

Also add custom behavior if IFS is empty or unset. In that event, split
the input on every character, instead of the previous behavior of doing
no splitting at all.
2014-07-14 00:46:38 -07:00
Kevin Ballard
cfa13ed84c Update tests for new type behavior
One of the tests was using `>/dev/null` to suppress the `type` output.
That needs to be `^/dev/null` now, but instead just go ahead and use the
new `-q` flag.
2014-07-13 19:11:29 -07:00