Skip to content

Commit

Permalink
cleanup and update test case for job info format
Browse files Browse the repository at this point in the history
  • Loading branch information
sekiguchi-nagisa committed Dec 6, 2023
1 parent 8bc3f46 commit 72f910a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,9 @@ std::string JobObject::formatInfo(JobInfoFormat fmt) const {
if (i > 0) {
value.append(prefixLen, ' ');
}
value += ' ';
auto &pid = fragments[i].first;
value += pid;
value.append(pidLen - pid.size(), ' ');
value += ' ';
auto &state = fragments[i].second;
value += state;
value.append(stateLen - state.size(), ' ');
value += " ";
value += descs[i];
value += '\n';
auto &[pid, state] = fragments[i];
formatTo(value, " %-*s %-*s %s\n", static_cast<int>(pidLen), pid.c_str(),
static_cast<int>(stateLen), state.c_str(), descs[i].c_str());
}
}
return value;
Expand Down
10 changes: 10 additions & 0 deletions test/exec/cases/base/builtin_jobs.ds
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ $out = IFS=$'\n' $(jobs -l $j)
assert $out.size() == 1
assert $out[0] == "[1] - ${$j.pid(0)!} Stopped {\n while(true 1) {}\n}"

# -l option (pipeline)
var j3 = while(true) {} | true &
defer { $j3.raise($SIGKILL); }
sleep 0.5
$j3.poll()
$out = IFS=$'\n' $(jobs -l $j3)
assert $out.size() == 2
assert $out[0] =~ $/^\[3\] \+ +[0-9]+ +Running while\(true\) {} \|$/ : ">> ${$out[0]}"
assert $out[1] =~ $/^ +[0-9]+ +Done +true$/ : ">> ${$out[1]}"

# help
assert help jobs | grep '^jobs: jobs \[-lprs] \[jobspec ...]'
assert $PIPESTATUS[0] == 0 && $PIPESTATUS[1] == 0
Expand Down

0 comments on commit 72f910a

Please sign in to comment.