File: cgreen_libxml_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 (118 lines) | stat: -rwxr-xr-x 3,013 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
#!/bin/bash
#
# Will run the cgreen-runner in directory ../tools
# on library with name $1 (e.g. 'lib${name}.so')
# generating XML output that will be compared to
# sources are in $2 for...
# ...expected output file name in $3
# ...and commands to normalize output (in the file normalize_{name}.sed)
#
# 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=lib
    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 (don't know how to generalize this...)
    sourcedir=`echo $sourcedir | sed -e s#/cygdrive/c/Users#/home#`
fi

# TODO: don't shift
expected=$1 ; shift 1

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 -X L "${prefix}${name}.${extension}" > "${name}.output" 2> "${name}.error"
cat "${name}.error" >> "${name}.output"
cat L-*${name}.xml L-*${name}-default.xml >> "${name}.output"

tempfile=`mktemp`

# sed commands to normalize...
# - line numbers in error messages
echo "s/:[0-9]+:/:/g" > $tempfile

# - timing info
echo "s/in [0-9]+ms\./in 0ms\./g" >> $tempfile

# - library prefix
# TODO: should use prefix, shouldn't it?
echo s/\".*${name}\"/\"${name}\"/g >> $tempfile

# - source path, ensure parenthesis are not interpreted by sed -E
#                but allow any characters before sourcedir in the string
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