Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Fix %- (prevjob) picking wrong job after resuming




On Wed, 1 Apr 2026, 22:25 Bart Schaefer, <schaefer@xxxxxxxxxxxxxxxx> wrote:
On Sun, Mar 22, 2026 at 2:10 PM Mikel Ward <mikel@xxxxxxxxxxxxx> wrote:
>
>> (!(sjn->stat & STAT_DONE)).  Is the latter a clearer _expression_ of the
>> intent of this test?
>
> Should I resend or are you happy to make the changes?

I'm happy to make that change, but when testing -- these error
messages have become a lot less informative:

Thanks Bart!

This test takes 3 seconds and hangs the shell when it fails...
--- /tmp/zsh.ztst.79176/ztst.err    2026-04-01 09:24:51
+++ /tmp/zsh.ztst.79176/ztst.terr    2026-04-01 09:24:51
@@ -1,7 +1,7 @@
 (eval):wait:1: pid 1 is not a child of this shell
-(eval):wait:3: %%: no such job
-(eval):wait:5: %+: no such job
-(eval):wait:7: %-: no such job
+(eval):wait:3: no current job
+(eval):wait:5: no current job
+(eval):wait:7: no previous job
 (eval):wait:9: %1: no such job
 (eval):wait:11: job not found: foo
 (eval):wait:13: job not found: ?bar
Test ./A05execution.ztst failed: error output differs from expected as
shown above for:
  wait 1
  echo $?
  wait %%
  echo $?
  wait %+
  echo $?
  wait %-
  echo $?
  wait %1
  echo $?
  wait %foo
  echo $?
  wait %\?bar
Was testing: 'wait' exit status and warning for unknown ID


Hmm. I didn't touch the message, so I'm not sure what's going on. It looks like that code path has always printed "no current job" and "no previous job"?

We could update the test expectation:

diff --git a/Test/A05execution.ztst b/Test/A05execution.ztst zsh-workers@xxxxxxx
index edc5615..5e47853 100644
--- a/Test/A05execution.ztst
+++ b/Test/A05execution.ztst
@@ -363,9 +363,9 @@ F:anonymous function, and a descriptor leak when backgrounding a pipeline
 >127
 >127
 ?(eval):wait:1: pid 1 is not a child of this shell
-?(eval):wait:3: %%: no such job
-?(eval):wait:5: %+: no such job
-?(eval):wait:7: %-: no such job
+?(eval):wait:3: no current job
+?(eval):wait:5: no current job
+?(eval):wait:7: no previous job
 ?(eval):wait:9: %1: no such job
 ?(eval):wait:11: job not found: foo
 ?(eval):wait:13: job not found: ?bar
-- 

Or more consistently print the jobspec:

diff --git a/Src/jobs.c b/Src/jobs.c
index d7df51f..82daa57 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -1923,7 +1923,7 @@ getjob(const char *s, const char *prog)
     if (*s == '%' || *s == '+' || !*s) {
  if (curjob == -1) {
      if (prog && !isset(POSIXBUILTINS))
- zwarnnam(prog, "no current job");
+ zwarnnam(prog, "%%%c: no such job", *s ? *s : '%');
      returnval = -1;
      goto done;
  }
@@ -1934,7 +1934,7 @@ getjob(const char *s, const char *prog)
     if (*s == '-') {
  if (prevjob == -1) {
      if (prog && !isset(POSIXBUILTINS))
- zwarnnam(prog, "no previous job");
+ zwarnnam(prog, "%%-: no such job");
      returnval = -1;
      goto done;
  }
-- 

Apologies for any copy paste formatting issues.

Thanks!


Messages sorted by: Reverse Date, Date, Thread, Author