#!/usr/bin/env bash
set +e
testfunc() {
	echo -n 0
	v=$(false || end)
	echo -n 1
}
output=$(
	init
	(
		(
			testfunc
			echo -n 2
		)
		echo -n 3
	)
	echo -n 4
)
errno=${?}
(( errno == 166 )) || fail "expected exit status 166, got ${errno}"
[[ ${output} == 0 ]] || fail "expected output of '0', got '${output}'"

(init; var=$(true && end 1))
errno=${?}
(( errno == 167 )) || fail "expected exit status 167, got ${errno}"

(var=$(true && end 1))
errno=${?}
(( errno == 1 )) || fail "expected exit status 1, got ${errno}"

init
(end)
fail "expected to die, but still around"
