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