#!/bin/bash # test.sh - Don Yang (uguu.org) # # 09/03/12 set -e source=nyaruko.c target=nyaruko.exe output_prefix=test-data-$$ test_input=$output_prefix-expected-output.txt test_output_c=$output_prefix-output.c test_output_bin=$output_prefix-output.exe test_output_data=$output_prefix-actual-output.txt # Fail with error message function die() { echo "$1" exit 1 } # Delete temporary files function cleanup() { rm -f $test_input $test_output_c $test_output_bin $test_output_data } # Run tests for a single input function run_single_test() { build=$1 label=$2 data=$3 echo "test: $label" echo -n $data > $test_input ./$target < $test_input > $test_output_c $build $test_output_c -o $test_output_bin || "Can not compile output" ./$test_output_bin > $test_output_data || true diff -q $test_input $test_output_data || die "Outputs differ" } # Run tests for a single compiler setting function run_tests() { build=$1 echo "build: $build" $build $source -o $target run_single_test "$build" "empty" "" for i in $(seq 1 1 70); do run_single_test "$build" "size $i" $(perl -e "print 'x'x $i;") done for i in $(seq 71 11 256); do run_single_test "$build" "size $i" $(perl -e "print 'x'x $i;") done for i in 100000 1000000 2000000; do run_single_test "$build" "size $i" $(perl -e "print 'x'x $i;") done for i in $(seq 1 1 10); do run_single_test "$build" "ordered $i" $(perl -e "print '0123456789'x $i;") done } echo "Input: $source" echo "Output prefix: $output_prefix" cleanup run_tests "gcc -Wall -O3" #run_tests "clang" cleanup echo "all good"