Suggestion/request: use of functions in test scripts

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

 



While debugging YASRTF (Yet Another Spurious Regression Test Failure), I
came across the following construct:

        bash_function () {
                command_1
                [ $? -ne 0 ] && return 1
                command_2
                return $?
        }

        TEST bash_function

First, the "return $?" is unnecessary.  The return value for the
function will *automatically* be the return value from the last thing it
called, even in pipelines.  Try it.  Second, this construct loses
information.  If the TEST fails, is it because of command_1 or
command_2?  We'll never know.  Sometimes, doing the same commands
"inline" in the main body of the script, with TEST on each one, is both
shorter and more debuggable.

        TEST command_1
        TEST command_2

For longer functions, you can at least provide a more informative
result.  If you provide that result as output instead of as a return
value, it will even show up in test reports.

        bash_function () {

                command_1
                if [ $? -ne 0 ]; then
                        echo "command_1 failed"
                        return
                fi

                command_2
                if [ $? -ne 0 ]; then
                        echo "command_2 failed"
                        return
                fi

                echo "ok"
        }

        EXPECT "ok" bash_function

Yes, this time it's longer, but storage is cheaper than stalling the
whole project because of "mysterious" regression-test failures.
_______________________________________________
Gluster-devel mailing list
Gluster-devel@xxxxxxxxxxx
http://www.gluster.org/mailman/listinfo/gluster-devel




[Index of Archives]     [Gluster Users]     [Ceph Users]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux