aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Aaron Gyes <me@aaron.gy>2016-06-18 08:00:40 -0700
committerGravatar Aaron Gyes <me@aaron.gy>2016-06-18 08:26:07 -0700
commit2cabcf4ad466d44a4fc45afa3892c933238e2ebe (patch)
tree0161b30f2173cf40283fa5f3b994d49014bccee4
parent20d36f16d3e8e8b02c2406eec46369ad74f78cd2 (diff)
bg had also had wrong exit code for some errors
Stop printing usage information when error isn't a usage problem. Add simple test for bg and fg
-rw-r--r--src/builtin.cpp17
-rw-r--r--tests/jobs.err2
-rw-r--r--tests/jobs.in2
3 files changed, 7 insertions, 14 deletions
diff --git a/src/builtin.cpp b/src/builtin.cpp
index 17ee3cac..248ca323 100644
--- a/src/builtin.cpp
+++ b/src/builtin.cpp
@@ -2604,7 +2604,6 @@ static int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
streams.err.append_format(_(L"%ls: Ambiguous job\n"), argv[0]);
} else {
streams.err.append_format(_(L"%ls: '%ls' is not a job\n"), argv[0], argv[1]);
-
}
builtin_print_help(parser, streams, argv[0], streams.err);
@@ -2624,13 +2623,11 @@ static int builtin_fg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
j = job_get_from_pid(pid);
if (!j || !job_get_flag(j, JOB_CONSTRUCTED) || job_is_completed(j)) {
streams.err.append_format(_(L"%ls: No suitable job: %d\n"), argv[0], pid);
- builtin_print_help(parser, streams, argv[0], streams.err);
j = 0;
} else if (!job_get_flag(j, JOB_CONTROL)) {
streams.err.append_format(_(L"%ls: Can't put job %d, '%ls' to foreground because "
L"it is not under job control\n"),
argv[0], pid, j->command_wcstr());
- builtin_print_help(parser, streams, argv[0], streams.err);
j = 0;
}
}
@@ -2694,7 +2691,7 @@ static int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
if (!j) {
streams.err.append_format(_(L"%ls: There are no suitable jobs\n"), argv[0]);
- res = 1;
+ res = STATUS_BUILTIN_ERROR;
} else {
res = send_to_bg(parser, streams, j, _(L"(default)"));
}
@@ -2702,23 +2699,15 @@ static int builtin_bg(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
wchar_t *end;
int i;
int pid;
- int err = 0;
for (i = 1; argv[i]; i++) {
errno = 0;
pid = fish_wcstoi(argv[i], &end, 10);
if (errno || pid < 0 || *end || !job_get_from_pid(pid)) {
streams.err.append_format(_(L"%ls: '%ls' is not a job\n"), argv[0], argv[i]);
- err = 1;
- break;
- }
- }
-
- if (!err) {
- for (i = 1; !res && argv[i]; i++) {
- pid = fish_wcstoi(argv[i], 0, 10);
- res |= send_to_bg(parser, streams, job_get_from_pid(pid), *argv);
+ return STATUS_BUILTIN_ERROR;
}
+ res |= send_to_bg(parser, streams, job_get_from_pid(pid), *argv);
}
}
diff --git a/tests/jobs.err b/tests/jobs.err
index e69de29b..13e56fdf 100644
--- a/tests/jobs.err
+++ b/tests/jobs.err
@@ -0,0 +1,2 @@
+bg: '3' is not a job
+fg: No suitable job: 3
diff --git a/tests/jobs.in b/tests/jobs.in
index c32b9b37..14ed5181 100644
--- a/tests/jobs.in
+++ b/tests/jobs.in
@@ -1,3 +1,5 @@
sleep 1 &
sleep 1 &
jobs -c
+bg 3
+fg 3 \ No newline at end of file