#!/bin/sh
unset PT_TYPE GROWPART_RESIZER

error() { echo "$@" 1>&2; }
fail() { [ $# -eq 0 ] || error "$@"; }

runtests() {
    local mytest="$1" pt_type resizer
    make_executable "$1"
    for pt_type in gpt dos; do
        for resizer in auto sfdisk sgdisk; do
            echo "-- PT_TYPE=$pt_type GROWPART_RESIZER=$resizer --"
            case "$pt_type:$resizer" in
                # not supported
                dos:sgdisk)
                    echo "Skipping resize test for dos/sgdisk. not supported."
                    continue;;
            esac
            env "PT_TYPE=$pt_type" "GROWPART_RESIZER=$resizer" "$mytest"
            ret=$?
            [ $ret -eq 0 ] || {
                error "FAIL: $mytest failed. pt_type=$pt_type resizer=$resizer"
                return $ret
            }
            echo; echo;
        done
    done
}

make_executable() {
    # in case the thing to be executed is not executable
    # as it might be created by a patch application.
    if [ -f "$1" -a ! -x "$1" ]; then
        chmod +x "$1" || return
    fi
    return 0
}

execute() {
    make_executable "$1"
    "$@"
}

# vi: ts=4 expandtab
