Stream: helpdesk (published)

Topic: How to test for errors in a subprocess


view this post on Zulip Simon Christ (Sep 09 2022 at 09:15):

I'd like to write something along the lines of

using Test
@test_throws DomainError run(`julia -e 'sqrt(-1)'`)

Is that possible somehow?

view this post on Zulip Sukera (Sep 09 2022 at 09:15):

no, because the DomainError doesn't make it to the spawning process

view this post on Zulip Sukera (Sep 09 2022 at 09:15):

it's handled by the spawned process, the only thing run ends up seeing is the exit code of the process

view this post on Zulip Sukera (Sep 09 2022 at 09:16):

when dealing with subprocesses, you're limited to what they're communicating outside, either via various output streams, an exit code or explicit communication

view this post on Zulip Sukera (Sep 09 2022 at 09:17):

what you can do is search for DomainError in the stdout/stderr of the spawned process, but that's not reliable due to other output possibly creating a false positive

view this post on Zulip Simon Christ (Sep 09 2022 at 09:19):

Thanks! I feared it would be like that..


Last updated: Nov 06 2024 at 04:40 UTC