Commit graph

121 commits

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