Post-mortem unit testing

前端 未结 4 2166
半阙折子戏
半阙折子戏 2021-02-20 03:14

I do version control with Git, and unit testing with QUnit. Sometimes I find a bug in my software that was not present in a past version. It\'s easy for me to write a unit test

4条回答
  •  死守一世寂寞
    2021-02-20 03:24

    Git has a command to do exactly what you want, git bisect

    Find by binary search the change that introduced a bug

    In your case you want to use it as git bisect run /path/to/script, which will automatically test commits and performs a check with each commit to find the bad commit.

    Note that the script (my_script in the above example) should exit with code 0 if the current source code is good, and exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad.

    Any other exit code will abort the bisect process. It should be noted that a program that terminates via "exit(-1)" leaves $? = 255, (see the exit(3) manual page), as the value is chopped with "& 0377".

    The special exit code 125 should be used when the current source code cannot be tested. If the script exits with this code, the current revision will be skipped (see git bisect skip above). 125 was chosen as the highest sensible value to use for this purpose, because 126 and 127 are used by POSIX shells to signal specific error status (127 is for command not found, 126 is for command found but not executable---these details do not matter, as they are normal errors in the script, as far as "bisect run" is concerned).

    So, your script would compile your sources, run your unit test suite and then give the corresponding exit code. The example section from the bisect manpage covers this nicely (including broken builds, merging hotfix commits, etc.)

提交回复
热议问题