compiler

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

commit 7e81afb1de009f2781505127ed56f40847e878c1
parent 42e661f0b1f075a0920042cad22b4933d35e541b
Author: William Djupström <william@deepztream.com>
Date:   Mon, 25 Mar 2019 10:28:03 +0000

Beginning of testing framework

Diffstat:
Atest/test.sh | 7+++++++
Atest/test_framework | 40++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/test/test.sh b/test/test.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +: ${COMPILER:=../compiler} +. ./test_framework + +name=exit check "_start(){exit(42);}" "" "" 42 +name=writestring check '_start(){write(13, "Hello,\nWorld!");exit(42);}' "" "Hello,\nWorld!" 42 diff --git a/test/test_framework b/test/test_framework @@ -0,0 +1,40 @@ +#!/bin/bash + +# Examples +# check "_start(){exit(42);}" "" "" 42 + +C_RESET="\033[0m" +C_RED="\033[0;31m" +C_GREEN="\033[0;32m" + +fail() { + printf "${C_RESET}[${C_RED} FAIL ${C_RESET}] %s${C_RESET}: %s\n${C_RESET}" "$name" "$1" + #exit 1 +} + +pass() { + printf "${C_RESET}[${C_GREEN} PASS ${C_RESET}] %s\n${C_RESET}" "$name" + #exit 0 +} + +check() { + bin="$(mktemp -p /tmp XXXXXX)" + res="$(mktemp -p /tmp XXXXXX)" + chmod +x "$bin" + if $COMPILER - "$bin" <<< "$1"; then + "$bin" > "$res" <<< "$2" + ec=$? + if printf "$3" | diff -U1 "$res" -; then + if [ "$ec" -eq "$4" ]; then + pass + else + fail "wrong exit code" + fi + else + fail "stdout doesn't match" + fi + else + fail "failed to compile" + fi + rm "$bin" "$res" +}