Edit

kc3-lang/kc3/test/test.subr

Branch :

  • test/test.subr
  • #!/bin/sh
    ## kc3
    ## Copyright from 2022 to 2025 kmx.io <contact@kmx.io>
    ##
    ## Permission is hereby granted to use this software granted the above
    ## copyright notice and this permission paragraph are included in all
    ## copies and substantial portions of this software.
    ##
    ## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
    ## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
    ## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
    ## THIS SOFTWARE.
    
    TEST_COLOR_KO=""
    TEST_COLOR_OK=""
    TEST_COLOR_RESET=""
    TEST_COUNT=0
    TEST_KO=0
    TEST_OK=0
    
    if [ "x$IKC3" = "x" ]; then
        if [ -f ../../ikc3/ikc3 ]; then
    	IKC3=../../ikc3/ikc3
        elif [ -f ../../ikc3 ]; then
    	IKC3=../../ikc3
        fi
    fi
    
    if [ "x$KC3S" = "x" ]; then
        if [ -f ../../kc3s/kc3s ]; then
    	KC3S=../../kc3s/kc3s
        elif [ -f ../../kc3s ]; then
    	KC3S=../../kc3s
        fi
    fi
    
    test_ko() {
        printf "%s" "${TEST_COLOR_KO}F${TEST_COLOR_RESET}"
        echo $@ >> .test_ko
        echo $@ >> .test
    }
    
    test_ok() {
        printf "%s" "${TEST_COLOR_OK}.${TEST_COLOR_RESET}"
        echo $@ >> .test_ok
        echo $@ >> .test
    }
    
    test_run () (
        TEST_RUNNER="$1"; shift
        TARGETS="$@"
        rm -f *.diff *.out *.ret
        rm -f .test .test_ko .test_ok
        touch .test .test_ko .test_ok
        for TARGET in $TARGETS; do
            echo "( ../test_runner ${TEST_RUNNER} ${TARGET}; )"
        done | runj -1 /bin/sh
        TEST_COUNT=$(echo $(wc -l .test) | cut -f 1 -d ' ')
        TEST_KO=$(echo $(wc -l .test_ko) | cut -f 1 -d ' ')
        TEST_OK=$(echo $(wc -l .test_ok) | cut -f 1 -d ' ')
        echo
        DIFFS="$(for TARGET in $TARGETS; do
        if [ -f "${TARGET}.diff" ]; then
            printf "%s " "${TARGET}.diff"
        fi
    done)"
        if [ "x$DIFFS" != "x" ]; then
            ls $DIFFS
            less $DIFFS || cat $DIFFS
        fi
        echo
        printf "%s" "Total $TEST_COUNT tests. "
        printf "%s" "${TEST_COLOR_OK}OK $TEST_OK ($(($TEST_OK * 100 / $TEST_COUNT))%)${TEST_COLOR_RESET}. "
        echo "${TEST_COLOR_KO}KO $TEST_KO ($(($TEST_KO * 100 / $TEST_COUNT))%)${TEST_COLOR_RESET}."
        if [ "x$TEST_KO" = "x0" ]; then
            exit 0
        fi
        exit 1
    )