forked from folio-org/folio-analytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testall.sh
executable file
·75 lines (75 loc) · 2.18 KB
/
testall.sh
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
#!/bin/bash
#
# Set the following environment variables before running this script:
#
# PGHOST - e.g. "glintcore.net"
# PGDATABASE - e.g. "folio_juniper" or "folio_snapshot"
# PGUSER - database user name
#
# For example:
#
# $ cd sql_metadb/derived_tables/
# $ PGHOST=glintcore.net PGDATABASE=folio_juniper PGUSER=nrn ../../testall.sh
#
set -e
usage() {
echo ''
echo 'Usage: PGHOST=<database-host> PGDATABASE=<database_name> PGUSER=<database_user> testall.sh [<flags>]'
echo ''
echo 'Flags:'
echo '-h Help'
echo '-t Print running time at the beginning of each output line'
}
fmttime='false'
while getopts 'JTcfhtvX' flag; do
case "${flag}" in
h) usage
exit 1 ;;
t) fmttime='true' ;;
*) usage
exit 1 ;;
esac
done
# Check which operating system is running.
case "$(uname -s)" in
Linux*) tmpfile=`pwd`/`mktemp --tmpdir=. tmp-testall-XXXXXXXXXX`
gnutime=/usr/bin/time ;;
Darwin*) tmpfile=`pwd`/`mktemp tmp-testall.XXXXXXXXXX`
gnutime=gtime ;;
*) echo "testall.sh: unsupported operating system: `uname -s`" 1>&2
exit 1 ;;
esac
# Run all queries.
trap 'rm -f -- "$tmpfile"' EXIT
if $fmttime; then
gtimefmt='%e'
else
gtimefmt='%es'
fi
IFS=$'\n'
for d in $( find `pwd` -type d ); do
cd "$d"
# Check that the runlist exists.
if [[ ! -f runlist.txt ]]; then
continue
fi
echo ""
echo "###############################################################################"
echo "# $d"
echo "###############################################################################"
# Check for duplicates in runlist.
if [[ $(sort runlist.txt | uniq -d) ]]; then
echo "testall.sh: runlist.txt contains duplicates: `sort runlist.txt | uniq -d`" 1>&2
exit 1
fi
for f in $( cat runlist.txt ); do
if ! PGOPTIONS='--client-min-messages=warning' $gnutime -o $tmpfile -f $gtimefmt psql -P pager -c '\set ON_ERROR_STOP on' -f $f -Xq ; then
exit 1
fi
if $fmttime; then
printf '%s\t%-50s\n' `cat $tmpfile` $f
else
printf 'ok\t%-50s\t%s\n' $f `cat $tmpfile`
fi
done || exit 1
done || exit 1