Repository navigation
Expand file tree
/
Copy pathTest
More file actions
executable file
·75 lines (62 loc) · 2.41 KB
/
Copy pathTest
File metadata and controls
executable file
·75 lines (62 loc) · 2.41 KB
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
#!/usr/bin/env bash
set -Eeuo pipefail
trap 'ec=$?; echo 1>&2 "INTERNAL ERROR: ec=$ec line=$LINENO cmd=$BASH_COMMAND";
exit $ec;' ERR
####################################################################
# First arg is the exit code; remaining args are echoed to stderr.
die() { ec="$1"; shift; echo 1>&2 "ERROR ($ec):" "$@"; exit $ec; }
# The `trap` above will print INTERNAL ERROR on unchecked failures. If
# you're running something you expect may fail, and when it does it's not
# an error in this script, use `|| fail` to instead fail the build.
fail() { ec=$?; echo "FAILED exitcode=$ec ($(elapsed)s)"; exit $ec; }
warn() { echo 1>&2 "WARNING:" "$@"; }
vecho() { [[ -z $verbose ]] && return 0; echo "$@"; }
notverbose() {
# Echo $1 when not verbose, otherwise nothing.
# E.g. `$(notverbose --quiet)`.
[[ -z $verbose ]] && echo $1 || true;
}
elapsed_start=$(date +%s)
elapsed() { echo $(( $(date +%s) - $elapsed_start )); }
####################################################################
# Build functions
cleanbig() {
rm -rf "$PROJDIR/.build/"
}
cleansmall() {
rm -rf "$PROJDIR/.build/"
}
####################################################################
# Argparse, main
usage() {
cat <<_____
Usage: Test [OPTS] [-- PYTEST-OPTS]
Options:
-c small clean: whatever can be rebuilt quickly
-C big clean: everything, but causes slow builds
-T skip mypy type-checking
-v verbose mode (multiple use increases verbosity)
-- pass all subsequent arguments to pytest
_____
}
export PROJDIR=$(cd "$(dirname "$0")" && pwd -P)
skip_mypy=false
verbose='' # zero or more '-v's
while [[ $# -gt 0 ]]; do case "$1" in
-h|--help) shift; usage; exit 0;;
-C) shift; cleanbig;;
-c) shift; cleansmall;;
-T) shift; skip_mypy=true;;
-v) shift; verbose="$verbose -v";; # add another -v
--) shift; break;;
*) die 2 "Unknown argument '$1'; use -- before pytest arguments";;
esac; done
source "$PROJDIR"/pactivate $(notverbose -q)
vecho '───── mypy'
$skip_mypy || mypy "${@:-.}"
vecho '───── pytest'
pytest -q $verbose "$PROJDIR" "$@" || fail
vecho '───── functional test'
tanuki --help | grep -q '^usage: tanuki' \
|| die 1 "tanuki --help: missing or unexpected output"
echo "───── OK ($(elapsed)s)"