Q:

(foo; echo $?) echoing empty string for functions that return >0 w/ set -e

I'm trying to unit test some bash scripts. One of my functions returns 1 as a false value, which I can use in if tests like 
foo() {
  return 0
}

if foo; then
  echo "Passed"
fi

This is really handy for writing clean code.
However when trying to unit test this code using shunit2, the assertFalse assertion needs a string value to test.
I've got around this by writing tests like this:
test_foo() {
  local result="$(foo; echo $?)"
  assertFalse "$result"
}

but this fails when foo returns 1. The echo $? seems to be echoing an empty string, rather than the actual return code.
Any idea what's going on?
edit
This only seems to occur when set -e is set. No idea why though.

A:

With set -e, the subshell
(foo; echo $?)

exits if foo fails—and in this case exits immediately after foo returns— so echo $? is never executed.
As a side note, some people dislike set -e (and there are good reasons for that, that you'll discover by reading the link).

