Commit Graph

996 Commits

Author SHA1 Message Date
Soumya
518170b299 Also call fish_job_summary for foreground sigint
The default implementation will not print any output in that case, but this provides users with additional flexibility when it comes to customising the shell's behaviour.
2020-05-19 20:39:10 +02:00
Soumya
324fa64114 Add fish_job_summary, called whenever a job ends, stops, or is signalled
This allows users to customise the behaviour of the shell by redefining the function. This is similar to how fish_title or fish_greeting behave, where the default implementation can be easily overridden.

The function receives as arguments the job id, command line, signal name and signal description.
2020-05-19 20:39:10 +02:00
Fabian Homborg
56f24f08d7 printf: Don't print an error if not given an argument 2020-05-18 20:48:36 +02:00
Johannes Altmanninger
e03c375ee3 Purge remnants of process expansion, document {fish,last}_pid 2020-05-16 11:58:12 +02:00
Johannes Altmanninger
49c5f96470 Use set -l to force use of a local variable
Bare set overwrites a global/universal variable if it exists.
2020-05-15 08:25:07 +02:00
Fabian Homborg
e390ee12c2 Disable flaky pipeline-pgroup test
This fails *a lot* on Travis, obscuring other tests.

As far as we can tell, a newline is somehow sneaking in here.

See #6693
2020-05-07 21:19:28 +02:00
ridiculousfish
82f2d86718 Thread pgroups into builtin_eval
Ensure that if eval is invoked as part of a pipeline, any jobs spawned
by eval will have the same pgroup as the parent job.

Partially fixes #6806
2020-04-26 11:05:50 -07:00
ridiculousfish
938b683895 Thread pgroups into command substitutions
Give string expansion an (optional) parent pgroup. This is threaded all
the way into eval(). This ensures that in a mixed pipeline like:

   cmd | begin ; something (cmd2) ; end

that cmd2 and cmd have the same pgroup.

Add a test to ensure that command substitutions inherit pgroups
properly.

Fixes #6624
2020-04-26 11:05:50 -07:00
Fabian Homborg
6990c44443 Shorten set --show output
Changes it from

```
$fish_color_user: not set in local scope
$fish_color_user: set in global scope, unexported, with 1 elements
$fish_color_user[1]: length=3 value=|080|
$fish_color_user: set in universal scope, unexported, with 1 elements
$fish_color_user[1]: length=7 value=|brgreen|

```

(with the trailing empty line - not just a newline)

to

```
$fish_color_user: set in global scope, unexported, with 1 elements
$fish_color_user[1]: |080|
$fish_color_user: set in universal scope, unexported, with 1 elements
$fish_color_user[1]: |brgreen|
```
2020-04-26 08:49:01 +02:00
Jason Nader
6a839519b9 string split: add --allow-empty flag to be used with --fields 2020-04-20 22:39:48 +02:00
Jason Nader
3bb86d3a61 string split --fields: handle multi-line/arg input 2020-04-20 22:39:48 +02:00
Johannes Altmanninger
23427f3168 Add test for ~ (togglecase-char and togglecase-selection) 2020-04-19 05:51:25 +02:00
ridiculousfish
3e8422f472 terminal_maybe_give_to_job to stop returning error on ENOTTY
Prior to this fix, if job control is enabled but stdin is not a tty, we
would return an error from terminal_maybe_give_to_job which would cause us
to avoid waiting for the job. Instead just return notneeded.

Fixes #6573.
2020-04-18 16:26:54 -07:00
Johannes Altmanninger
be36c96028 alias.fish: unbreak listing aliases without backslashes
The description for an alias which already has escape sequences will
use backslash escapes for quoting; usually `string escape` can simply
quote it.  Use a regex that accepts either escaping style.
2020-04-18 09:35:33 +02:00
Johannes Altmanninger
77d33a8eb9 Ignore SIGINT and SIGQUIT in non-interactive background processes
Fixes #6828
2020-04-07 22:18:15 +02:00
Fabian Homborg
f0f162f07e argparse test: Tighten regex against travis' shenanigans
Travis puts the commit message in an environment variable, so if it
contains the string `_flag` this would match TRAVIS_COMMIT_MESSAGE.

That happened in ca91c201c3, so the
tests failed.

We simply tighten the regex a little more, and make a commit message
that doesn't include the string.
2020-04-06 19:57:22 +02:00
Fabian Homborg
5dfaff4281 Make "." a builtin as well
Yeah, it's not going anywhere. This is one line in builtin.cpp vs 9
lines of script, most of which used to print an error that is never triggered.
2020-04-06 18:55:59 +02:00
Jason Nader
21bbd2ecb4 Return 1 if non-existent field is given 2020-04-04 15:30:09 +02:00
Jason Nader
1329a40e87 Allow simple ranges to be specified for --fields 2020-04-04 15:30:08 +02:00
Jason Nader
7cb1d3a646 Add string split --fields 2020-04-04 15:30:08 +02:00
Fabian Homborg
a29bc127ce Move the invocation checks to invocation.fish
These where separate files so we could use the %s substitution to run
that fish, but since discovering setting $fish that
workaround isn't necessary.
2020-04-04 13:31:48 +02:00
Fabian Homborg
d54609bd63 Skip interactive tests on github actions for now
Github actions doesn't run this in a terminal, so the `fish -i` tests won't really work.

But still, it might be nicer than Travis.
2020-04-04 13:31:48 +02:00
Soumya
61a9cdaa74 Add $fish_kill_signal to track the signal that terminated a command.
Set to `0` if the command exited normally.
2020-04-02 09:32:32 +02:00
Fabian Homborg
1c880e5888 tests: Specify which tests completed successfully
It's a bit weird to just see "All tests completed successfully" and
then another set of tests follows.
2020-03-28 18:41:44 +01:00
Fabian Homborg
917f26b1dd tests/interactive.fish: Match littlecheck's coloring
Littlecheck resets the color before the time, which looks a bit nicer.

But most of all, it's inconsistent.
2020-03-28 18:40:57 +01:00
Fabian Homborg
82977f07a0 test.fish: Remove mention of ".in" files 2020-03-28 18:29:21 +01:00
Fabian Homborg
3a1bc33cad tests: Remove leftover reference to "../test/root/bin/fish"
We have that in a variable now.
2020-03-28 15:46:47 +01:00
Johannes Altmanninger
6699a72e0e Handle child receiving SIGCONT
Fixes #6818
2020-03-27 20:30:58 +01:00
Soumya
96563d6eff jobs: suppress "No suitable job" if -q is given
This allows code of the form `if jobs -q $some_pid` in scripts to check whether a previously started job is still running. Previously this would return the correct value, but also print an error message.

The invalid argument errors will still be printed.
Added test cases for both.
2020-03-26 17:09:09 +01:00
Johannes Altmanninger
0a2eea4cc6 Invert test for implicit cd after builtin command
Because `command ./somedir/somecommand` is okay.

Fixes test failure from aa304cbd3d.

Child directories in $PATH are still not suggested, as was the main
intention of the commit that introduced the tests:
8a3cf144f Don't include child directories of $PATH in completions.
2020-03-24 22:02:27 +01:00
George Christou
a3436110c1
Add string sub --end (#6765) 2020-03-22 15:53:09 +01:00
Fabian Homborg
179d92452d Resurrect one last function
So *that's* where "r2l" is used!
2020-03-17 21:58:49 +01:00
Fabian Homborg
b7b09add95 Revert complete_directories change
Turns out my test dir wasn't as clean as it should have been.
2020-03-17 21:45:49 +01:00
Fabian Homborg
04bc16530c Ressurect a couple of test functions
Missed these, sorry!
2020-03-17 21:44:26 +01:00
Fabian Homborg
4d052da922 Remove classic ".in" test machinery
We have now entirely switched the script tests to littlecheck.

Note: This adjusts the complete_directories test, because it removes a
directory that was created before by a .in test. There's no real
change in behavior.

This does require the test directory be cleaned, or the tests will fail.

test_util gets to stay for a while longer, because it sets up the
testing env (locale and such).
2020-03-17 21:34:36 +01:00
Fabian Homborg
957526a283 Port "test9" to littlecheck
Just add it to basic.fish

This was the last .in test.
2020-03-17 21:19:41 +01:00
Fabian Homborg
fbf9d4e6f8 Port "test7" to littlecheck
Soon.
2020-03-17 20:57:45 +01:00
Fabian Homborg
e78db2bcb8 Port "test1" to littlecheck
This, together with the other testX, really just tests some basic
syntax. So let's just call it "basic".

Note that this file uses escaped newlines on purpose, so restyling it
would currently break it. I'm not sure what the best thing to do here is.
2020-03-17 20:48:40 +01:00
Fabian Homborg
2731bcec70 Port umask tests to littlecheck
This saves us from adding all these explanatory echoes.
2020-03-16 21:21:10 +01:00
Fabian Homborg
52b5afe2f8 Port expansion test to littlecheck
This one really is a lot easier to follow
2020-03-16 21:21:10 +01:00
Fabian Homborg
7e594e692c Port fish_indent tests to littlecheck 2020-03-16 21:21:10 +01:00
ridiculousfish
5f0c698601 Pass all check files to littlecheck at once
Instead of invoking littlecheck.py independently for each file, pass
all files at once. This amortizes the Python startup cost, and reduces
the total test time by ~15 seconds (!).
2020-03-15 18:16:14 -07:00
Fabian Homborg
aa629c5aca Reformat fish scripts with escaped newline changes to fish_indent 2020-03-15 21:01:11 +01:00
Fabian Homborg
7891973c9c fish_indent: Add check
This isn't quite the old-style test, but it checks some of the line
continuation stuff.

Note that littlecheck ignores leading whitespace, so testing the
actual indentation requires some more effort.
2020-03-15 21:01:11 +01:00
Fabian Homborg
cb16d9e741 fish_indent: Allow escaped newlines only for certain things
Things like

```fish
\
echo foo
```

or

```fish
echo foo; \
echo bar
```

are a formatting blunder and should be handled.

This makes it so the escaped newline is removed, and the
semicolon/token_type_end handling will then put the statements on
different lines.

One case this doesn't handle brilliantly is an escaped newline after a
pipe:

```fish
echo foo | \
cat
```

is turned into

```fish
echo foo | cat
```

which here works great, but in long pipelines can cause issues.

Pipes at the end of the line cause fish to continue parsing on the
next line, so this can just be written as

```fish
echo foo |
cat
```

for now.
2020-03-15 21:01:00 +01:00
ridiculousfish
3040486968 Use -S when invoking Python for littlecheck
This prevents needless imports. It speeds up the test time by ~2 seconds.
2020-03-09 15:08:33 -07:00
Fabian Homborg
9f984ee897 Reindent final check
This included some things in its string, so `fish_indent` would stomp
over it.
2020-03-09 19:46:43 +01:00
Fabian Homborg
9367d4ff71 Reindent functions to remove useless quotes
This does not include checks/function.fish because that currently
includes a "; end" in a message that indent would remove, breaking the test.
2020-03-09 19:46:43 +01:00
Fabian Homborg
b25f72f391 Teach fish_indent to remove useless quotes
This tries to see if quotes guard some expansion from happening. If it
detects a "weird" character it'll leave the quotes in place, even in
some cases where it might not trigger.

So

    for i in 'c' 'color'

turns into

    for i in c color

The rationale here is that these quotes are useless, wasting
space (and line length), but more importantly that they are
superstitions. They don't do anything, but look like they do.

The counter argument is that they can be kept in case of later
changes, or that they make the intent clear - "this is supposed to be
a string we pass".
2020-03-09 19:46:43 +01:00
ridiculousfish
5886b961d8 Send events more often for variable sets outside of builtin_set
When changing certain variables programmatically, ensure that events
are sent. Fixes #6653
2020-03-08 23:28:37 -07:00
ridiculousfish
29c2bce704 Use self-insert-notfirst on spaces during paste
This changes a5a643f854 to use the new self-insert-notfirst binding.
It also adds a test.
2020-03-07 13:31:55 -08:00
Norio Nomura
60fca97523 Add test to verify that the fish_postexec handler is called after SIGINT 2020-03-03 21:49:15 -08:00
ridiculousfish
17c569f6d5 Disable SIGINT handling expect test
The problem is that under TSAN, the timing of signals becomes very weird and
exposes some real race conditions. We will need to re-design how signal
event handlers work.
2020-03-03 18:15:24 -08:00
ridiculousfish
593c43663c Add a bit of a delay to signals.expect test
Unclear why this is needed.
2020-03-03 10:52:16 -08:00
ridiculousfish
b0c2eda3b4 Revert "Revert "Enable job-control in pipeline-pgroup test""
This reverts commit c9f450a93e.

Puts back job-control in this test.
2020-03-02 14:01:59 -08:00
ridiculousfish
1c5b1ff5c2 Correct a race condition in pipeline-pgroup test
This test launches two background processes and is sensitive to
interleaving of output. Fix it so that newlines are not output by
the background process.

Hopefully this fixes the flakiness of this test.
2020-03-02 14:00:57 -08:00
ridiculousfish
c9f450a93e Revert "Enable job-control in pipeline-pgroup test"
This reverts commit cdbf0a9d20.

Reverting until the tests pass consistently.
2020-03-01 23:35:53 -08:00
ridiculousfish
bc702ccb31 Fix interactive --on-signal INT handlers
f8ba0ac5bf introduced a bug where INT handlers would themselves be
cancelled, due to the signal. Defer processing handlers until the
parser is ready to execute more fish script.

Fixes the interactive case of #6649.
2020-03-01 13:31:59 -08:00
ridiculousfish
cdbf0a9d20 Enable job-control in pipeline-pgroup test
Otherwise it's not testing anything interesting
2020-02-29 18:00:19 -08:00
ridiculousfish
c5fa580948 Rationalize background-in-background procs
If a background process runs a fish function which launches another
background process, ensure that these background procs get different
pgroups. Add a test for it.
2020-02-29 15:07:09 -08:00
Johannes Altmanninger
706c1a838e Fix tests for 91fcb8c42c 2020-02-29 10:48:19 +01:00
Johannes Altmanninger
91fcb8c42c Revert "read: discard IFS delimiters before the last token"
See #6650.

This reverts commit 1410f938aa.
2020-02-29 09:53:53 +01:00
Fabian Homborg
22c0054c1e Add check to test all fish files with -n
This executes `fish --no-execute` a whole bunch of times in order to
find syntax errors in our fish scripts.

tests/ is exempt because it contains syntax errors on purpose.

This is a great idea in principle, but it takes ~4s on my system.
2020-02-26 19:15:50 +01:00
Fabian Homborg
70b8fb22e1 test: Reject nan/inf instead of crashing
I really don't want to get into the business of explaining to people
how nan != nan.

Fixes #6655.
2020-02-26 16:43:12 +01:00
Johannes Altmanninger
ccd3ac4f18 fixup test
only works interactively
2020-02-24 00:21:23 +01:00
Johannes Altmanninger
aa0e16b1a5 Skip variable assignments in status current command
Fixes #6635
2020-02-24 00:16:12 +01:00
Johannes Altmanninger
7ef7f93a90 List time as builtin, support time --help
`a=b time foo` will no longer call an external `time` command
(like it does in bash).

Fixes #6598
2020-02-23 23:42:57 +01:00
Fabian Homborg
5f9c33b50a Don't time --no-execute
This made some output for non-execution.

See #977.
2020-02-17 11:39:53 +01:00
Fabian Homborg
3f5c60e634 Silence some errors for fish --no-execute
It used to error out when a command wasn't known, even when it was a
function that would only be discovered via autoloading.

Now we just accept that a command doesn't exist when no-execute is
given - we're not gonna execute it anyway.

Also, in the same breath stop counting empty commands after expansion
and empty wildcard expansions as errors - these depend on runtime
values, so we can't verify them without executing.

Fixes #977.

(note that it still executes "time", but that's another commit)
2020-02-17 11:39:53 +01:00
Fabian Homborg
aba900a71f Reallow "2>>&1" as a redirection
Appending to an fd doesn't really make sense, but we allowed the
syntax previously and it was actually used.

It's not too harmful to allow it, so let's just do that again.

For the record: Zsh also allows it, bash doesn't.

Fixes #6614
2020-02-17 08:57:41 +01:00
Johannes Altmanninger
7517128b68 Update exports when an exported universal variable changes
Fixes #6612
2020-02-16 18:51:19 +01:00
Fabian Homborg
13b470af07 Readd ^&1 redirection
This was lost in 35671dd9f0.

Even tho we plan to drop caret redirection, while it's there it should
fully work.

Fixes #6591.
2020-02-14 20:28:46 +01:00
Fabian Homborg
0d2c11249e Ignore unreadable cwd error harder
Should fix the tests on macOS.
2020-02-14 20:09:07 +01:00
Fabian Homborg
f053cd27c6 Return glob ordering to pre-3.1 state
Glob ordering is used in a variety of places, including figuring out
conf.d and really needs to be stable.

Other ordering, like completions, is really just cosmetic and can
change if it makes for a nicer experience.

So we uncouple it by copying the wcsfilecmp from 3.0.2, which will
return the ordering to what it was in that release.

Fixes #6593
2020-02-14 19:06:19 +01:00
Fabian Homborg
7c879ed356 Let test for unreadable cwd work on macos
It has a different error. We don't care, we expect an error.
2020-02-14 18:34:07 +01:00
Fabian Homborg
ceba851d44 parser: Stop crashing when cwd isn't readable
Everything seems to be working, so instead of crashing just print an
error and return.

Fixes #6597
2020-02-14 17:57:07 +01:00
ridiculousfish
35a50d5aff Clean up the "press a key" prompt in fish_key_reader
No need for two newlines.
2020-02-13 01:08:35 -08:00
Fabian Homborg
6cccfa7cf4 tests/read: Make an error more useful
It would be nice to know what the length *is* if it's not the max.
2020-02-12 22:02:32 +01:00
Fabian Homborg
860394d1bd tests/pipestatus: Allow for command false to return 255
SOLAAAAAARIIIIIISSS!
2020-02-12 22:02:32 +01:00
Aaron Gyes
d556f04823 Revert "timer.cpp: use units like 'ms', etc. vs. "millis""
This reverts commit c01356ddd1.

Tests broken
2020-02-12 02:06:30 -08:00
Aaron Gyes
c01356ddd1 timer.cpp: use units like 'ms', etc. vs. "millis"
Change wording and omit '.00' decimal points in times
2020-02-12 01:53:48 -08:00
Johannes Altmanninger
be06f842a2 Allow to omit indices in index range expansions
Missing range limits in, say $PATH[..] default to the first/last
element, just like Python/Go/Rust slices.
2020-02-10 18:38:01 +01:00
ridiculousfish
6bf9ae9aeb Fix up --on-job-exit caller
The `function --on-job-exit caller` feature allows a command substitution
to observe when the parent job exits. This has never worked very well - in
particular it is based on job IDs, so a function that observes this will
run multiple times. Implement it properly.

Do this by having a not-recycled "internal job id".

This is only used by psub, but ensure it works properly none-the-less.
2020-02-08 16:23:25 -08:00
Fabian Homborg
f67a9f2ee7 Port another part of test1 to littlecheck
This time it's redirections
2020-02-08 18:21:05 +01:00
Fabian Homborg
5e6c9508e9 Port a part of test1 to littlecheck
Test1 is a grab bag of stuff, so we need to separate it.

This part is concerned with for-loops, so we move it to loops.fish
2020-02-08 17:49:02 +01:00
Fabian Homborg
ee8ca246f8 Port test8 to littlecheck
This one tests a bunch of separate stuff, so we put it into a few
different files.

The main, new one is "slices.fish", which tests various index expressions.
2020-02-08 15:55:10 +01:00
Fabian Homborg
22edf3213f Port "test4" to littlecheck
It has to do with scoping, so call it "scoping.fish".
2020-02-08 15:54:58 +01:00
Fabian Homborg
6daab9c41f Port while test to littlecheck
And we're gonna add more loop stuff, so port it to a file called "loop.fish"
2020-02-08 15:21:22 +01:00
Fabian Homborg
0ddbd8d318 Fix typo in bad options test
This had a stray `}`, which made one possible message:

    unknown option -- Z}

with a literal `}`, which broke on NetBSD, which has that
message.
2020-02-08 13:30:48 +01:00
Fabian Homborg
cdf6260d70 Port fish_opt tests to littlecheck
It's a wrapper for argparse, so just put it in argparse.fish.
2020-02-08 12:34:43 +01:00
Fabian Homborg
849f27912e Port parameter_expansion test to littlecheck
Just put it in expansion.fish.
2020-02-08 11:16:53 +01:00
Fabian Homborg
e9b4f5f0ab Replace references to ".../test/root/bin/fish" in the checks 2020-02-08 11:06:36 +01:00
Fabian Homborg
884f347be6 Port "test6" to littlecheck
It's related to `complete`, so put it in complete.fish
2020-02-08 10:55:59 +01:00
Fabian Homborg
109a8b07a7 Port "test5" to littlecheck
Put the switch-related stuff in switch.fish, and the wildcard-related
stuff in wildcard.fish.
2020-02-08 10:53:50 +01:00
Fabian Homborg
e3ccc310e2 Port read test to littlecheck
This was a tad annoying because of all the messing with variables, and
because I insisted on getting it all into the existing read.fish.
2020-02-08 10:38:43 +01:00
Fabian Homborg
bf7629462a Port some small tests to littlecheck 2020-02-08 10:38:11 +01:00
Fabian Homborg
8bd97d087d Port set test to littlecheck
Just add it to set.fish. There may be some duplicated ones here, but
that's for another time.
2020-02-08 09:58:27 +01:00
Fabian Homborg
0ddf04b637 Port contains_opt test to littlecheck
And make it one file.
2020-02-08 09:51:52 +01:00
Fabian Homborg
7c2d7387d0 Port complete_directories test to littlecheck 2020-02-08 09:48:41 +01:00
Fabian Homborg
2fa8ae161a Port jobs test to littlecheck 2020-02-08 09:47:14 +01:00
Fabian Homborg
0fab1ce8b4 Port locale test to littlecheck 2020-02-08 09:38:23 +01:00
Fabian Homborg
f8af262af7 Port some smaller tests to littlecheck 2020-02-08 09:31:49 +01:00
Fabian Homborg
eaf84c553d Port line-continuation test to littlecheck 2020-02-08 09:31:49 +01:00
Fabian Homborg
e40441f901 Port history tests to littlecheck 2020-02-07 20:53:20 +01:00
Fabian Homborg
15d2797ec1 Port pipestatus test to littlecheck 2020-02-07 20:49:42 +01:00
Fabian Homborg
fc884e9cf4 Port function.in test to littlecheck 2020-02-07 20:41:01 +01:00
Fabian Homborg
921fce3a51 math: Complain about unknown *function*, not *variable*
We removed variables from tinyexpr, so we shouldn't use that error.
2020-02-07 17:43:22 +01:00
ridiculousfish
bd06a9aa6c Retain leading spaces in non-expanding braces
This makes two changes:

1. Remove the 'brace_text_start' idea. The idea of 'brace_text_start' was
to prevent emitting `BRACE_SPACE` at the beginning or end of an item. But
we later strip these off anyways, so there is no apparent benefit. If we
are not doing brace expansion, this prevented emitting whitespace at the
beginning or end of an item, leading to #6564.

2. When performing brace expansion, only stomp the space character with
`BRACE_SPACE`; do not stomp newlines and tabs. This is because the fix in
came from a newline or tab literal, then we would have effectively
replaced a newline or tab with a space, so this is important for #6564 as
well. Moreover, it is not easy to place a literal newline or tab inside a
brace expansion, and users who do probably do not mean for it to be
stripped, so I believe this is a good change in general.

Fixes #6564
2020-02-04 11:49:12 -08:00
ridiculousfish
97c456a986 Improve support for job control in non-interactive scenarios
Avoid complaining about ENOTTY results from tcsetpgrp, and ensure we
ignore SIGTTOU the first time job control is enabled.
2020-01-30 15:18:10 -08:00
Fabian Homborg
e8000cfea9 Add Solaris' error message to a test
Just another version of the error. We still want to get a bug if it
ever triggers a *wrong* error, so we still list all the options
instead of going for `.*option:.*Z.*`.

Fixes #6554
2020-01-30 18:07:03 +01:00
Fabian Homborg
9cbd3d57a0 Tests: Don't remove a parent of $PWD
Solaris/OpenIndiana/Illumos `rm` checks that and errors out.

In these cases we don't actually need it to be a part of $PWD as
it's just for cleanup, so we `cd` out before.

See #5472
See 1ee57e9244
Fixes #6555
Fixes #6558
2020-01-30 17:34:48 +01:00
ridiculousfish
7a2a6d76f3 Migrate a test from C++ to littlecheck
This eliminates noisy warnings about tcsetpgrp when the tests are run
without a tty, as reported in #6539
2020-01-26 20:59:08 -08:00
Fabian Homborg
3bb15defbb
Replace debug() with flog
PR #6511 

Flog has the advantage of having *categories*, not severities, so it'll be easier to get output for a certain subsystem now.
2020-01-26 14:13:17 +01:00
ridiculousfish
38f4330683 Rationalize $status and errors
Prior to this fix, fish was rather inconsistent in when $status gets set
in response to an error. For example, a failed expansion like "$foo["
would not modify $status.

This makes the following inter-related changes:

1. String expansion now directly returns the value to set for $status on
error. The value is always used.

2. parser_t::eval() now directly returns the proc_status_t, which cleans
up a lot of call sites.

3. We expose a new function exec_subshell_for_expand() which ignores
$status but returns errors specifically related to subshell expansion.

4. We reify the notion of "expansion breaking" errors. These include
command-not-found, expand syntax errors, and others.

The upshot is we are more consistent about always setting $status on
errors.
2020-01-25 17:28:41 -08:00
ridiculousfish
8a9c39d433 Add a test for some 'status' subcommands 2020-01-25 14:10:45 -08:00
ridiculousfish
788f359cda Make the cd check more robust on macOS
macOS `mktemp -d` likes to return symlinks. Guard against that possibility.
That allows the test to succeed when run directly, instead of through the
build target.
2020-01-25 12:59:18 -08:00
Fabian Homborg
cf508ee228 tests/job-ids: Wait for job to die
It was possible to start the new job and execute `jobs` again before
the job died (or we noticed it did), so the test would fail.

To properly test, we need to ensure the job has been removed. `wait`
should do it.
2020-01-25 14:06:34 +01:00
ridiculousfish
b99546e7a0 Port cmdsub tests to littlecheck 2020-01-24 15:03:59 -08:00
ridiculousfish
2af710f7c0 Eliminate expand_result_t::wildcard_match
This was an internal implementation detail that all callers had to deal
with. Just get rid of it.
2020-01-22 11:49:59 -08:00
Jason Nader
1cafc4eff6 Amend comments incorrectly referring to sed 2020-01-22 17:40:31 +01:00
Fabian Homborg
65397d4f5e Fix tests
By changing to flog I inadvertently changed the warning text from "<W>
fish:" to "warning:".

Since that's also okay, let's leave it.
2020-01-19 15:07:06 +01:00
ridiculousfish
d38db1bc61 Add a test for deep command substitutions 2020-01-18 11:50:50 -08:00
Johannes Altmanninger
b18f605e4f Fix completions if previous arg is a variable
complete -C'echo $HOM ' would complete $HOM instead of a new token.
Fixes another regression introduced in
6fb7f9b6b - Fix completion for builtins with subcommands
2020-01-18 20:21:10 +01:00
Fabian Homborg
14fd4570d5 Test using more than 64 threads
See #6503
2020-01-18 10:43:59 +01:00
Johannes Altmanninger
b62fa53807 set error code on failed command substitution to 255 instead of -1
the exit status ought to be in 0-255, e.g. exit -1
2020-01-17 17:36:18 +01:00
Johannes Altmanninger
05ddda9155 use variable assignments on commandline in completions
Fixes #6507

To do: If a variable assignment uses a command substitution that errors,
the error is printed, but without a proper location.
2020-01-17 14:53:35 +01:00
ridiculousfish
1da09f2c52 Ensure new job IDs are never smaller than existing running jobs
This makes job IDs "monotone" in the sense that newly spawned jobs
always have larger IDs than existing jobs, as requested in #6053
2020-01-16 16:01:29 -08:00
Fabian Homborg
69b464bc37 Run fish_indent on all our fish scripts
It's now good enough to do so.

We don't allow grid-alignment:

```fish
complete -c foo -s b -l barnanana -a '(something)'
complete -c foo -s z              -a '(something)'
```

becomes

```fish
complete -c foo -s b -l barnanana -a '(something)'
complete -c foo -s z -a '(something)'
```

It's just more trouble than it is worth.

The one part I'd change:

We align and/or'd parts of an if-condition with the in-block code:

```fish
if true
   and false
    dosomething
end
```

becomes

```fish
if true
    and false
    dosomething
end
```

but it's not used terribly much and if we ever fix it we can just
reindent.
2020-01-13 20:34:22 +01:00
Johannes Altmanninger
9a355d5482 complete: replace confusing comment with test case 2020-01-08 17:53:46 +01:00
Johannes Altmanninger
75fa3b6bae unbreak missing argument error on long option 2020-01-08 17:33:36 +01:00
Johannes Altmanninger
fdf398e435 show missing argument error only for last flag
closes #6483
2020-01-08 14:59:26 +01:00
Johannes Altmanninger
0e707b88f0 argparse: fix error message for missing option argument
case #1 in #6483
2020-01-08 14:38:05 +01:00
Johannes Altmanninger
992c864f26 Don't overwrite unrelated variables with for-loop-variables
for-loops that were not inside a function could overwrite global
and universal variables with the loop variable.  Avoid this by making
for-loop-variables local variables in their enclosing scope.

This means that if someone does:

    set a global
    for a in local; end
    echo $a

The local $a will shadow the global one (but not be visible in child
scopes). Which is surprising, but less dangerous than the previous
behavior.

The detection whether the loop is running inside a function was failing
inside command substitutions. Remove this special handling of functions
alltogether, it's not needed anymore.

Fixes #6480
2020-01-08 09:10:14 +01:00
Norio Nomura
cc7618985a Don't override exit status when stderr is closed by 2>&-
fixes #6470
2020-01-07 19:57:35 +01:00
Fabian Homborg
24970bb549 checks: Use "sleep" without "s" suffix
FreeBSD's sleep doesn't accept it.
2020-01-05 18:41:56 +01:00
ridiculousfish
62302ee172 Properly print leading comments and indentation in functions
Store the entire function declaration, not just its job list.
This allows us to extract the body of the function complete with any
leading comments and indents.

Fixes #5285
2020-01-03 14:40:28 -08:00
Johannes Altmanninger
c3374edc59 Reject time with background jobs
This check could probably done earlier in the parser but it works.
2020-01-03 01:07:49 -06:00
Johannes Altmanninger
3de95038b0 Make "time" a job prefix
In particular, this allows `true && time true`, or `true; and time true`,
and both `time not true` as well as `not time true` (like bash).

time is valid only as job _prefix_, so `true | time true` could call
`/bin/time` (same in bash)

See discussion in #6442
2020-01-03 01:07:49 -06:00
ridiculousfish
efa9d5dd6a Port cd tests to littlecheck 2019-12-31 14:16:20 -08:00
ridiculousfish
91404f1762 Rename job_ids check to job-ids
Other tests use a dash.
2019-12-31 13:32:04 -08:00
ridiculousfish
9a11c03097 Correct the job_ids test on the Mac
The Mac doesn't provide CPU percentages so the column is omitted, causing
the test to fail. Use a regex to cover both cases.
2019-12-31 13:17:26 -08:00
ridiculousfish
b691d3130e Don't give job IDs to block processes either
Extend the commit 8e17d29e04 to block processes, for example:

    begin ; stuff ; end

or if/while blocks as well.

Note there's an existing optimization where we do not create a job for a
block if it has no redirections.
2019-12-31 13:12:24 -08:00
ridiculousfish
a6e5583b5b Correct reordering of jobs in job_promote
job_promote attempts to bring the most recently "touched" job to the front
of the job list. It did this via:

    std::rotate(begin, job, end)

However this has the effect of pushing job-1 to the end. That is,
promoting '2' in [1, 2, 3] would result in [2, 3, 1].

Correct this by replacing it with:

    std::rotate(begin, job, job+1);

now we get the desired [2, 1, 3].

Also add a test.
2019-12-31 12:41:11 -08:00
Johannes Altmanninger
9f48fc6285 Fix status when function/block evaluation is cancelled
It looks like the last status already contains the signal that cancelled
execution.

Also make `fish -c something` always return the last exit status of
"something", instead of hardcoded 127 if exited or signalled.

Fixes #6444
2019-12-23 17:38:19 +01:00
ridiculousfish
97dd5ece26 Remove redirection_is_to_real_file
This was previously required so that, if there was a redirection to a
file, we would fork a process to create the file even if there was no
output. For example `echo -n >/tmp/file.txt` would have to create
file.txt even though it would be empty.

However now we open the file before fork, so we no longer need special
logic around this.
2019-12-20 14:40:57 -08:00
Fabian Homborg
dcf8b0e3aa Add test for time 2019-12-20 17:13:21 +01:00
Johannes Altmanninger
1410f938aa read: discard IFS delimiters before the last token
Do this only when splitting on IFS characters which usually contains
whitespace characters --- read --delimiter is unchanged; it still
consumes no more than one delimiter per variable. This seems better,
because it allows arbitrary delimiters in the last field.

Fixes #6406
2019-12-19 23:44:58 +01:00
Mahmoud Al-Qudsi
d90d4f849c Force symlink creation in realpath tests
If an earlier test was aborted, the symlink would still be present and
the subsequent run will fail to create the symlink as it wasn't forced.
2019-12-18 12:31:24 -06:00
Johannes Altmanninger
b1144a1fde completion: fix file completion of redirection targets
This fixes a regression introduced in
6fb7f9b6b - Fix completion for builtins with subcommands
2019-12-16 12:45:39 +01:00
ridiculousfish
9be77d1f9c Correctly handle "self fd redirections"
This adds a test for the obscure case where an fd is redirected to
itself. This is tricky because the dup2 will not clear the CLO_EXEC bit.
So do it manually; also posix_spawn can't be used in this case.
2019-12-13 16:51:49 -08:00
ridiculousfish
d6c71d77a9 Correctly cloexec file redirections
The IO cleanup left file redirections open in the child. For example,
/bin/cmd < file.txt would redirect stdin but also leave the file open.
Ensure these get closed properly.
2019-12-13 16:16:19 -08:00
ridiculousfish
c0b3be9fb4 Stop storing block_io in job_t
Prior to this fix, a job would hold onto any IO redirections from its
parent. For example:

    begin
        echo a
    end < file.txt

The "echo a" job would hold a reference to the I/O redirection.
The problem is that jobs then extend the life of pipes until the job is
cleaned up. This can prevent pipes from closing, leading to hangs.

Fix this by not storing the block IO; this ensures that jobs do not
prolong the life of pipes.

Fixes #6397
2019-12-11 16:34:20 -08:00
ridiculousfish
92a16921bf Add a test to verify that processes get the right pgrps in pipelines 2019-12-08 13:45:24 -08:00
ridiculousfish
d47541a3d7 Add a tricky test to verify disowning an in-flight job
There's some logic in fish to prevent blowing up when an under-construction
job is disowned. Add a test for it.
2019-12-08 11:44:21 -08:00
ridiculousfish
098fe86ebf Port empty functions test to littlecheck 2019-12-07 11:02:22 -08:00
Peter Collingbourne
6dc4ac60ae Use $PWD to retrieve the current directory in __fish_move_last.
(command pwd) uses the system's implementation of pwd. At least the GNU
coreutils implementation defaults to -P, which resulted in symlinks being
expanded when switching between directories with nextd/prevd.
2019-12-07 12:20:31 +01:00
Fabian Homborg
115892ccd2 alias: Use read --tokenize
This did some weird unescaping to try to extract the first word.

So we're now more likely to be *correct*, and the alias benchmark is
about 20% *faster*.

Call it a win-win.
2019-12-01 18:14:26 +01:00
Fabian Homborg
86133b0a2b Add read --tokenize
This splits a string into variables according to the shell's
tokenization rules, considering quoting, escaping etc.

This runs an automatic `unescape` on the string so it's presented like
it would be passed to the command. E.g.

    printf '%s\n' a\ b

returns the tokens

printf
%s\n
a b

It might be useful to add another mode "--tokenize-raw" that doesn't
do that, but this seems to be the more useful of the two.

Fixes #3823.
2019-12-01 18:14:26 +01:00
Fabian Homborg
662fb3f3d1 Fix line numbers in functions
This added the function offset *again*, but it's already included in
the line for the current file.

And yes, I have explicitly tested a function file with a function
defined at a later line.

Fixes #6350
2019-11-26 18:12:24 +01:00
Johannes Altmanninger
f36705bb66 Fix error messages for "and" and "or" after pipe
Fixes #6347
2019-11-26 14:03:53 +01:00
Johannes Altmanninger
97969a9363 Restore error messages for bare variable assignment
Since #6287, bare variable assignments do not parse, which broke
the "Unsupported use of '='" error message.

This commit catches parse errors that occur on bare variable assignments.
When a statement node fails to parse, then we check if there is at least one
prefixing variable assignment. If so, we emit the old error message.

See also #6347
2019-11-26 13:59:17 +01:00
ridiculousfish
305409a025 Fix the vi mode bind test
Note support for the 'replace' mode.
2019-11-25 16:43:54 -08:00
Jason
3cf6ebc0e1 Amend typos and grammar errors 2019-11-25 13:07:15 +01:00
Johannes Altmanninger
7d5b44e828 Support FOO=bar syntax for passing variables to individual commands
This adds initial support for statements with prefixed variable assignments.
Statments like this are supported:

a=1 b=$a echo $b        # outputs 1

Just like in other shells, the left-hand side of each assignment must
be a valid variable identifier (no quoting/escaping).  Array indexing
(PATH[1]=/bin ls $PATH) is *not* yet supported, but can be added fairly
easily.

The right hand side may be any valid string token, like a command
substitution, or a brace expansion.

Since `a=* foo` is equivalent to `begin set -lx a *; foo; end`,
the assignment, like `set`, uses nullglob behavior, e.g. below command
can safely be used to check if a directory is empty.

x=/nothing/{,.}* test (count $x) -eq 0

Generic file completion is done after the equal sign, so for example
pressing tab after something like `HOME=/` completes files in the
root directory
Subcommand completion works, so something like
`GIT_DIR=repo.git and command git ` correctly calls git completions
(but the git completion does not use the variable as of now).

The variable assignment is highlighted like an argument.

Closes #6048
2019-11-25 09:20:51 +01:00
Fabian Homborg
aae111584d Disable localized number test on OpenBSD
This feature simply does not work there.
2019-11-16 12:11:09 +01:00
Ankush Patil
ee982c4f6c Fixes #6280 : Added right associativity to 'pow' function 2019-11-13 13:51:01 -08:00
ridiculousfish
2555ecf757 Remove the forbidden function stack
Detect forbidden functions directly from the associated block_t.
Also unify where we do stack overflow detection.
2019-11-10 12:36:46 -08:00
ridiculousfish
626237c9c3 Add a check for fish function stack overflow 2019-11-10 12:35:58 -08:00
Johannes Altmanninger
e94b9ccf3e Do import bash history commands containing && or || 2019-11-07 23:33:35 +01:00
Fabian Homborg
d77c465d23 string: Allow -eq again
Instead of forbidding it for both modes, allow it for both and make it
quiet for string.

Fixes #6282
2019-11-04 17:34:37 +01:00
Johannes Altmanninger
6fb7f9b6b8 Fix completion for builtins (with subcommands)
Presently the completion engine ignores builtins that are part of the
fish syntax. This can be a problem when completing a string that was
based on the output of `commandline -p`.  This changes completions to
treat these builtins like any other command.

This also disables generic (filename) completion inside comments and
after strings that do not tokenize.

Additionally, comments are stripped off the output of `commandline -p`.

Fixes #5415
Fixes #2705
2019-11-04 16:44:51 +01:00
ridiculousfish
72bf5898d3 Clean up how PATH and CDPATH munging occurs
PATH and CDPATH have special behavior around empty elements. Express this
directly in env_stack_t::set rather than via variable dispatch; this is
cleaner.
2019-11-02 16:48:08 -07:00
ridiculousfish
a7f1d2c0c7 Add support for fish_trace variable to trace execution
This adds support for `fish_trace`, a new variable intended to serve the
same purpose as `set -x` as in bash. Setting this variable to anything
non-empty causes execution to be traced. In the future we may give more
specific meaning to the value of the variable.

The user's prompt is not traced unless you run it explicitly. Events are
also not traced because it is noisy; however autoloading is.

Fixes #3427
2019-11-02 14:40:57 -07:00
Johannes Altmanninger
6702c84d15 Prevent buffer overflow when custom completions edit the commandline
This was introduced in a7ea7648c3
"Completion: maintain cursor position when there is no completion"
2019-11-01 13:21:49 +01:00
Fabian Homborg
c0d8439f3a math: Print special error for logical operators
Until now, something like

`math '7 = 2'`

would complain about a "missing" operator.

Now we print an error about logical operators not being supported and
point the user towards `test`.

Fixes #6096
2019-11-01 08:43:13 +01:00
0x005c
067b30208d Fix math incorrect parenthesis error on missing term 2019-10-31 22:10:54 +01:00
ridiculousfish
0bfd897ee0 Add a special error message for |& 2019-10-27 15:24:57 -07:00
ridiculousfish
2a92e66902 Support for &> and &| as convenience redirections
This adds support for &> and &| syntax, which both redirect stdout, and
also apply a redirection of stderr to stdout.
2019-10-27 15:24:57 -07:00
Fabian Homborg
66938d206a string: Error out on match -eq
The `--entire` would enable output even though the `--quiet` should
have silenced it. These two don't make any sense together so print an
error, because the user could have just left off the `-q`.
2019-10-22 22:11:36 +02:00
Fabian Homborg
e0d623d4b7 tests/test_util: Fix wrong argument in delta
This spewed errors because the `math` invocation got no second
operand:

    Testing file checks/sigint.fish ... math: Error: Too few arguments
    '1571487730 -'

but only if the `date` didn't do milliseconds, which is the case on
FreeBSD and NetBSD.

(also force the variable to be global - we don't want to have a
universal causing trouble here)
2019-10-19 14:27:47 +02:00
Johannes Altmanninger
b7f35f949e Do not import vars that are equivalent to a universal exported var
Universal exported variables (created by `set -xU`) used to show up
both as universal and global variable in child instances of fish.

As a result, when changing an exported universal variable, the
new value would only be visible after a new login (or deleting the
variable from global scope in each fish instance).

Additionally, something like `set -xU EDITOR vim -g` would be imported
into the global scope as a single word resulting in failures to
execute $EDITOR in fish.

We cannot simply give precedence to universal variables, because
another process might have exported the same variable.  Instead, we
only skip importing a variable when it is equivalent to an exported
universal variable with the same name.  We compare their values after
joining with spaces, hence skipping those imports does not change the
environment fish passes to its children. Only the representation in
fish is changed from `"vim -g"` to `vim -g`.

Closes #5258.
This eliminates the issue #5348 for universal variables.
2019-10-19 12:41:57 +02:00
Johannes Altmanninger
5e274066e3 Always return absolute path in path_get_cdpath
Fixes #6220
2019-10-19 12:38:17 +02:00
Johannes Altmanninger
eae1683033 Completion: complete argument to last of a group of short options
Consider a group of short options, like -xzPARAM, where x and z are options and z takes an argument.

This commit enables completion of the argument to the last option (z), both within the same
token (-xzP) or in the next one (-xz P).

complete -C'-xz' will complete only parameters to z.
complete -C'-xz ' will complete only parameters to z if z requires a parameter
otherwise, it will also complete non-option parameters

To do so this implements a heuristic to differentiate such strings from single long options. To
detect whether our token contains some short options, we only require the first character after the
dash (here x) to be an option. Previously, all characters had to be short options. The last option
in our example is z. Everything after the last option is assumed to be a parameter to the last
option.

Assume there is also a single long option -x-foo, then complete -C'-x' will suggest both -x-foo and
-xy. However, when the single option x requires an argument, this will not suggest -x-foo.
However, I assume this will almost never happen in practise since completions very rarely mix
short and single long options.

Fixes #332
2019-10-16 11:30:50 +02:00
ridiculousfish
ca11b5edc8 Add a simple test for SIGINT out of loops 2019-10-15 22:33:53 -07:00
Johannes Altmanninger
cf3b24cf62 fix typo 2019-10-15 13:30:21 +02:00
Aaron Miller
15ed682bfa Fix options after --argument-names to function (#6188)
This stops reading argument names after another option appears. It does not break any previous uses and in fact fixes uses like

```fish
function foo --argument-names bar --description baz
```

* `function` command handles options after argument names (Fixes #6186)

* Removed unneccesary test
2019-10-10 18:09:26 +02:00
jalr
3d1e9423c2 cd: Add test for changing to a dir starting with a - char 2019-10-10 18:06:11 +02:00
Fabian Homborg
ff18b2a09a Fix tests
This didn't account for the path differing from when I ran the test
manually.

Sorry!
2019-10-08 19:12:56 +02:00
Fabian Homborg
a7913c3a10 function: Reject invalid variable names for --argument-names
Fixes #6147.
2019-10-07 21:26:41 +02:00
Johannes Altmanninger
f91c725ff0 Fix caret position of invalid expansion in command position
Fixes #5812
2019-10-06 13:43:05 -07:00
Johannes Altmanninger
9b86d5dd16 Export all local exported variables in a new scope
Fixes #6153
2019-10-06 12:10:21 -07:00
Johannes Altmanninger
7017a2fcf9 Unexpand abbreviations' variable names before completing them
Fixes #6166
2019-10-06 14:42:42 +02:00
Johannes Altmanninger
e167714899 Raise the recursion limit of complete
Users should generally prefer to use complete --wraps but this
corrects some unexpected behavior.

Fixes #3474
2019-10-03 21:25:19 +02:00
Johannes Altmanninger
aa011f70a8 Print an error when complete reaches its recursion limit 2019-10-03 21:25:19 +02:00
Aaron Gyes
902c6ec4a3 Check for {g,}date existance before trying --version 2019-09-21 18:42:55 -07:00
Aaron Gyes
7804a5e477 Revert "Correctly detect the presence of gdate"
This reverts commit 4b181df254.

It will result in systems without a GNU date having a literal "N"
in the output.
2019-09-21 18:40:32 -07:00
ridiculousfish
5f64972908 Do not try the same (command, wraps) pair more than once when completing
This prevents runaway wrap chains. Fixes #5638.
2019-09-21 14:09:38 -07:00
ridiculousfish
4b181df254 Correctly detect the presence of gdate
Fixes some test spew
2019-09-21 12:12:08 -07:00
Aaron Gyes
102ddd2b79 tests/checks/complete.fish: don't check unsorted lines 2019-09-19 15:44:15 -07:00
Aaron Gyes
6459682c93 Work around indeterminant ordering for complete test
Not a cool fix but it should work
2019-09-19 15:35:25 -07:00
Aaron Gyes
9486af8805 tests: fix date --version printing junk, update interactive.fish 2019-09-19 15:06:51 -07:00
Aaron Gyes
53a3533285 Add tests for complete (no args) output
Hopefully this should catch things if the output gets broken again.
2019-09-19 15:01:09 -07:00
Aaron Gyes
5c06e68115 tests: add a lame gdate-based ms-precision timer if installed
I got tired of seeing ' ... ok (0 sec)' so now with GNU date/gdate
installed there is millisecond output shown. One can get rough
nanoseconds from gdate.
2019-09-19 14:26:53 -07:00
Aaron Gyes
61f0756fe6 builtins: Use standard builtin.h error macros more 2019-09-17 22:04:33 -07:00
ridiculousfish
533ee65963 Allow binding nul (zero byte)
This sequence can be generatd by control-spacebar. Allow it to be bound
properly.

To do this we must be sure that we never round-trip the key sequence
through a C string.
2019-09-14 16:37:57 -07:00
ridiculousfish
7ea3255eef Correct the exit expect test
There was an errant space which is not matched; this seems to cause problems
only on one machine for mysterious reasons.
2019-09-14 12:46:57 -07:00
David Adam
77ef2ef6c3 jobs: return success when a job is found via --last
Closes #6104.
2019-09-14 13:01:36 -05:00
ridiculousfish
fa6bac1283 Correctly implement and --help and or --help 2019-09-08 10:42:24 -07:00
David Adam
225b1204d6 read: add --list as synonym for --array
Work on #5846.
2019-08-22 21:24:17 +08:00
Aaron Gyes
47798510bd tests, CHANGELOG: regex-easyesc
Oops, missed these the first time around.
2019-08-13 22:56:31 -07:00
Fabian Homborg
6500765256 Allow switch with something that expands to nothing
Meaning empty variables, command substitutions that don't print
anything.

A switch without an argument

```fish
switch
   case ...
end
```

is still a syntax error, and more than one argument is still a runtime
error.

The none-argument matches either an empty-string `case ''` or a
catch-all `case '*'`.

Fixes #5677.

Fixes #4943.
2019-07-31 14:08:28 +02:00
Fabian Homborg
57ffd18787 tests/checks/set: Make a temporary XDG_CONFIG_HOME
This test uses universal variables, and so it can fail when run
multiple times.

It might be a good idea to do this in general, but for now let's just
try it here.
2019-07-31 13:52:36 +02:00
ridiculousfish
554ee240b3 Correct handling of explicitly separated output when all elements are empty
Previously when propagating explicitly separated output, we would early-out
if the buffer was empty, where empty meant contains no characters. However
it may contain one or more empty strings, in which case we should propagate
those strings.

Remove this footgun "empty" function and handle this properly.

Fixes #5987
2019-07-21 14:00:27 -07:00
ridiculousfish
e8c6de8055 Correctly export empty universal variables
Fixes #5992
2019-07-21 12:45:29 -07:00
ridiculousfish
01dff25f62 Remove test3
This is now handled by littlecheck
2019-07-21 12:18:28 -07:00
ridiculousfish
07d1607e58 Port tests/test3.in to littlecheck
This just tests 'set'
2019-07-21 12:18:28 -07:00
ridiculousfish
cdcea0f00d Port setenv tests to littlecheck 2019-07-09 10:02:50 -07:00
Fabian Homborg
65eb4cd9d3 eval tests: Fix path
I tested this manually (`littlecheck.py -s fish=fish tests/checks/eval.fish`) from the base directory, which means I got
"tests/checks/eval", while the real test gets "checks/eval".

I then reran `make test_fishscript`, but that didn't pull in the
updated test - we should really handle that better.
2019-07-03 15:14:49 +02:00
Fabian Homborg
f1fa8d5f5b Port complete tests to littlecheck 2019-07-03 13:02:15 +02:00
Fabian Homborg
87b05d3111 Port eval tests to littlecheck 2019-07-03 12:54:42 +02:00
Fabian Homborg
4ae18951ee Add NetBSD's error to the bad-option test
I'm kinda close to just checking `.*fish: .*option.*Z.*`
2019-07-02 23:48:25 +02:00
Fabian Homborg
d775c584a5 Port realpath tests to littlecheck
I'm gonna add more tests to this and I don't want to touch the old stuff.

Notice that this needs to have the output of the complete_directories
test adjusted because this one now runs later.

That's something we should take into account in future.
2019-07-02 23:05:50 +02:00
Fabian Homborg
7d3bec1297 test.fish: Notice littlecheck failures
This failed to propagate the exit status. Sorry!
2019-07-02 22:50:16 +02:00
Fabian Homborg
4c022a708f tests: Simplify directory-redirect test
This doesn't need the indirection, since it was only an invocation
test because we couldn't express it in the old runner.
2019-06-28 20:48:11 +02:00
ridiculousfish
262fe65121 Correctly mark a node when erasing an exported variable
Fixes #5965
2019-06-28 11:22:49 -07:00
ridiculousfish
3c800e0608 Make history tests more robust
history now often writes to the history file asynchronously, but the history
test expects to find the text in the file immediately after running the
command. Hack a bit in history to make this test more reliable.
2019-06-28 11:16:27 -07:00
Fabian Homborg
22d2620716 Rerun all interactive tests once
They are *all* flakey enough that we regularly see them fail, at least
on Travis.
2019-06-26 21:26:20 +02:00
Fabian Homborg
4d035cbd10 Port bind tests to littlecheck 2019-06-26 21:19:40 +02:00
Fabian Homborg
fdf0a661cf Port andandoror test to littlecheck 2019-06-26 21:19:40 +02:00
Fabian Homborg
8e11f802b4 Port alias test to littlecheck 2019-06-26 21:19:40 +02:00
Fabian Homborg
9462aacc5c Port abbr test to littlecheck 2019-06-26 21:19:40 +02:00
Fabian Homborg
21805759a3 Port math test to littlecheck
This shows one bit where not trimming whitespace would make sense.
2019-06-26 21:19:40 +02:00
Fabian Homborg
2f19ec1c34 Port count test to littlecheck 2019-06-26 21:19:40 +02:00
ridiculousfish
b672e1891e Port signal tests to littlecheck 2019-06-26 11:07:46 -07:00
Fabian Homborg
cdbd0891f7 Remove invocation tests
These are now all performed by littlecheck, so there's no need for the
entire target anymore.
2019-06-25 22:31:45 +02:00
Fabian Homborg
a33c2f0bce Port config tests to littlecheck
This required a bit of thinking.

What we do is we have one test that fakes $HOME, and then we do the
various config tests there.

The fake config we have is reused and we exercise all of the same codepaths.
2019-06-25 22:31:06 +02:00
Fabian Homborg
10949648e7 Port qmark1 test to littlecheck
This one just needs a random home.
2019-06-25 22:31:06 +02:00
Fabian Homborg
5c7b7fd609 Readd bad-switch and directory-redirection tests
Made possible by the power of regex.
2019-06-25 22:30:58 +02:00
Fabian Homborg
b9c1f4b122 Remove ported tests 2019-06-25 21:00:13 +02:00
Fabian Homborg
21667850b3 tests/test.fish: Normalize littlecheck output
This prints a green "ok" with the duration, just like the rest of the
tests.

Note that this clashes a bit with
https://github.com/ridiculousfish/littlecheck/pull/3.

(also don't check for python again and again and again)
2019-06-25 20:57:37 +02:00
Fabian Homborg
9d5620c170 Port most of the invocation tests to littlecheck
This is a bit weird sometimes, e.g. to test the return status (that
fish actually *returns $status*), we use a #RUN line with %fish
invoking %fish, so we can use the substitution.

Still much nicer.

The missing scripts are those that rely on config.
2019-06-25 20:56:29 +02:00
Fabian Homborg
93d9fa4551 tests/test.fish: Run littlecheck with any python
Some operating systems don't have a "python" symlink, so we just run
it with the first python we find.
2019-06-25 19:25:36 +02:00
Fabian Homborg
1bba77e485 Port string tests to littlecheck
`wc -l tests/string.*`
  329 tests/string.err
  422 tests/string.in
  520 tests/string.out
 1271 total

`wc -l tests/checks/string.fish`
 555 tests/checks/string.fish

and it looks nicer. 'nuff said.
2019-06-25 17:26:36 +02:00
Fabian Homborg
77d8487078 string: Also stop printing documentation
Especially as, in this case, the documentation is quite massive.

Caught by porting string's test to littlecheck.

See #3404 - this was already supposed to be included.
2019-06-25 17:26:30 +02:00
Fabian Homborg
60edc9a45d Port argparse tests to littlecheck
This is a nice test (ha!) for how this works and what littlecheck can
do for us.

1. Input is now the actual file, not "Standard Input" anymore. So
any errors mentioning that now include the filename.
2. Regex are really nice for filenames, but especially for line
numbers
3. It's much nicer to have the output where it's created, instead of
needing to follow three files at the same time.
2019-06-25 16:11:24 +02:00
Fabian Homborg
8bfaf9e7ef Add test for erasing unloaded functions
Not perfect, but better than nothing.
2019-06-22 18:20:54 +02:00
Lily Ballard
fe2ec1e4f8
Merge pull request #5943 from lilyball/string_collect
Add new `string` subcommand `string collect`
2019-06-22 00:30:20 -07:00
Lily Ballard
181e44d331 Invert the flag for string collect
Instead of requiring a flag to enable newline trimming, invert it so the
flag (now `--no-trim-newlines`) disables newline trimming. This way our
default behavior matches that of sh's `"$(cmd)"`.

Also change newline trimming to trim all newlines instead of just one,
again to match sh's behavior.
2019-06-16 16:40:14 -07:00
Lily Ballard
b41e5cbbb7 Add string collect
The `string collect` subcommand behaves quite similarly in practice to
`string split0 -m 0` in that it doesn't split its output, but it also
takes an optional `--trim-newline` flag to trim a single trailing
newline off of the output.

See issue #159.
2019-06-16 15:51:57 -07:00
ridiculousfish
fcf0593dfb Port printf tests to littlecheck and teach the tester how to run it
This adds support for .check files inside the tests directory. .check
files are tests designed to be run with littlecheck.

Port printf test to littlecheck and remove the printf.in test.
2019-06-16 14:10:41 -07:00