#!/bin/bash # # Will run the cgreen-runner in directory ../tools # on library with name $1 (e.g. 'lib${name}.so') # sources are in $2 for... # ...expected output file name in $3 # ...and commands to normalize output (in the file normalize_{name}.sed) # # TODO: refactor the duplication in this and cgreen_xml_output_diff to something # not having the duplication, common sub-script, maybe? # # TODO: make 'prefix' and 'extension' into arguments instead of evaluating them here # Determine OS unameo=`uname -o 1>/dev/null 2>/dev/null; echo $?` if [ $unameo -eq 0 ]; then OS=`uname -o` else OS=`uname -s` fi # Set up library prefix and extension case "$OS" in Darwin) prefix=lib extension=dylib ;; GNU/Linux|FreeBSD) prefix=lib extension=so ;; Cygwin) prefix=cyg extension=dll ;; Msys) prefix=msys- extension=dll ;; *) echo "ERROR: $0 can't handle OS=$OS" exit 2 ;; esac # Handle arguments if [ $# -ne 3 ]; then echo "ERROR: $0 requires exactly 3 arguments" exit 2 fi # TODO: don't shift name=$1; shift 1 sourcedir=$1 ; shift 1 sourcedir=$(perl -e 'use Cwd "abs_path"; print abs_path(@ARGV[0])' -- "$sourcedir") if [ $(uname -n) = thoni64 ]; then # On my Cygwin machine I have linked /home to c:/Users so absolute paths don't match # what runner prints, so try to replace that # TODO: generalize this... sourcedir=`echo $sourcedir | sed -e s#/cygdrive/c/Users#/home#` fi expected=$1 ; shift 1 # TODO: remove empty normalize-files and don't call them if not necessary commandfile="${sourcedir}/normalize_${name}.sed" # Do it! if [ -z "$CGREEN_PER_TEST_TIMEOUT" ]; then printf "Comparing output of ${name} to expected: " else printf "Comparing output of ${name} to expected with CGREEN_PER_TEST_TIMEOUT=$CGREEN_PER_TEST_TIMEOUT: " fi # Run runner on library store output and error ../tools/cgreen-runner ./${prefix}${name}.${extension} > "${name}.output" 2> "${name}.error" cat "${name}.error" >> "${name}.output" tempfile=`mktemp` # sed commands to normalize... # - line numbers in error messages echo "s/:[0-9]+:/:000:/g" > $tempfile # - timing info echo "s/in [0-9]+ms\./in 0ms\./g" >> $tempfile # - library prefix echo s/\"${prefix}${name}\"/\"${name}\"/g >> $tempfile # - source path, ensure parenthesis are not interpreted by sed -E echo s%.*${sourcedir//[\(\)]/.}/%%g >> $tempfile # Do normalization using the commands in the tempfile and the specified commandfile sed -E -f "${tempfile}" -f "${commandfile}" "${name}.output" > "${name}.output.normalized" # Check for color capability if test -t 1; then ncolors=$(tput colors) if test -n "$ncolors" && test $ncolors -ge 8; then green="$(tput setaf 2)" normal="$(tput sgr0)" fi fi # Compare normalized output to expected cmp -s "${name}.output.normalized" "${sourcedir}/${expected}" # If not the same, show diff rc=$? if [ $rc -ne 0 ] then echo diff -c "${name}.output.normalized" "${sourcedir}/${expected}" else echo ${green}Ok${normal} fi exit $rc