Possible to make something like macros in c, but in bash?
<p>I am pretty new to bash cripting, and have run into the following problem:</p>

<p>I am writing test cases in Bash, defined as functions which should return 1 in case of failure. These test cases could use some sort of macro, (or alias?) which takes a command as an argument, evaluates its results, and returns 1 (from the test case) if a failure occurs.</p>

<p>My current solution is a function which takes a command as an argument, and returns 0 or 1 depending on its result. The problem here is that each time this function is used in a test case, an if statement is needed to check its return value, and then return from the test case if there was an error. I would rather just have a one-line "assertion" of some sort. Some way to return a value "two levels up" from a function, or a c-style macro which makes a preprocessor insert the if statement after the result automatically could solve my isse, but I haven't found anything similar.</p>

<p>Is this even possible, or perhaps just bad practice?</p>

<p>A quick example of what I'm after:</p>

<pre><code>function a_test_case{
    return_1_if_prints_foo "echo foo" #should return 1 from a_test_case
    ...
}
</code></pre>

<p>which should have the same result as</p>

<pre><code>function a_test_case{
    prints_foo "echo foo"
    if [ $? = 1 ]; then
        return 1
    fi
    ...
}
</code></pre>

<p>Thanks!</p>