! exec cue cmd cannotFail
cmp stderr cannotFail-stderr.golden

exec cue cmd canFail
cmp stdout canFail-stdout.golden

! exec cue cmd withSpaces
cmp stderr withSpaces-stderr.golden

-- cue.mod/module.cue --
module: "example.com"
language: version: "v0.9.0"

-- cannotFail-stderr.golden --
task failed: command ["false"] failed: exit status 1
-- canFail-stdout.golden --
errExit:
success=false
hasStderr=false

errNotFound:
success=false
hasStderr=true
-- withSpaces-stderr.golden --
task failed: command ["false" "with an ignored argument"] failed: exit status 1
-- foo_tool.cue --
package foo

import (
	"tool/cli"
	"tool/exec"
)

command: cannotFail: {
	one: exec.Run & {
		cmd: ["false"]
	}
}

command: canFail: {
	errExit: exec.Run & {
		cmd: ["false"]
		stderr: string
		mustSucceed: false
	}
	errNotFound: exec.Run & {
		cmd: ["program-does-not-exist"]
		stderr: string
		mustSucceed: false
	}
	second: cli.Print & {
		text: """
			errExit:
			success=\(errExit.success)
			hasStderr=\(errExit.stderr != "")

			errNotFound:
			success=\(errNotFound.success)
			hasStderr=\(errNotFound.stderr != "")
			"""
	}
}

command: withSpaces: exec.Run & {
	cmd: ["false", "with an ignored argument"]
}
