Parallelize testing. Fix compiletest dependencies.

This commit is contained in:
Sergio Benitez 2017-02-02 00:41:47 -08:00
parent 4d2f695db0
commit d4eda278a2
5 changed files with 37 additions and 56 deletions

View File

@ -9,10 +9,8 @@ fn run_mode(mode: &'static str) {
config.mode = cfg_mode; config.mode = cfg_mode;
config.src_base = PathBuf::from(format!("tests/{}", mode)); config.src_base = PathBuf::from(format!("tests/{}", mode));
let flags = [ let flags = [
"-L ../target/debug/", "-L crate=../target/debug/",
"-L ../target/debug/deps/", "-L dependency=../target/debug/deps/",
"-L target/debug/",
"-L target/debug/deps/"
].join(" "); ].join(" ");
config.target_rustcflags = Some(flags); config.target_rustcflags = Some(flags);

View File

@ -21,3 +21,6 @@ cargo install diesel_cli # install diesel CLI tools
DATABASE_URL=db/db.sql diesel migration run # create db/db.sql DATABASE_URL=db/db.sql diesel migration run # create db/db.sql
``` ```
## Running
Run this example using: `DATABASE_URL=db/db.sql cargo run`

View File

@ -12,3 +12,5 @@ pushd $SCRIPT_PATH > /dev/null
# create db/db.sql # create db/db.sql
diesel migration --database-url=$DATABASE_URL run diesel migration --database-url=$DATABASE_URL run
popd $SCRIPT_PATH > /dev/null popd $SCRIPT_PATH > /dev/null
echo "export DATABASE_URL=$DATABASE_URL"

View File

@ -1,15 +1,17 @@
mod schema {
infer_schema!("db/db.sql");
}
use diesel; use diesel;
use diesel::prelude::*; use diesel::prelude::*;
use diesel::sqlite::SqliteConnection; use diesel::sqlite::SqliteConnection;
use self::schema::tasks; use self::schema::tasks;
use self::schema::tasks::dsl::{tasks as all_tasks, completed as task_completed}; use self::schema::tasks::dsl::{tasks as all_tasks, completed as task_completed};
const DATABASE_FILE: &'static str = env!("DATABASE_URL");
mod schema {
infer_schema!("env:DATABASE_URL");
}
fn db() -> SqliteConnection { fn db() -> SqliteConnection {
SqliteConnection::establish("db/db.sql").expect("Failed to connect to db.") SqliteConnection::establish(DATABASE_FILE).expect("Failed to connect to db.")
} }
#[table_name = "tasks"] #[table_name = "tasks"]

View File

@ -8,23 +8,6 @@ source $SCRIPT_DIR/config.sh
# Add Cargo to PATH. # Add Cargo to PATH.
export PATH=${HOME}/.cargo/bin:${PATH} export PATH=${HOME}/.cargo/bin:${PATH}
# Builds and tests the Cargo project at $1
function build_and_test() {
local dir=$1
if [ -z "${dir}" ] || ! [ -d "${dir}" ]; then
echo "Tried to build and test inside '${dir}', but it is an invalid path."
exit 1
fi
pushd ${dir}
echo ":: Building '${PWD}'..."
RUST_BACKTRACE=1 cargo build --all-features
echo ":: Running unit tests in '${PWD}'..."
RUST_BACKTRACE=1 cargo test --all-features
popd
}
# Checks that the versions for Cargo projects $@ all match # Checks that the versions for Cargo projects $@ all match
function check_versions_match() { function check_versions_match() {
local last_version="" local last_version=""
@ -56,6 +39,26 @@ function ensure_tab_free() {
fi fi
} }
function bootstrap_examples() {
for file in ${EXAMPLES_DIR}/*; do
if [ -d "${file}" ]; then
bootstrap_script="${file}/bootstrap.sh"
if [ -x "${bootstrap_script}" ]; then
echo " Bootstrapping ${file}..."
env_vars=$(${bootstrap_script})
bootstrap_result=$?
if [ $bootstrap_result -ne 0 ]; then
echo " Running bootstrap script (${bootstrap_script}) failed!"
exit 1
else
eval $env_vars
fi
fi
fi
done
}
echo ":: Ensuring all crate versions match..." echo ":: Ensuring all crate versions match..."
check_versions_match "${LIB_DIR}" "${CODEGEN_DIR}" "${CONTRIB_DIR}" check_versions_match "${LIB_DIR}" "${CODEGEN_DIR}" "${CONTRIB_DIR}"
@ -65,35 +68,8 @@ ensure_tab_free
echo ":: Updating dependencies..." echo ":: Updating dependencies..."
cargo update cargo update
echo ":: Cleaning cached crates..." echo ":: Boostrapping examples..."
cargo clean -p rocket bootstrap_examples
cargo clean -p rocket_codegen
cargo clean -p rocket_contrib
echo ":: Building and testing libraries..." echo ":: Building and testing libraries..."
build_and_test "${LIB_DIR}" cargo test --all-features --all
build_and_test "${CODEGEN_DIR}"
build_and_test "${CONTRIB_DIR}"
for file in ${EXAMPLES_DIR}/*; do
if [ -d "${file}" ]; then
bootstrap_script="${file}/bootstrap.sh"
if [ -x "${bootstrap_script}" ]; then
echo ":: Bootstrapping ${file}..."
# We're just going to leave this commented out for next time...
# if [ "$(basename $file)" = "todo" ]; then
# echo ":: Skipping todo example due to broken Diesel..."
# continue
# fi
if ! ${bootstrap_script}; then
echo ":: Running bootstrap script (${bootstrap_script}) failed!"
echo ":: Skipping ${file}."
continue
fi
fi
build_and_test "${file}"
fi
done