File: tap-functions.shi

package info (click to toggle)
graphicsmagick 1.4%2Breally1.3.45%2Bhg17696-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 49,092 kB
  • sloc: ansic: 249,519; cpp: 18,805; sh: 8,000; perl: 3,634; makefile: 2,567; tcl: 2,209; python: 1,250
file content (115 lines) | stat: -rw-r--r-- 2,599 bytes parent folder | download | duplicates (8)
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
# -*- shell-script -*-
#
# Copyright (C) 2012 GraphicsMagick Group
#
# TAP-test implementation functions specific to GraphicsMagick.
#
test_count=0

# Populate a set of shell variables with a variable per feature
# This is used to implement a poor-man's hash map.
for feature in ${MAGICK_FEATURES}
do
    eval MAGICK_FEATURE_${feature}=yes
done

# Report the number of TAP tests we will subsequently run
#
# Usage:
#   test_plan_fn integer
test_plan_fn ()
{
    #set +x
    tests_planned=$1
    echo "1..${tests_planned}"
    #set -x
}

# Report TAP test result and increment current test count
#
# Usage:
#   test_result_fn result description
test_result_fn ()
{
    #set +x
    test_result=$1
    shift
    #test_count=$(($test_count + 1))
    test_count=`expr $test_count + 1`
    test_output="${test_result} ${test_count}"
    if test x"$*" != x
    then
        test_output="${test_output} - $*"
    fi
    printf '%s\n' "${test_output}"
    #set -x
}

# Test a simple command where pass/fail depends on command exit status
#
# Usage:
#   test_command_fn description [ -F 'feat1 feat2 ...'] command
#
# Where:
#    description -- test description
#    -F          -- optional space-delimited required features
#    command     -- command to execute
test_command_fn ()
{
    #set +x
    test_description=$1
    shift

    # Parse any feature dependency specification (-F 'feat1 feat2 ...'
    test_feature_spec=''
    while test $# -gt 0
    do
        case $1 in
            -F)
                test_feature_spec=$2
                shift
                ;;
            *)
                break
                ;;
        esac
        shift
    done

    missing=''
    for feature in ${test_feature_spec}
    do
        # Check if required feature is supported
        if eval test \""\$MAGICK_FEATURE_${feature}"\" != yes
        then
            if test "${missing}x" = 'x'
            then
                missing=${feature}
            else
                missing="${missing} ${feature}"
            fi
        fi
    done

    # Determine if we expect this test to fail due to missing
    # dependencies.
    diagnosis=
    if test "${missing}x" != 'x'
    then
        xfail='yes'
        diagnosis=" # SKIP requires ${missing} support"
    else
        xfail='no'
        diagnosis=
    fi

    # Execute the test and determine execution status
    echo "EXEC: $@"
    ("$@") && fail='no' || fail='yes'

    test "${xfail}" = "${fail}" && test_result='ok' || test_result='not ok'

    # Report results
    test_result_fn "${test_result}" "${test_description}${diagnosis}"
    #set -x
}