#!/bin/bash if [ -z "$HOP" ]; then hop=hop else hop=$HOP fi space=" " dir=$(pwd) hop_opt="--no-server --no-so --so-policy none -q" CC=/usr/bin/gcc batchfile=/tmp/batch.js output_hop=/tmp/TEST-HOPJS.out verb= debug= report_ok() { echo -en "\x1B[33m\x1B[1mok\x1B[0m" success=$(($success+1)) if [ "$verb " != " " ]; then echo "" cat $output_hop fi } report_failure() { echo -en "\x1B[32m\x1B[1mfailure\x1B[0m" failure=$(($failure+1)) if [ "$verb " != " " ]; then echo "" cat $output_hop exit 1 fi } report_missing() { i=$((i + 1)) echo -n "$i. $1 ... " grep "^$1" BLACKLIST 2> /dev/null > /dev/null if [ $? = 0 ]; then echo -e "\x1B[34m\x1B[1mblacklist\x1B[0m." blacklist=$(($blacklist+1)) else echo -e "\x1B[31m\x1B[1mmissing\x1B[0m." missing=$(($missing+1)) fi } run_test() { i=$((i + 1)) file=$1 suf=$2 echo -n "$i. $file$suf.js ... " if [ -f $file.in ]; then cat < $batchfile "use strict"; "use hopscript"; import { batch } from "`dirname $PWD`/tests/node_modules/@hop/hiphop/lib/batch.js"; import test from "$dir/$file$suf.js"; if (test.prg) { try { batch(test.prg); } catch (e){ console.log(e.message); process.exit(1); } } EOF if [ "$verb " != " " ]; then echo "$hop $hop_opt $batchfile < $file.in" fi $hop $hop_opt $batchfile < $file.in > $output_hop 2>&1 status=$? else cat < $batchfile "use strict"; "use hopscript"; import { batch } from "`dirname $PWD`/tests/node_modules/@hop/hiphop/lib/batch.js"; import test from "$dir/$file$suf.js"; EOF if [ "$verb " != " " ]; then echo "$hop $hop_opt $batchfile" fi $hop $hop_opt $batchfile > $output_hop 2>&1 status=$? fi diff_out=$(diff $output_hop $file.out) #echo "$diff_out" if [ "$status" != "0" ]; then if [ -f $dir/$file.err ]; then report_ok else report_failure fi elif [ "$diff_out" != "" ]; then if [ -f $dir/$file.err ]; then report_ok else report_failure fi else report_ok fi echo "."; } init_stats() { i=0 success=0 failure=0 missing=0 blacklist=0 } print_stats() { echo -e "\x1B[1m$space*** $success success $failure failure $missing missing $blacklist blacklist ***\x1B[0m" } if [ "$(dirname $0)" != "." ] then echo "ERROR: The tests must be run inside test directory" exit 1 fi while : ; do case $1 in "") break;; -v) verb="$verb -v";; -g) debug=yes; hop_opt+=" -g";; *) break;; esac shift done hiphop=`(cd ..; basename $PWD)` if [ ! -d node_modules ]; then mkdir node_modules fi if [ ! -d node_modules/@hop ]; then mkdir node_modules/@hop fi if [ ! -e node_modules/@hop/hiphop ]; then (cd node_modules/@hop; ln -s ../../../../$hiphop hiphop) fi init_stats echo -e "\x1B[1m$space*** HIPHOP.JS TESTS ***\x1B[0m" if [ "$1 " != " " ]; then file=`basename $1 .js` file=`basename $file .hh` if [ "$file.js" = $1 -a -f $file.js ]; then run_test $file fi if [ "$file.hh.js" = $1 -a -f $file.hh.js ]; then run_test $file .hh fi else for file in *.out; do file=${file%.*} if [ -f $file.js ]; then run_test $file else report_missing $file.js fi if [ -f $file.hh.js ]; then run_test $file .hh else report_missing $file.hh.js fi done fi print_stats if [ "$debug " = " " -a "$failure " = "0 " ]; then rm $batchfile fi rm $output_hop exit $failure