-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testscript: add kill command #243
Conversation
testscript/cmd.go
Outdated
if bg == nil { | ||
ts.Fatalf("unknown background process %q", bgName) | ||
} | ||
signal := os.Interrupt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be more generic to be able to choose the signal? (hup vs int vs kill...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was thinking that. I was wondering about the API for that. Would you be happy with kill [-SIG] [name]
? (SIG would be numeric only in the first instance on second thought, named signal would be better). With that, the default would probably be SIGKILL
.
89324db
to
f056824
Compare
ping As noted in the slack conversation about this PR, if adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know @rogpeppe isn't sure whether this is the perfect solution, but I'm perfectly comfortable to choose a solution that's good enough over no solution at all :)
! exec sleep 5 & | ||
|
||
kill -KILL test_sleep | ||
wait test_sleep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add failure test cases? in particular:
- trying to kill a running background process that was started with
&
rather than&word&
(i.e. using a background process name that doesn't exist) - trying to kill a background process that already stopped or was already killed
Please also cover the kill
and kill name
forms, as otherwise we can't be sure they will keep working in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These negated tests are not currently possible since the kill
command is not negatable. This is consistent with wait
.
The positive tests for without name are possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding more tests!
I see your point about consistency with wait
not being negatable. I personally think both should be, and both should fail if given an unknown/exited process, but we can always add that later - especially once we have ?
to ignore the result of a command.
I would personally also be fine with this, but given that the majority of users would presumably use that to write their own |
This allows sending a termination signal to backgrounded commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
This allows sending a termination signal to backgrounded commands.
Please take a look.
Closes #242