compiler

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.deepztream.com/compiler
Log | Files | Refs

test_framework (757B)


      1 #!/bin/bash
      2 
      3 # Examples
      4 # check "_start(){exit(42);}" "" "" 42
      5 
      6 C_RESET="\033[0m"
      7 C_RED="\033[0;31m"
      8 C_GREEN="\033[0;32m"
      9 
     10 fail() {
     11   printf "${C_RESET}[${C_RED} FAIL ${C_RESET}] %s${C_RESET}: %s\n${C_RESET}" "$name" "$1"
     12   #exit 1
     13 }
     14 
     15 pass() {
     16   printf "${C_RESET}[${C_GREEN} PASS ${C_RESET}] %s\n${C_RESET}" "$name"
     17   #exit 0
     18 }
     19 
     20 check() {
     21   bin="$(mktemp -p /tmp XXXXXX)"
     22   res="$(mktemp -p /tmp XXXXXX)"
     23   chmod +x "$bin"
     24   if $COMPILER - "$bin" <<< "$1"; then
     25     "$bin" > "$res" <<< "$2"
     26     ec=$?
     27     if printf "$3" | diff -U1 "$res" -; then
     28       if [ "$ec" -eq "$4" ]; then
     29         pass
     30       else
     31         fail "wrong exit code"
     32       fi
     33     else
     34       fail "stdout doesn't match"
     35     fi
     36   else
     37     fail "failed to compile"
     38   fi
     39   rm "$bin" "$res"
     40 }