From 709a1d3ff8b438f7608870974e2d77e59257d391 Mon Sep 17 00:00:00 2001 From: cedricbuild Date: Thu, 29 Aug 2024 15:29:43 +0000 Subject: [PATCH] print status code only once and check tests --- src/proc.rs | 15 +++++++++++---- tests/pexpects/job_summary.py | 5 +++++ tests/test_exit.py | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 tests/test_exit.py diff --git a/src/proc.rs b/src/proc.rs index 35f35bbd8..ed03d1c9d 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -1588,6 +1588,13 @@ fn proc_wants_summary_in_job(j: &Job, p: &Process) -> bool { true } +/// check if any of the processes in the job normally exited with non zero status code +fn job_any_process_exited_normally_and_non_with_zero_status(j: &Job) -> bool { + j.processes() + .iter() + .any(|p| p.status.normal_exited() && p.status.status_value() != 0) +} + /// Return whether to emit a fish_job_summary call for a job as a whole. We may also emit this for /// its individual processes. fn job_wants_summary(j: &Job) -> bool { @@ -1655,18 +1662,17 @@ fn summary_command(j: &Job, p: Option<&Process>) -> WString { // We are summarizing a process which exited with a signal. // Arguments are the signal name and description. buffer.push(' '); - if p.status.normal_exited(){ + if p.status.normal_exited() { buffer += L!("STATUS"); buffer.push(' '); buffer.push_str(&format!("{}", p.status.status_value())); - } else{ + } else { let sig = Signal::new(p.status.signal_code()); buffer += &escape(sig.name())[..]; buffer.push(' '); buffer += &escape(sig.desc())[..]; } - // If we have multiple processes, we also append the pid and argv. if j.processes().len() > 1 { buffer += &sprintf!(" %d", p.pid())[..]; @@ -1699,7 +1705,8 @@ fn summarize_jobs(parser: &Parser, jobs: &[JobRef]) -> bool { } // Overall status for the job. - if job_wants_summary(j) { + if job_wants_summary(j) && !job_any_process_exited_normally_and_non_with_zero_status(j) + { call_job_summary(parser, &summary_command(j, None)); } } diff --git a/tests/pexpects/job_summary.py b/tests/pexpects/job_summary.py index fa3d0d84e..ed921f961 100644 --- a/tests/pexpects/job_summary.py +++ b/tests/pexpects/job_summary.py @@ -1,4 +1,6 @@ #!/usr/bin/env python3 +import sys +sys.path.append("/home/cedric/projects/fish-shell/build_tools/") from pexpect_helper import SpawnedProc sp = SpawnedProc() @@ -52,6 +54,9 @@ expect_re("[0-9]+:0:sleep 20 &:SIGTERM:Polite quit request", timeout=20) sendline("") expect_prompt() +sendline("python -c 'import time;import sys;time.sleep(1);sys.exit(1)'") +expect_re("Job.* has Non Zero status code 1", timeout=1) + # fish_job_summary is called when foreground job is signalled. # cmd_line contains the entire pipeline. proc_id and proc_name are set in a pipeline. sendline("true | sleep 6") diff --git a/tests/test_exit.py b/tests/test_exit.py new file mode 100644 index 000000000..9dc1e434b --- /dev/null +++ b/tests/test_exit.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +import time +import sys +time.sleep(1) +# exits with non zero status code +sys.exit(1) +