]> git.ipfire.org Git - thirdparty/haproxy.git/commit
TESTS: add a unit test runner in the Makefile
authorWilliam Lallemand <wlallemand@haproxy.com>
Sat, 1 Mar 2025 16:22:45 +0000 (17:22 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Mon, 3 Mar 2025 11:43:32 +0000 (12:43 +0100)
commit1e7478bb4ec4058cd3b35c1cd89b8d8a44f94a64
tree622577aed428bc90080fa7fce834cd511193cc59
parenta6478399547259dbfb8241d8c0077722f77ed2be
TESTS: add a unit test runner in the Makefile

`make unit-tests` would run shell scripts from tests/unit/

The run-unittests.sh script will look for any .sh in tests/unit/ and
will call it twice:

- first with the 'check' argument in order to decide if we should skip
  the test or not
- second to run the check

A simple test could be written this way:

#!/bin/sh

check() {
       ${HAPROXY_PROGRAM} -cc 'feature(OPENSSL)'
       command -v socat
}

run() {
 ${HAPROXY_PROGRAM} -dI -f ${ROOTDIR}/examples/quick-test.cfg -c
}

case "$1" in
       "check")
               check
       ;;
       "run")
               run
       ;;
esac

The tests *MUST* be written in POSIX shell in order to be portable, and
any special commands should be tested with `command -v` before using it.

Tests are run with `sh -e` so everything must be tested.
Makefile
scripts/run-unittests.sh [new file with mode: 0755]