summaryrefslogtreecommitdiff
path: root/check
blob: 82774119cefb339bbc0b27474d04f6bd896a30f6 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/sh
#
# Run test suite for morph.
#
# Copyright (C) 2011-2014  Codethink Limited
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


set -e


# Parse the command line.

run_style=false
run_unit_tests=false
run_cmdtests=false
run_slow_cmdtests=false
run_yarns=false
if [ "$#" -eq 0 ]; then
    run_style=true
    run_unit_tests=true
    run_cmdtests=true
    run_slow_cmdtests=false
    run_yarns=true
fi
while [ "$#" -gt 0 ]
do
    case "$1" in
    --full)
        run_style=true
        run_unit_tests=true
        run_cmdtests=true
        run_slow_cmdtests=true
        run_yarns=true
        ;;
    --style)
        run_style=true
        ;;
    --no-style)
        run_style=false
        ;;
    --unit-tests)
        run_unit_tests=true
        ;;
    --no-unit-tests)
        run_unit_tests=false
        ;;
    --cmdtests)
        run_cmdtests=true
        ;;
    --no-cmdtests)
        run_cmdtests=false
        ;;
    --slow-cmdtests)
        run_slow_cmdtests=true
        ;;
    --no-slow-cmdtests)
        run_slow_cmdtests=false
        ;;
    --yarns)
        run_yarns=true
        ;;
    --no-yarns)
        run_yarns=false
        ;;
    *) echo "ERROR: Unknown argument $1." 1>&2; exit 1 ;;
    esac
    shift
done


# Set PYTHONPATH to start with the current directory so that we always
# find the right version of it for the test suite.

case "$PYTHONPATH" in
    '') PYTHONPATH="$(pwd)" ;;
    *) PYTHONPATH="$(pwd):$PYTHONPATH" ;;
esac
export PYTHONPATH

# Run the style checks

if "$run_style" && [ -d .git ];
then
    echo "Checking copyright statements"
    if ! (git ls-files --cached -z |
          xargs -0r scripts/check-copyright-year); then
        exit 1
    fi

    echo 'Checking source code for silliness'
    if ! (git ls-files --cached |
          grep -v '\.gz$' |
          grep -Ev 'tests[^/]*/.*\.std(out|err)' |
          grep -vF 'tests.build/build-system-autotools.script' |
          xargs -r scripts/check-silliness); then
        exit 1
    fi
fi

# Clean up artifacts from previous (possibly failed) runs, build,
# and run the tests.

if "$run_unit_tests"; then
    python setup.py clean check
fi

# Run scenario tests with yarn, if yarn is available.
#
# Yarn cleans up the environment when it runs tests, and this removes
# PYTHONPATH from the environment. However, we need our tests to have
# the PYTHONPATH, so that we can get them to, for example, use the right
# versions of updated dependencies.  The immediate current need is to
# be able to get them to use an updated version of cliapp, but it is
# a general need.
#
# We solve this by using the yarn --env option, allowing us to tell yarn
# explicitly which environment variables to set in addition to the set
# it sets anyway.

if "$run_yarns" && command -v yarn > /dev/null
then
    yarn --env "PYTHONPATH=$PYTHONPATH" -s yarns/morph.shell-lib yarns/*.yarn
fi

# cmdtest tests.

HOME="$(pwd)/scripts"

if "$run_cmdtests"
then
    cmdtest tests
else
    echo "NOT RUNNING test"
fi

if "$run_slow_cmdtests"
then
    cmdtest tests.branching
else
    echo "NOT RUNNING test.branching"
fi

if false && "$run_cmdtests"
then
    cmdtest tests.merging
else
    echo "NOT RUNNING test.merging"
fi

if "$run_cmdtests"
then
    cmdtest tests.deploy
else
    echo "NOT RUNNING test.deploy"
fi

# Building systems requires the 'filter' parameter of tarfile.TarFile.add():
# this was introduced in Python 2.7
if ! "$run_cmdtests"; then
    echo "NOT RUNNING tests.build"
elif ! (python --version 2>&1 | grep -q '^Python 2\.[78]'); then
    echo "NOT RUNNING tests.build (requires Python 2.7)"
else
    cmdtest tests.build
fi

# The as-root tests use YAML morphologies, so they require the PyYAML module.
if ! "$run_slow_cmdtests"; then
    echo "NOT RUNNING tests.as-root"
elif [ $(whoami) != root ] || ! command -v mkfs.btrfs > /dev/null; then
    echo "NOT RUNNING tests.as-root (no btrfs)"
elif ! python -c "
import morphlib, sys
if not morphlib.got_yaml:
    sys.exit(1)
" > /dev/null 2>&1
then
    echo "NOT RUNNING tests.as-root (requires PyYAML)"
else
    cmdtest tests.as-root
fi