From d4eda278a2e614f1ae2fb70533a697d9bab6e5b5 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 2 Feb 2017 00:41:47 -0800 Subject: [PATCH] Parallelize testing. Fix compiletest dependencies. --- codegen/tests/tests.rs | 6 ++-- examples/todo/README.md | 3 ++ examples/todo/bootstrap.sh | 2 ++ examples/todo/src/task.rs | 12 ++++--- scripts/test.sh | 70 +++++++++++++------------------------- 5 files changed, 37 insertions(+), 56 deletions(-) diff --git a/codegen/tests/tests.rs b/codegen/tests/tests.rs index fb6767f5..3f813710 100644 --- a/codegen/tests/tests.rs +++ b/codegen/tests/tests.rs @@ -9,10 +9,8 @@ fn run_mode(mode: &'static str) { config.mode = cfg_mode; config.src_base = PathBuf::from(format!("tests/{}", mode)); let flags = [ - "-L ../target/debug/", - "-L ../target/debug/deps/", - "-L target/debug/", - "-L target/debug/deps/" + "-L crate=../target/debug/", + "-L dependency=../target/debug/deps/", ].join(" "); config.target_rustcflags = Some(flags); diff --git a/examples/todo/README.md b/examples/todo/README.md index c7f81025..355cd6ab 100644 --- a/examples/todo/README.md +++ b/examples/todo/README.md @@ -21,3 +21,6 @@ cargo install diesel_cli # install diesel CLI tools DATABASE_URL=db/db.sql diesel migration run # create db/db.sql ``` +## Running + +Run this example using: `DATABASE_URL=db/db.sql cargo run` diff --git a/examples/todo/bootstrap.sh b/examples/todo/bootstrap.sh index 89aba9da..e1b5aad4 100755 --- a/examples/todo/bootstrap.sh +++ b/examples/todo/bootstrap.sh @@ -12,3 +12,5 @@ pushd $SCRIPT_PATH > /dev/null # create db/db.sql diesel migration --database-url=$DATABASE_URL run popd $SCRIPT_PATH > /dev/null + +echo "export DATABASE_URL=$DATABASE_URL" diff --git a/examples/todo/src/task.rs b/examples/todo/src/task.rs index 8f8935e3..a11a0733 100644 --- a/examples/todo/src/task.rs +++ b/examples/todo/src/task.rs @@ -1,15 +1,17 @@ -mod schema { - infer_schema!("db/db.sql"); -} - use diesel; use diesel::prelude::*; use diesel::sqlite::SqliteConnection; use self::schema::tasks; 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 { - SqliteConnection::establish("db/db.sql").expect("Failed to connect to db.") + SqliteConnection::establish(DATABASE_FILE).expect("Failed to connect to db.") } #[table_name = "tasks"] diff --git a/scripts/test.sh b/scripts/test.sh index 05bd470a..b9de6755 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -8,23 +8,6 @@ source $SCRIPT_DIR/config.sh # Add Cargo to 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 function check_versions_match() { local last_version="" @@ -56,6 +39,26 @@ function ensure_tab_free() { 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..." check_versions_match "${LIB_DIR}" "${CODEGEN_DIR}" "${CONTRIB_DIR}" @@ -65,35 +68,8 @@ ensure_tab_free echo ":: Updating dependencies..." cargo update -echo ":: Cleaning cached crates..." -cargo clean -p rocket -cargo clean -p rocket_codegen -cargo clean -p rocket_contrib +echo ":: Boostrapping examples..." +bootstrap_examples echo ":: Building and testing libraries..." -build_and_test "${LIB_DIR}" -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 +cargo test --all-features --all