[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

assert built-in

From: Craig
Subject: assert built-in
Date: Wed, 19 Aug 2015 08:39:15 +0000

Is this the appropriate place to present feature requests or is there another forum for that?

I am keen to propose the introduction of an assert built-in.  The only purpose of this built-in is to behave functionally identical to the eval built-in, except that on error, the current shell process exits with an appropriate exit code after outputting an assertion error and the line number (possibly with the line of code that triggered the assert).

It's somewhat cumbersome to have to transport this assert function from project to project, so it would save a considerable amount of effort and time if it were built-in.  Here's an implementation I use, which achieves a similar goal, but obviously doesn't capture the entire context as bash may be able to internally. It is also a post execution assertion as opposed to the one I proposed:

function assert() {
    local lineno=${BASH_LINENO[0]} \
          src="" \

    mapfile -n 1 -t -s $(( $lineno - 1 )) lines < "$src"

    printf "ASSERT: ${src##*/}:$lineno: %s\n" "$lines"

    exit 1

reply via email to

[Prev in Thread] Current Thread [Next in Thread]