Created
March 7, 2021 23:08
-
-
Save winfamy/a8f7fd6c884f92bd8cc3a460f45b9077 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -u # raise error for uninitialized variables | |
export PGHOST="127.0.0.1" | |
export PGUSER="student" | |
export PGPASSWORD="CompSci364" | |
if which colordiff > /dev/null; then | |
# redefine `diff` as `colordiff` (if available) | |
diff() { | |
command colordiff "$@" | |
} | |
fi | |
errors=0 | |
trap '(( $? && ++errors ))' ERR | |
for i in $(seq --equal-width 1 25); do | |
database='LargeCo' | |
if [ $i -le 5 ]; then | |
database='ConstructCo' | |
fi | |
# setup (e.g., inserting data into tables) | |
if [ -f "test/$i-pre.sql" ]; then | |
psql --dbname="$database" --file="test/$i-pre.sql" --quiet | |
fi | |
psql --dbname="$database" --file="src/$i.sql" --output="/tmp/$i.out" | |
# tear down (e.g., queries used to test non-SELECT statements) | |
if [ -f "test/$i-post.sql" ]; then | |
psql --dbname="$database" --file="test/$i-post.sql" --output="/tmp/$i.out" | |
fi | |
echo "Comparing output for $i..." | |
diff --unified "test/$i.out" "/tmp/$i.out" | |
done | |
echo | |
echo "$errors errors encountered." | |
[ $errors = 0 ] # exit with non-zero status if there were any errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment