📄 pg_regress.sh
字号:
mv $conv $backup sed -e "s@\$libdir@$pkglibdir@g" $backup > $conv rm $backup message "initializing database system" [ "$debug" = yes ] && initdb_options='--debug' "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1 if [ $? -ne 0 ] then echo echo "$me: initdb failed" echo "Examine $LOGDIR/initdb.log for the reason." echo (exit 2); exit fi # ---------- # Start postmaster # ---------- message "starting postmaster" [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5" [ "$unix_sockets" = no ] && postmaster_options="$postmaster_options -i" "$bindir/postmaster" -D "$PGDATA" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 & postmaster_pid=$! # Wait till postmaster is able to accept connections (normally only # a second or so, but Cygwin is reportedly *much* slower). Don't # wait forever, however. i=0 max=60 until "$bindir/psql" $psql_options template1 </dev/null 2>/dev/null do i=`expr $i + 1` if [ $i -ge $max ] then break fi if kill -0 $postmaster_pid >/dev/null 2>&1 then : still starting up else break fi sleep 1 done if kill -0 $postmaster_pid >/dev/null 2>&1 then echo "running on port $PGPORT with pid $postmaster_pid" else echo echo "$me: postmaster did not start" echo "Examine $LOGDIR/postmaster.log for the reason." echo (exit 2); exit fielse # not temp-install # If Unix sockets are not available, use the local host by default. if [ "$unix_sockets" = no ]; then PGHOST=$hostname export PGHOST unset PGHOSTADDR fi if [ -n "$PGPORT" ]; then port_info="port $PGPORT" else port_info="default port" fi if [ -n "$PGHOST" ]; then echo "(using postmaster on $PGHOST, $port_info)" else echo "(using postmaster on Unix socket, $port_info)" fi message "dropping database \"$dbname\"" "$bindir/dropdb" $psql_options "$dbname" # errors can be ignoredfi# ----------# Set up SQL shell for the test.# ----------PSQL="$bindir/psql -a -q -X $psql_options"# ----------# Set frontend timezone and datestyle explicitly# ----------PGTZ='PST8PDT'; export PGTZPGDATESTYLE='Postgres, MDY'; export PGDATESTYLE# ----------# Set up multibyte environment# ----------if [ -n "$multibyte" ]; then PGCLIENTENCODING=$multibyte export PGCLIENTENCODING encoding_opt="-E $multibyte"else unset PGCLIENTENCODINGfi# ----------# Create the regression database# We use template0 so that any installation-local cruft in template1# will not mess up the tests.# ----------message "creating database \"$dbname\"""$bindir/createdb" $encoding_opt $psql_options --template template0 "$dbname"if [ $? -ne 0 ]; then echo "$me: createdb failed" (exit 2); exitfi"$bindir/psql" $psql_options -c "\alter database \"$dbname\" set lc_messages to 'C';alter database \"$dbname\" set lc_monetary to 'C';alter database \"$dbname\" set lc_numeric to 'C';alter database \"$dbname\" set lc_time to 'C';" "$dbname" 2>/dev/nullif [ $? -ne 0 ]; then echo "$me: could not set database default locales" (exit 2); exitfi# ----------# Remove regressuser* and regressgroup* user accounts.# ----------message "dropping regression test user accounts""$bindir/psql" $psql_options -c 'DROP GROUP regressgroup1; DROP GROUP regressgroup2; DROP USER regressuser1, regressuser2, regressuser3, regressuser4;' $dbname 2>/dev/nullif [ $? -eq 2 ]; then echo "$me: could not drop user accounts" (exit 2); exitfi# ----------# Install the PL/pgSQL language in it# ----------if [ "$enable_shared" = yes ]; then message "installing PL/pgSQL" "$bindir/createlang" -L "$pkglibdir" $psql_options plpgsql $dbname if [ $? -ne 0 ] && [ $? -ne 2 ]; then echo "$me: createlang failed" (exit 2); exit fifi# ----------# Let's go# ----------message "running regression test queries"if [ ! -d "$outputdir/results" ]; then mkdir -p "$outputdir/results" || { (exit 2); exit; }firesult_summary_file=$outputdir/regression.outdiff_file=$outputdir/regression.diffscat /dev/null >"$result_summary_file"cat /dev/null >"$diff_file"lno=0( [ "$enable_shared" != yes ] && echo "ignore: plpgsql" cat $schedule </dev/null for x in $extra_tests; do echo "test: $x" done) | sed 's/[ ]*#.*//g' | \while read linedo # Count line numbers lno=`expr $lno + 1` [ -z "$line" ] && continue set X $line; shift if [ x"$1" = x"ignore:" ]; then shift ignore_list="$ignore_list $@" continue elif [ x"$1" != x"test:" ]; then echo "$me:$schedule:$lno: syntax error" (exit 2); exit fi shift # ---------- # Start tests # ---------- if [ $# -eq 1 ]; then # Run a single test formatted=`echo $1 | awk '{printf "%-20.20s", $1;}'` $ECHO_N "test $formatted ... $ECHO_C" $PSQL -d "$dbname" <"$inputdir/sql/$1.sql" >"$outputdir/results/$1.out" 2>&1 else # Start a parallel group $ECHO_N "parallel group ($# tests): $ECHO_C" if [ $maxconnections -gt 0 ] ; then connnum=0 test $# -gt $maxconnections && $ECHO_N "(in groups of $maxconnections) $ECHO_C" fi for name do ( $PSQL -d "$dbname" <"$inputdir/sql/$name.sql" >"$outputdir/results/$name.out" 2>&1 $ECHO_N " $name$ECHO_C" ) & if [ $maxconnections -gt 0 ] ; then connnum=`expr \( $connnum + 1 \) % $maxconnections` test $connnum -eq 0 && wait fi done wait echo fi # ---------- # Run diff # (We do not want to run the diffs immediately after each test, # because they would certainly get corrupted if run in parallel # subshells.) # ---------- for name do if [ $# -ne 1 ]; then formatted=`echo "$name" | awk '{printf "%-20.20s", $1;}'` $ECHO_N " $formatted ... $ECHO_C" fi # Check list extracted from resultmap to see if we should compare # to a system-specific expected file. # There shouldn't be multiple matches, but take the last if there are. EXPECTED="$inputdir/expected/${name}" for LINE in $SUBSTLIST do if [ `expr "$LINE" : "$name="` -ne 0 ] then SUBST=`echo "$LINE" | sed 's/^.*=//'` EXPECTED="$inputdir/expected/${SUBST}" fi done # If there are multiple equally valid result files, loop to get the right one. # If none match, diff against the closest one. bestfile= bestdiff= result=2 for thisfile in $EXPECTED.out ${EXPECTED}_[0-9].out; do [ ! -r "$thisfile" ] && continue diff $DIFFFLAGS $thisfile $outputdir/results/${name}.out >/dev/null 2>&1 result=$? case $result in 0) break;; 1) thisdiff=`diff $DIFFFLAGS $thisfile $outputdir/results/${name}.out | wc -l` if [ -z "$bestdiff" ] || [ "$thisdiff" -lt "$bestdiff" ]; then bestdiff=$thisdiff; bestfile=$thisfile fi continue;; 2) break;; esac done # Now print the result. case $result in 0) echo "ok";; 1) ( diff $DIFFFLAGS -C3 $bestfile $outputdir/results/${name}.out echo echo "======================================================================" echo ) >> "$diff_file" if echo " $ignore_list " | grep " $name " >/dev/null 2>&1 ; then echo "failed (ignored)" else echo "FAILED" fi ;; 2) # desaster struck echo "trouble" 1>&2 (exit 2); exit;; esac donedone | tee "$result_summary_file" 2>&1[ $? -ne 0 ] && exit# ----------# Server shutdown# ----------if [ -n "$postmaster_pid" ]; then message "shutting down postmaster" kill -15 "$postmaster_pid" wait "$postmaster_pid" unset postmaster_pidfirm -f "$TMPFILE"# ----------# Evaluation# ----------count_total=`cat "$result_summary_file" | grep '\.\.\.' | wc -l | sed 's/ //g'`count_ok=`cat "$result_summary_file" | grep '\.\.\. ok' | wc -l | sed 's/ //g'`count_failed=`cat "$result_summary_file" | grep '\.\.\. FAILED' | wc -l | sed 's/ //g'`count_ignored=`cat "$result_summary_file" | grep '\.\.\. failed (ignored)' | wc -l | sed 's/ //g'`echoif [ $count_total -eq $count_ok ]; then msg="All $count_total tests passed." result=0elif [ $count_failed -eq 0 ]; then msg="$count_ok of $count_total tests passed, $count_ignored failed test(s) ignored." result=0elif [ $count_ignored -eq 0 ]; then msg="$count_failed of $count_total tests failed." result=1else msg="`expr $count_failed + $count_ignored` of $count_total tests failed, $count_ignored of these failures ignored." result=1fidashes=`echo " $msg " | sed 's/./=/g'`echo "$dashes"echo " $msg "echo "$dashes"echoif [ -s "$diff_file" ]; then echo "The differences that caused some tests to fail can be viewed in the" echo "file \`$diff_file'. A copy of the test summary that you see" echo "above is saved in the file \`$result_summary_file'." echoelse rm -f "$diff_file" "$result_summary_file"fi(exit $result); exit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -