summaryrefslogblamecommitdiffstats
path: root/test
blob: 9bf58c8e00161f13763576c02b2b6db98dd3fce9 (plain) (tree)
1
2
3
4
5
6
7
8




                                                              
      

        







                                                                                                
        
 
                       



                                                       
          
                                                   
          
          
 


                                  
                                    
                                                                                                             

                                      
                                                                                                                              
                         

      
 


                                                                                
          
  
#!/bin/sh

# Every test file must start with a line formatted as follows:
#   #:<exit code>:<additional makel command line options>

set -e
exec >&2

exit2str () {
    if test $1 = 0; then
        printf '%s\n' 'all good'
    else
        sed -n 's/^ *#define *EXIT_\([^ ]*\) *'"$1"' *$/ (\1)/p' < common.h | tr '[A-Z]' '[a-z]'
    fi
}

nfails=0

for f in tests/*.mk; do
    header="$(head -n 1 < "$f")"
    expected=$(printf '%s' "$header" | cut -d : -f 2)
    options="$(printf '%s' "$header" | cut -d : -f 3-)"

    set +e
    ./makel -f "$f" $options >/dev/null 2>/dev/null
    got=$?
    set -e

    expstr="$(exit2str $expected)"
    gotstr="$(exit2str $got)"

    if test $got -lt $expected; then
        printf '%s: %s\n' "$f" "defect was not detected (expected ${expected}${expstr}, got ${got}${gotstr})"
        : $(( nfails++ ))
    elif test $got -gt $expected; then
        printf '%s: %s\n' "$f" "found more serious defects than expected (expected ${expected}${expstr}, got ${got}${gotstr})"
        : $(( nfails++ ))
    fi
done

if test $nfails -gt 0; then
    printf '%s\n' '----------'
    printf '%s\n' "${nfails} tests returned different exit codes than expected."
    exit 1
fi