File: cgreen_runner_output_diff

package info (click to toggle)
cgreen 1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,588 kB
  • sloc: ansic: 12,276; sh: 558; makefile: 474; cpp: 403; python: 181; xml: 33; sed: 13
file content (121 lines) | stat: -rwxr-xr-x 3,064 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/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