-#!/bin/sh
+#!/usr/bin/env bash
set -e
-psql -U lemmy -d postgres -c "DROP DATABASE lemmy;"
-psql -U lemmy -d postgres -c "CREATE DATABASE lemmy;"
+CWD="$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
+
+cd $CWD/../
+
+PACKAGE="$1"
+echo "$PACKAGE"
+
+source scripts/start_dev_db.sh
-export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
# tests are executed in working directory crates/api (or similar),
# so to load the config we need to traverse to the repo root
export LEMMY_CONFIG_LOCATION=../../config/config.hjson
-RUST_BACKTRACE=1 \
+export RUST_BACKTRACE=1
+
+if [ -n "$PACKAGE" ];
+then
+ cargo test -p $PACKAGE --all-features --no-fail-fast
+else
cargo test --workspace --no-fail-fast
+fi
+
# Add this to do printlns: -- --nocapture
+
+pg_ctl stop
+rm -rf $PGDATA