c759ae9cb0405fa8ff6fcd2bc9041ac7e3377a37
[portage.git] / runtests.sh
1 #!/bin/bash
2 # Copyright 2010-2014 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # These are the versions we care about.  The rest are just "nice to have".
6 PYTHON_SUPPORTED_VERSIONS="2.6 2.7 3.2 3.3"
7 PYTHON_VERSIONS="2.6 2.7 2.7-pypy-1.8 2.7-pypy-1.9 2.7-pypy-2.0 3.1 3.2 3.3 3.4"
8
9 # has to be run from portage root dir
10 cd "${0%/*}" || exit 1
11
12 case "${NOCOLOR:-false}" in
13         yes|true)
14                 GOOD=
15                 BAD=
16                 NORMAL=
17                 ;;
18         no|false)
19                 GOOD=$'\e[1;32m'
20                 BAD=$'\e[1;31m'
21                 NORMAL=$'\e[0m'
22                 ;;
23 esac
24
25 interrupted() {
26         echo "interrupted." >&2
27         exit 1
28 }
29
30 trap interrupted SIGINT
31
32 unused_args=()
33 IGNORE_MISSING_VERSIONS=true
34
35 while [ $# -gt 0 ] ; do
36         case "$1" in
37                 --python-versions=*)
38                         PYTHON_VERSIONS=${1#--python-versions=}
39                         IGNORE_MISSING_VERSIONS=false
40                         ;;
41                 --python-versions)
42                         shift
43                         PYTHON_VERSIONS=$1
44                         IGNORE_MISSING_VERSIONS=false
45                         ;;
46                 *)
47                         unused_args[${#unused_args[@]}]=$1
48                         ;;
49         esac
50         shift
51 done
52 if [[ ${PYTHON_VERSIONS} == "supported" ]] ; then
53         PYTHON_VERSIONS=${PYTHON_SUPPORTED_VERSIONS}
54 fi
55
56 set -- "${unused_args[@]}"
57
58 eprefix=${PORTAGE_OVERRIDE_EPREFIX}
59 exit_status="0"
60 found_versions=()
61 status_array=()
62 for version in ${PYTHON_VERSIONS}; do
63         if [[ $version =~ ^([[:digit:]]+\.[[:digit:]]+)-pypy-([[:digit:]]+\.[[:digit:]]+)$ ]] ; then
64                 executable=${eprefix}/usr/bin/pypy-c${BASH_REMATCH[2]}
65         else
66                 executable=${eprefix}/usr/bin/python${version}
67         fi
68         if [[ -x "${executable}" ]]; then
69                 echo -e "${GOOD}Testing with Python ${version}...${NORMAL}"
70                 "${executable}" -Wd pym/portage/tests/runTests "$@"
71                 status=$?
72                 status_array[${#status_array[@]}]=${status}
73                 found_versions[${#found_versions[@]}]=${version}
74                 if [ ${status} -ne 0 ] ; then
75                         echo -e "${BAD}Testing with Python ${version} failed${NORMAL}"
76                         exit_status="1"
77                 fi
78                 echo
79         elif [[ ${IGNORE_MISSING_VERSIONS} != "true" ]] ; then
80                 echo -e "${BAD}Could not find requested Python ${version}${NORMAL}"
81                 exit_status="1"
82         fi
83 done
84
85 if [ ${#status_array[@]} -gt 0 ] ; then
86         max_len=0
87         for version in ${found_versions[@]} ; do
88                 [ ${#version} -gt ${max_len} ] && max_len=${#version}
89         done
90         (( columns = max_len + 2 ))
91         (( columns >= 7 )) || columns=7
92         printf "\nSummary:\n\n"
93         printf "| %-${columns}s | %s\n|" "Version" "Status"
94         (( total_cols = columns + 11 ))
95         eval "printf -- '-%.0s' {1..${total_cols}}"
96         printf "\n"
97         row=0
98         for version in ${found_versions[@]} ; do
99                 if [ ${status_array[${row}]} -eq 0 ] ; then
100                         status="success"
101                 else
102                         status="fail"
103                 fi
104                 printf "| %-${columns}s | %s\n" "${version}" "${status}"
105                 (( row++ ))
106         done
107 fi
108
109 exit ${exit_status}