summaryrefslogtreecommitdiff
path: root/menu/tests/menutest
blob: 6061ba8a62625d6ff9963e2da363abb9d8977845 (plain)
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
122
123
124
125
126
127
#!/bin/bash

function installData()
{
  local DIR=$1
  shift 1
  mkdir -p ${DIR}
  for file in $*; do 
    cp data/${file} ${DIR}
  done
}

function installDataAs()
{
  local DIR=$1
  mkdir -p ${DIR}
  cp data/$2 ${DIR}/$3
}

if [ "x${MENUTEST}" == "x" ]; then
  echo 'To run the test set $MENUTEST to your menu-spec implementation.'
  exit 1
fi

if [ "x${MENUTESTDIR}" == "x" ]; then
  MENUTESTDIR=/tmp/menutestdir
  echo Using ${MENUTESTDIR} as test directory, override with '$MENUTESTDIR.'
else
  echo Using ${MENUTESTDIR} as test directory.
fi

export MENUTESTDIR

if [ "x${TESTS}" == "x" ]; then
	TESTS=`ls tests`
fi

FAILED=
SUCCEEDED=
for TEST in ${TESTS}; do
  if [ "${TEST}" == "CVS" ]; then
    continue
  fi

  echo
  rm -rf ${MENUTESTDIR} 2> /dev/null
  mkdir ${MENUTESTDIR}
  RESULT=tests/${TEST}/result

  (
    echo ">>> Running test ${TEST}"

    # Some predefined values
    XDG_CONFIG_HOME=${MENUTESTDIR}/xdg_config_home
    XDG_DATA_HOME=${MENUTESTDIR}/xdg_data_home
    XDG_CONFIG_DIR=${MENUTESTDIR}/xdg_config_dir
    XDG_DATA_DIR=${MENUTESTDIR}/xdg_data_dir
    XDG_CONFIG_DIRS=$XDG_CONFIG_DIR
    XDG_DATA_DIRS=$XDG_DATA_DIR

    export XDG_CONFIG_HOME
    export XDG_DATA_HOME
    export XDG_CONFIG_DIR
    export XDG_DATA_DIR
    export XDG_CONFIG_DIRS
    export XDG_DATA_DIRS

     . tests/${TEST}/test

    $MENUTEST > ${MENUTESTDIR}/result1 2> ${MENUTESTDIR}/log

    if [ -e ${RESULT} ]; then
      ./expand ${RESULT} > ${MENUTESTDIR}/result2
    fi
  )

  if [ ! -e ${RESULT} ]; then
    echo '!!! Result file ('${RESULT}') for '${TEST}' missing'
    echo '>>> Failed'
    FAILED="${FAILED} ${TEST}"

  else
    if diff -q ${MENUTESTDIR}/result1 ${MENUTESTDIR}/result2 > /dev/null; then
      echo '>>> OK'
      SUCCEEDED="${SUCCEEDED} ${TEST}"
    else
      sort ${MENUTESTDIR}/result1 > ${MENUTESTDIR}/result1.sorted
      sort ${MENUTESTDIR}/result2 > ${MENUTESTDIR}/result2.sorted
      if diff -u ${MENUTESTDIR}/result1.sorted ${MENUTESTDIR}/result2.sorted > ${MENUTESTDIR}/result.diff; then
        echo '>>> OK (different order)'
        SUCCEEDED="${SUCCEEDED} ${TEST}"
      else
        grep ${MENUTESTDIR} ${MENUTESTDIR}/result1 > ${MENUTESTDIR}/result1.filtered 2> /dev/null
        if diff -q ${MENUTESTDIR}/result1.filtered ${MENUTESTDIR}/result2 > /dev/null; then
          echo '>>> OK (additional system items)'
          SUCCEEDED="${SUCCEEDED} ${TEST}"
        else
          grep ${MENUTESTDIR} ${MENUTESTDIR}/result1.sorted > ${MENUTESTDIR}/result1.filtered 2> /dev/null
          if diff -u ${MENUTESTDIR}/result1.filtered ${MENUTESTDIR}/result2.sorted > ${MENUTESTDIR}/result.diff; then
            echo '>>> OK (different order, additional system items)'
            SUCCEEDED="${SUCCEEDED} ${TEST}"
          else
            echo '>>> Failed'
            cat ${MENUTESTDIR}/result.diff
            cat ${MENUTESTDIR}/log
            FAILED="${FAILED} ${TEST}"
          fi
        fi
      fi
    fi
  fi
done


echo "OK tests:     ${SUCCEEDED}"

if ! test -z "${FAILED}" ; then
    echo "Failed tests: ${FAILED}"
fi

echo `echo ${SUCCEEDED} | wc -w`' tests passed, '`echo ${FAILED} | wc -w`' tests failed'

if test -z "${FAILED}" ; then
    exit 0
else
    exit 1
fi