diff --git a/test/0-init-fail-json.sh b/test/0-init-fail-json.sh index 63ebb5a12..069014e14 100755 --- a/test/0-init-fail-json.sh +++ b/test/0-init-fail-json.sh @@ -1,9 +1,13 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-fail-pack" deps="logger PACKAGE_DONT_EXIST" # would be very unlucky if it does exist... -$DUB init -n $packname $deps -f json +if $$DUB init -n $packname $deps -f json 2>/dev/null; then + die $LINENO 'Init with unknown non-existing dependency expected to fail' +fi + function cleanup { rm -rf $packname @@ -11,6 +15,5 @@ function cleanup { if [ -e $packname/dub.json ]; then # package is there, it should have failed cleanup - exit 1 + die $LINENO "$packname/dub.json was not created" fi -exit 0 diff --git a/test/0-init-fail.sh b/test/0-init-fail.sh index db594b2c6..c440a5781 100755 --- a/test/0-init-fail.sh +++ b/test/0-init-fail.sh @@ -1,9 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-fail-pack" deps="logger PACKAGE_DONT_EXIST" # would be very unlucky if it does exist... -$DUB init -n $packname $deps +if $DUB init -n $packname $deps 2>/dev/null; then + die $LINENO 'Init with unknown non-existing dependency expected to fail' +fi function cleanup { rm -rf $packname @@ -11,6 +14,5 @@ function cleanup { if [ -e $packname/dub.sdl ]; then # package is there, it should have failed cleanup - exit 1 + die $LINENO "$packname/dub.sdl was not created" fi -exit 0 diff --git a/test/0-init-interactive.sh b/test/0-init-interactive.sh index 65065f329..945838bd7 100755 --- a/test/0-init-interactive.sh +++ b/test/0-init-interactive.sh @@ -1,5 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-interactive" echo -e "sdl\ntest\ndesc\nauthor\ngpl\ncopy\n\n" | $DUB init $packname @@ -9,16 +10,13 @@ function cleanup { } if [ ! -e $packname/dub.sdl ]; then # it failed - echo "No dub.sdl file has been generated." cleanup - exit 1 + die $LINENO 'No dub.sdl file has been generated.' fi if ! diff $packname/dub.sdl "$CURR_DIR"/0-init-interactive.dub.sdl; then - echo "Contents of generated dub.sdl not as expected." - cleanup - exit 1 + cleanup + die $LINENO 'Contents of generated dub.sdl not as expected.' fi cleanup -exit 0 diff --git a/test/0-init-multi-json.sh b/test/0-init-multi-json.sh index c9fd92d21..239c419cb 100755 --- a/test/0-init-multi-json.sh +++ b/test/0-init-multi-json.sh @@ -1,5 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-multi-pack" deps="openssl logger" type="vibe.d" @@ -10,20 +11,17 @@ function cleanup { rm -rf $packname } -if [ ! -e $packname/dub.json ]; then # it failed, exit 1 - exit 1 +if [ ! -e $packname/dub.json ]; then + die $LINENO '$packname/dub.json not created' else # check if resulting dub.json has all dependencies in tow deps="$deps vibe-d"; IFS=" " read -a arr <<< "$deps" for ele in "${arr[@]}" do if [ `grep -c "$ele" $packname/dub.json` -ne 1 ]; then #something went wrong - echo "$ele not in $packname/dub.json" cleanup - exit 1 + die $LINENO "$ele not in $packname/dub.json" fi done cleanup - exit 0 - fi diff --git a/test/0-init-multi.sh b/test/0-init-multi.sh index a03694e20..8432b969c 100755 --- a/test/0-init-multi.sh +++ b/test/0-init-multi.sh @@ -1,5 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-multi-pack" deps="openssl logger" type="vibe.d" @@ -10,22 +11,18 @@ function cleanup { rm -rf $packname } -if [ ! -e $packname/dub.sdl ]; then # it failed, exit 1 - echo "No dub.sdl file has been generated." +if [ ! -e $packname/dub.sdl ]; then cleanup - exit 1 + die $LINENO 'No dub.sdl file has been generated.' else # check if resulting dub.sdl has all dependencies in tow deps="$deps vibe-d"; IFS=" " read -a arr <<< "$deps" for ele in "${arr[@]}" do if [ `grep -c "$ele" $packname/dub.sdl` -ne 1 ]; then #something went wrong - echo "$ele not in $packname/dub.sdl" cleanup - exit 1 + die $LINENO "$ele not in $packname/dub.sdl" fi done cleanup - exit 0 - fi diff --git a/test/0-init-simple-json.sh b/test/0-init-simple-json.sh index a18bd3d83..2a7ec8a0c 100755 --- a/test/0-init-simple-json.sh +++ b/test/0-init-simple-json.sh @@ -1,5 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-simple-pack" $DUB init -n $packname -f json @@ -8,9 +9,8 @@ function cleanup { rm -rf $packname } -if [ ! -e $packname/dub.json ]; then # it failed +if [ ! -e $packname/dub.json ]; then cleanup - exit 1 + die $LINENO 'No dub.json file has been generated.' fi cleanup -exit 0 diff --git a/test/0-init-simple.sh b/test/0-init-simple.sh index 6b25f5a9f..f4fee2eba 100755 --- a/test/0-init-simple.sh +++ b/test/0-init-simple.sh @@ -1,5 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh packname="0-init-simple-pack" $DUB init -n $packname --format sdl @@ -9,9 +10,7 @@ function cleanup { } if [ ! -e $packname/dub.sdl ]; then # it failed - echo "No dub.sdl file has been generated." cleanup - exit 1 + die $LINENO 'No dub.sdl file has been generated.' fi cleanup -exit 0 diff --git a/test/4-describe-data-1-list.sh b/test/4-describe-data-1-list.sh index aefbf7828..3cfe5dc19 100755 --- a/test/4-describe-data-1-list.sh +++ b/test/4-describe-data-1-list.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/describe-project @@ -30,7 +30,7 @@ if ! $DUB describe --compiler=$DC --data-list \ --data=post-build-commands \ '--data=requirements, options' \ > "$temp_file"; then - die 'Printing project data failed!' + die $LINENO 'Printing project data failed!' fi # Create the expected output path file to compare against. @@ -134,6 +134,6 @@ echo "warnings" >> "$expected_file" #echo "stackStomping" >> "$expected_file" # Not sure if this (from a sourceLib dependency) should be missing from the result if ! diff "$expected_file" "$temp_file"; then - die 'The project data did not match the expected output!' + die $LINENO 'The project data did not match the expected output!' fi diff --git a/test/4-describe-data-2-dmd.sh b/test/4-describe-data-2-dmd.sh index 3f307694a..d323bc503 100755 --- a/test/4-describe-data-2-dmd.sh +++ b/test/4-describe-data-2-dmd.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh if [ "${DC}" != "dmd" ]; then echo Skipping DMD-centric test on configuration that lacks DMD. diff --git a/test/4-describe-data-3-zero-delim.sh b/test/4-describe-data-3-zero-delim.sh index 2d6738b03..aee4d08fb 100755 --- a/test/4-describe-data-3-zero-delim.sh +++ b/test/4-describe-data-3-zero-delim.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/describe-project diff --git a/test/4-describe-import-paths.sh b/test/4-describe-import-paths.sh index ba03205a8..375bc4001 100755 --- a/test/4-describe-import-paths.sh +++ b/test/4-describe-import-paths.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/describe-project diff --git a/test/4-describe-json.sh b/test/4-describe-json.sh index 56415953b..21f5105e6 100755 --- a/test/4-describe-json.sh +++ b/test/4-describe-json.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/describe-project diff --git a/test/4-describe-string-import-paths.sh b/test/4-describe-string-import-paths.sh index aa649796b..c1106a683 100755 --- a/test/4-describe-string-import-paths.sh +++ b/test/4-describe-string-import-paths.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/describe-project diff --git a/test/5-convert-stdout.sh b/test/5-convert-stdout.sh index 86cba02a4..ae7b491d9 100755 --- a/test/5-convert-stdout.sh +++ b/test/5-convert-stdout.sh @@ -1,6 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash -set -e +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/1-exec-simple @@ -10,16 +10,13 @@ targetType \"executable\"" RESULT=`${DUB} convert -s -f sdl` if [ ! -f dub.json ]; then - echo "Package recipe got modified!" - exit 1 + die $LINENO 'Package recipe got modified!' fi if [ -f dub.sdl ]; then - echo "An SDL recipe got written." - exit 2 + die $LINENO 'An SDL recipe got written.' fi if [ "$RESULT" != "$EXPECTED" ]; then - echo "Unexpected SDLang output." - exit 3 + die $LINENO 'Unexpected SDLang output.' fi diff --git a/test/5-convert.sh b/test/5-convert.sh index fac1360c3..5cdbaa91d 100755 --- a/test/5-convert.sh +++ b/test/5-convert.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/5-convert @@ -9,31 +9,23 @@ temp_file=$(mktemp $(basename $0).XXXXXX) function cleanup { rm $temp_file } - -function die { - echo "$@" 1>&2 - exit 1 -} - trap cleanup EXIT cp dub.sdl dub.sdl.ref $DUB convert -f json -if [ -f "dub.sdl" ]; then die 'Old recipe file not removed.'; fi -if [ ! -f "dub.json" ]; then die 'New recipe file not created.'; fi +if [ -f "dub.sdl" ]; then die $LINENO 'Old recipe file not removed.'; fi +if [ ! -f "dub.json" ]; then die $LINENO 'New recipe file not created.'; fi $DUB convert -f sdl -if [ -f "dub.json" ]; then die 'Old recipe file not removed.'; fi -if [ ! -f "dub.sdl" ]; then die 'New recipe file not created.'; fi +if [ -f "dub.json" ]; then die $LINENO 'Old recipe file not removed.'; fi +if [ ! -f "dub.sdl" ]; then die $LINENO 'New recipe file not created.'; fi if ! diff "dub.sdl" "dub.sdl.ref"; then - die 'The project data did not match the expected output!' + die $LINENO 'The project data did not match the expected output!' fi rm dub.sdl.ref -echo OK - diff --git a/test/common.sh b/test/common.sh new file mode 100644 index 000000000..f464b3c27 --- /dev/null +++ b/test/common.sh @@ -0,0 +1,13 @@ +SOURCE_FILE=$_ + +set -ueEo pipefail + +# lineno[, msg] +function die() { + local line=$1 + local msg=${2:-command failed} + local rc=${3:-1} + >&2 echo "$SOURCE_FILE:$1 Error: $msg" + exit $rc +} +trap 'die $LINENO' ERR diff --git a/test/ddox.sh b/test/ddox.sh index c68e02388..44f836e4b 100755 --- a/test/ddox.sh +++ b/test/ddox.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh (cd $CURR_DIR/ddox/default && $DUB build -b ddox) grep -qF ddox_project $CURR_DIR/ddox/default/docs/index.html diff --git a/test/feat663-search.sh b/test/feat663-search.sh index 1f6f3a4a1..4778a51c9 100755 --- a/test/feat663-search.sh +++ b/test/feat663-search.sh @@ -1,5 +1,12 @@ -#!/bin/bash +#!/usr/bin/env bash -${DUB} search 2>/dev/null && exit 1 -${DUB} search nonexistent123456789package 2>/dev/null && exit 1 -${DUB} search dub | grep -q '^dub' || exit 1 +. $(dirname "${BASH_SOURCE[0]}")/common.sh +if ${DUB} search 2>/dev/null; then + die $LINENO '`dub search` succeeded' +fi +if ${DUB} search nonexistent123456789package 2>/dev/null; then + die $LINENO '`dub search nonexistent123456789package` succeeded' +fi +if ! ${DUB} search dub | grep -q '^dub'; then + die $LINENO '`dub search dub` failed' +fi diff --git a/test/interactive-remove.sh b/test/interactive-remove.sh index a0bb59ea3..f689fdda2 100755 --- a/test/interactive-remove.sh +++ b/test/interactive-remove.sh @@ -1,36 +1,31 @@ -#!/bin/bash +#!/usr/bin/env bash -set -euo pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh $DUB fetch dub --version=0.9.20 && [ -d $HOME/.dub/packages/dub-0.9.20/dub ] $DUB fetch dub --version=0.9.21 && [ -d $HOME/.dub/packages/dub-0.9.21/dub ] if $DUB remove dub --non-interactive 2>/dev/null; then - echo "Non-interactive remove should fail" 1>&2 - exit 1 + die $LINENO 'Non-interactive remove should fail' fi echo 1 | $DUB remove dub | tr --delete '\n' | grep --ignore-case 'select.*0\.9\.20.*0\.9\.21.*' if [ -d $HOME/.dub/packages/dub-0.9.20/dub ]; then - echo "Failed to remove dub-0.9.20" 1>&2 - exit 1 + die $LINENO 'Failed to remove dub-0.9.20' fi $DUB fetch dub --version=0.9.20 && [ -d $HOME/.dub/packages/dub-0.9.20/dub ] # EOF aborts remove echo -xn '' | $DUB remove dub if [ ! -d $HOME/.dub/packages/dub-0.9.20/dub ] || [ ! -d $HOME/.dub/packages/dub-0.9.21/dub ]; then - echo "Aborted dub still removed a package" 1>&2 - exit 1 + die $LINENO 'Aborted dub still removed a package' fi # validates input echo -e 'abc\n4\n-1\n3' | $DUB remove dub if [ -d $HOME/.dub/packages/dub-0.9.20/dub ] || [ -d $HOME/.dub/packages/dub-0.9.21/dub ]; then - echo "Failed to remove all version of dub" 1>&2 - exit 1 + die $LINENO 'Failed to remove all version of dub' fi $DUB fetch dub --version=0.9.20 && [ -d $HOME/.dub/packages/dub-0.9.20/dub ] $DUB fetch dub --version=0.9.21 && [ -d $HOME/.dub/packages/dub-0.9.21/dub ] # is non-interactive with --version= $DUB remove dub --version=\* if [ -d $HOME/.dub/packages/dub-0.9.20/dub ] || [ -d $HOME/.dub/packages/dub-0.9.21/dub ]; then - echo 'Failed to non-interactively remove specified versions' 1>&2 - exit 1 + die $LINENO 'Failed to non-interactively remove specified versions' fi diff --git a/test/issue1004-override-config.sh b/test/issue1004-override-config.sh index 7bcd4434d..96080f18b 100755 --- a/test/issue1004-override-config.sh +++ b/test/issue1004-override-config.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue1004-override-config -${DUB} build --bare main --override-config a/success || exit 1 +${DUB} build --bare main --override-config a/success diff --git a/test/issue1005-configuration-resolution.sh b/test/issue1005-configuration-resolution.sh index 3665a5eff..1233e76df 100755 --- a/test/issue1005-configuration-resolution.sh +++ b/test/issue1005-configuration-resolution.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue1005-configuration-resolution -${DUB} build --bare main || exit 1 +${DUB} build --bare main diff --git a/test/issue1024-selective-upgrade.sh b/test/issue1024-selective-upgrade.sh index a15921679..dc7c00971 100755 --- a/test/issue1024-selective-upgrade.sh +++ b/test/issue1024-selective-upgrade.sh @@ -1,15 +1,14 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue1024-selective-upgrade echo "{\"fileVersion\": 1,\"versions\": {\"a\": \"1.0.0\", \"b\": \"1.0.0\"}}" > main/dub.selections.json -$DUB upgrade --bare --root=main a || exit 1 +$DUB upgrade --bare --root=main a if ! grep -c -e "\"a\": \"1.0.1\"" main/dub.selections.json; then - echo "Specified dependency was not upgraded." - exit 1 + die $LINENO "Specified dependency was not upgraded." fi if grep -c -e "\"b\": \"1.0.1\"" main/dub.selections.json; then - echo "Non-specified dependency got upgraded." - exit 1 + die $LINENO "Non-specified dependency got upgraded." fi diff --git a/test/issue103-single-file-package.sh b/test/issue103-single-file-package.sh index 64c58481b..693a926e6 100755 --- a/test/issue103-single-file-package.sh +++ b/test/issue103-single-file-package.sh @@ -1,12 +1,11 @@ -#!/bin/sh -set -e +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR} rm -f single-file-test ${DUB} run --single issue103-single-file-package-json.d --compiler=${DC} if [ ! -f single-file-test ]; then - echo "Normal invocation did not produce a binary in the current directory" - exit 1 + die $LINENO 'Normal invocation did not produce a binary in the current directory' fi rm single-file-test @@ -15,6 +14,5 @@ rm single-file-test ${DUB} issue103-single-file-package-w-dep.d if [ -f single-file-test ]; then - echo "Shebang invocation produced binary in current directory" - exit 1 + die $LINENO 'Shebang invocation produced binary in current directory' fi diff --git a/test/issue1091-bogus-rebuild.sh b/test/issue1091-bogus-rebuild.sh index 689f57248..ae440ebf6 100755 --- a/test/issue1091-bogus-rebuild.sh +++ b/test/issue1091-bogus-rebuild.sh @@ -1,8 +1,8 @@ -#!/bin/sh +#!/usr/bin/env bash -set -e +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/1-exec-simple rm -f dub.selections.json -${DUB} build --compiler=${DC} 2>&1 | grep -e "building configuration" -c || exit 1 -${DUB} build --compiler=${DC} 2>&1 | grep -e "building configuration" -c && exit 1 || exit 0 +${DUB} build --compiler=${DC} 2>&1 | grep -e 'building configuration' -c +${DUB} build --compiler=${DC} 2>&1 | { ! grep -e 'building configuration' -c; } diff --git a/test/issue346-redundant-flags.sh b/test/issue346-redundant-flags.sh index fb88526ff..c6b27f2fb 100755 --- a/test/issue346-redundant-flags.sh +++ b/test/issue346-redundant-flags.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue346-redundant-flags -${DUB} build --bare --force --compiler=${DC} -a x86_64 -v main 2>&1 | grep -e "-m64 -m64" -c && exit 1 || exit 0 +${DUB} build --bare --force --compiler=${DC} -a x86_64 -v main 2>&1 | { ! grep -e '-m64 -m64' -c; } diff --git a/test/issue361-optional-deps.sh b/test/issue361-optional-deps.sh index 69b7f0fcd..db8779449 100755 --- a/test/issue361-optional-deps.sh +++ b/test/issue361-optional-deps.sh @@ -1,5 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue361-optional-deps rm -rf a/.dub rm -rf a/b/.dub @@ -7,20 +8,20 @@ rm -rf main1/.dub rm -rf main2/.dub rm -f main1/dub.selections.json -${DUB} build --bare --compiler=${DC} main1 || exit 1 +${DUB} build --bare --compiler=${DC} main1 echo "{" > cmp.tmp echo " \"fileVersion\": 1," >> cmp.tmp echo " \"versions\": {" >> cmp.tmp echo " \"b\": \"~master\"" >> cmp.tmp echo " }" >> cmp.tmp echo "}" >> cmp.tmp -diff cmp.tmp main1/dub.selections.json || exit 1 +diff cmp.tmp main1/dub.selections.json -${DUB} build --bare --compiler=${DC} main2 || exit 1 +${DUB} build --bare --compiler=${DC} main2 echo "{" > cmp.tmp echo " \"fileVersion\": 1," >> cmp.tmp echo " \"versions\": {" >> cmp.tmp echo " \"a\": \"~master\"" >> cmp.tmp echo " }" >> cmp.tmp echo "}" >> cmp.tmp -diff cmp.tmp main2/dub.selections.json || exit 1 +diff cmp.tmp main2/dub.selections.json diff --git a/test/issue564-invalid-upgrade-dependency.sh b/test/issue564-invalid-upgrade-dependency.sh index a1af6bd1d..19258cec2 100755 --- a/test/issue564-invalid-upgrade-dependency.sh +++ b/test/issue564-invalid-upgrade-dependency.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue564-invalid-upgrade-dependency rm -rf a-1.0.0/.dub rm -rf a-1.1.0/.dub rm -rf main/.dub -${DUB} build --bare --compiler=${DC} main || exit 1 +${DUB} build --bare --compiler=${DC} main diff --git a/test/issue586-subpack-dep.sh b/test/issue586-subpack-dep.sh index fe0ad5fe2..306bca74b 100755 --- a/test/issue586-subpack-dep.sh +++ b/test/issue586-subpack-dep.sh @@ -1,8 +1,9 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue586-subpack-dep rm -rf a/.dub rm -rf a/b/.dub rm -rf main/.dub -${DUB} build --bare --compiler=${DC} main || exit 1 -${DUB} run --bare --compiler=${DC} main || exit 1 +${DUB} build --bare --compiler=${DC} main +${DUB} run --bare --compiler=${DC} main diff --git a/test/issue613-dynlib-pic.sh b/test/issue613-dynlib-pic.sh index d7e90b740..b8fc5e702 100755 --- a/test/issue613-dynlib-pic.sh +++ b/test/issue613-dynlib-pic.sh @@ -1,10 +1,10 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue613-dynlib-pic rm -rf .dub if [ "${DC}" = "dmd" ]; then - ${DUB} build --compiler=${DC} || exit 1 + ${DUB} build --compiler=${DC} else echo "Skipping shared library test for ${DC}..." fi - diff --git a/test/issue616-describe-vs-generate-commands.sh b/test/issue616-describe-vs-generate-commands.sh index 8f85c099d..698ef6363 100755 --- a/test/issue616-describe-vs-generate-commands.sh +++ b/test/issue616-describe-vs-generate-commands.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set -e -o pipefail +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd "$CURR_DIR"/issue616-describe-vs-generate-commands diff --git a/test/issue672-upgrade-optional.sh b/test/issue672-upgrade-optional.sh index 8c16aa6f8..15e07d2e9 100755 --- a/test/issue672-upgrade-optional.sh +++ b/test/issue672-upgrade-optional.sh @@ -1,11 +1,11 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue672-upgrade-optional rm -rf b/.dub echo "{\"fileVersion\": 1,\"versions\": {\"dub\": \"1.0.0\"}}" > dub.selections.json -${DUB} upgrade || exit 1 +${DUB} upgrade if ! grep -c -e "\"dub\": \"1.1.0\"" dub.selections.json; then - echo "Dependency not upgraded." - exit 1 + die $LINENO 'Dependency not upgraded.' fi diff --git a/test/issue672-upgrade-optional/dub.selections.json b/test/issue672-upgrade-optional/dub.selections.json index 44b07d410..712a9f610 100644 --- a/test/issue672-upgrade-optional/dub.selections.json +++ b/test/issue672-upgrade-optional/dub.selections.json @@ -1,6 +1,6 @@ { "fileVersion": 1, "versions": { - "dub": "1.0.0" + "dub": "1.1.0" } } diff --git a/test/issue674-concurrent-dub.sh b/test/issue674-concurrent-dub.sh index d1cfadde8..d49bdd3ec 100755 --- a/test/issue674-concurrent-dub.sh +++ b/test/issue674-concurrent-dub.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -e -o pipefail +. $(dirname "${BASH_SOURCE[0]}")/common.sh TMPDIR=$(mktemp -d $(basename $0).XXXXXX) @@ -16,6 +16,4 @@ cd ${TMPDIR} && $DUB fetch --cache=local bloom & pid2=$! wait $pid1 wait $pid2 -if [ ! -d ${TMPDIR}/bloom* ]; then - exit 1 -fi +[ -d ${TMPDIR}/bloom* ] diff --git a/test/issue686-multiple-march.sh b/test/issue686-multiple-march.sh index cdf2cde5d..24b84b74a 100755 --- a/test/issue686-multiple-march.sh +++ b/test/issue686-multiple-march.sh @@ -1,7 +1,5 @@ -#!/bin/sh - -set -e +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue686-multiple-march - -${DUB} build --bare --force --compiler=${DC} -a x86_64 -v main 2>&1 | grep -e "-m64 -m64" -c && exit 1 || exit 0 +${DUB} build --bare --force --compiler=${DC} -a x86_64 -v main 2>&1 | { ! grep -e '-m64 -m64' -c; } diff --git a/test/issue782-gtkd-pkg-config.sh b/test/issue782-gtkd-pkg-config.sh index 434ca02b5..a91d73899 100755 --- a/test/issue782-gtkd-pkg-config.sh +++ b/test/issue782-gtkd-pkg-config.sh @@ -1,5 +1,6 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh if [ "${DC}" != "dmd" ]; then echo "Skipping issue782-dtkd-pkg-config test for ${DC}..." else @@ -7,16 +8,18 @@ else # the ${CURR_DIR-$(pwd)} allows running issue782-gtkd-pkg-config.sh stand-alone from the test directory cd ${CURR_DIR-$(pwd)}/issue782-gtkd-pkg-config rm -rf fake-gtkd/.dub - rm fake-gtkd/libfake-gtkd.so + rm -f fake-gtkd/libfake-gtkd.so rm -rf main/.dub - rm main/fake-gtkd-test + rm -f main/fake-gtkd-test echo ${DUB} - cd fake-gtkd && ${DUB} build -v --compiler=${DC} || exit 1 + cd fake-gtkd && ${DUB} build --compiler=${DC} cd ../main # `run` needs to find the fake-gtkd shared library, so set LD_LIBRARY_PATH to where it is - # pkg-config needs to find our .pc file which is in $(pwd)/../fake-gtkd/pkgconfig, so set PKG_CONFIG_PATH accordingly - LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/../fake-gtkd PKG_CONFIG_PATH=$(pwd)/../fake-gtkd/pkgconfig ${DUB} -v run --force --compiler=${DC} || exit 1 + export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}${LD_LIBRARY_PATH:+:}$PWD/../fake-gtkd + # pkg-config needs to find our .pc file which is in $PWD/../fake-gtkd/pkgconfig, so set PKG_CONFIG_PATH accordingly + export PKG_CONFIG_PATH=$PWD/../fake-gtkd/pkgconfig + ${DUB} run --force --compiler=${DC} cd .. rm -rf fake-gtkd/.dub rm fake-gtkd/libfake-gtkd.so diff --git a/test/issue813-fixed-dependency.sh b/test/issue813-fixed-dependency.sh index 2785cdbe5..bddf07884 100755 --- a/test/issue813-fixed-dependency.sh +++ b/test/issue813-fixed-dependency.sh @@ -1,7 +1,8 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue813-fixed-dependency rm -rf main/.dub rm -rf sub/.dub rm -rf sub/sub/.dub -${DUB} build --bare --compiler=${DC} main || exit 1 +${DUB} build --bare --compiler=${DC} main diff --git a/test/issue813-pure-sub-dependency.sh b/test/issue813-pure-sub-dependency.sh index 85ab84e69..ec2291ebe 100755 --- a/test/issue813-pure-sub-dependency.sh +++ b/test/issue813-pure-sub-dependency.sh @@ -1,8 +1,9 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue813-pure-sub-dependency rm -rf main/.dub rm -rf sub/.dub rm -rf sub/sub/.dub rm -f main/dub.selections.json -${DUB} build --bare --compiler=${DC} main || exit 1 +${DUB} build --bare --compiler=${DC} main diff --git a/test/issue820-extra-fields-after-convert.sh b/test/issue820-extra-fields-after-convert.sh index ec9e9359d..5e81e35a1 100755 --- a/test/issue820-extra-fields-after-convert.sh +++ b/test/issue820-extra-fields-after-convert.sh @@ -1,17 +1,16 @@ -#!/bin/sh +#!/usr/bin/env bash -set -e +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/1-exec-simple cp dub.json dub.json.bak ${DUB} convert -f sdl -if grep -c -e "version\|sourcePaths\|importPaths\|configuration" dub.sdl > /dev/null; then - echo "Conversion added extra fields." +if grep -qe "version\|sourcePaths\|importPaths\|configuration" dub.sdl > /dev/null; then mv dub.json.bak dub.json rm dub.sdl - exit 1 + die $LINENO 'Conversion added extra fields.' fi mv dub.json.bak dub.json diff --git a/test/issue884-init-defer-file-creation.sh b/test/issue884-init-defer-file-creation.sh index 38c393e47..b71b26892 100755 --- a/test/issue884-init-defer-file-creation.sh +++ b/test/issue884-init-defer-file-creation.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +. $(dirname "${BASH_SOURCE[0]}")/common.sh TMPDIR=${CURR_DIR}tmppack echo $TMPDIR @@ -21,5 +21,5 @@ rm -r ${TMPDIR} # ignore sum + "." + ".." if [ ${NFILES_PLUS_ONE} -gt 3 ]; then - exit 1; + die $LINENO 'Aborted dub init left spurious files around.' fi diff --git a/test/issue895-local-configuration.sh b/test/issue895-local-configuration.sh index 8edc10f20..d00bb62fb 100755 --- a/test/issue895-local-configuration.sh +++ b/test/issue895-local-configuration.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -e +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR} mkdir ../etc @@ -7,19 +7,16 @@ mkdir ../etc/dub echo "{\"defaultCompiler\": \"foo\"}" > ../etc/dub/settings.json if [ -e /var/lib/dub/settings.json ]; then - echo "Found existing system wide DUB configuration. Aborting." - exit 1 + die $LINENO 'Found existing system wide DUB configuration. Aborting.' fi if [ -e ~/.dub/settings.json ]; then - echo "Found existing user wide DUB configuration. Aborting." - exit 1 + die $LINENO 'Found existing user wide DUB configuration. Aborting.' fi -if ! ${DUB} describe --single issue103-single-file-package.d 2>&1 | grep -e "Unknown compiler: foo" -c > /dev/null; then +if ! { ${DUB} describe --single issue103-single-file-package.d 2>&1 || true; } | grep -cF 'Unknown compiler: foo'; then rm -r ../etc - echo "DUB didn't find the local configuration" - exit 1 + die $LINENO 'DUB did not find the local configuration' fi rm -r ../etc diff --git a/test/issue923-subpackage-deps.sh b/test/issue923-subpackage-deps.sh index f35d58cfa..f3be79c4f 100755 --- a/test/issue923-subpackage-deps.sh +++ b/test/issue923-subpackage-deps.sh @@ -1,14 +1,14 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue923-subpackage-deps rm -rf main/.dub rm -rf a/.dub rm -rf b/.dub rm -f main/dub.selections.json -${DUB} build --bare --compiler=${DC} main || exit 1 +${DUB} build --bare --compiler=${DC} main if ! grep -c -e \"b\" main/dub.selections.json; then - echo "Dependency b not resolved." - exit 1 + die $LINENO 'Dependency b not resolved.' fi diff --git a/test/issue934-path-dep.sh b/test/issue934-path-dep.sh index 6aa477a49..387521bfa 100755 --- a/test/issue934-path-dep.sh +++ b/test/issue934-path-dep.sh @@ -1,9 +1,10 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue934-path-dep rm -rf main/.dub rm -rf a/.dub rm -rf b/.dub rm -f main/dub.selections.json cd main -${DUB} build --compiler=${DC} || exit 1 +${DUB} build --compiler=${DC} diff --git a/test/issue990-download-optional-selected.sh b/test/issue990-download-optional-selected.sh index 1d5355cc0..8b548a348 100755 --- a/test/issue990-download-optional-selected.sh +++ b/test/issue990-download-optional-selected.sh @@ -1,6 +1,7 @@ -#!/bin/sh +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh cd ${CURR_DIR}/issue990-download-optional-selected rm -rf b/.dub -${DUB} remove gitcompatibledubpackage -n --version=* -${DUB} run || exit 1 +${DUB} remove gitcompatibledubpackage -n --version=* 2>/dev/null || true +${DUB} run diff --git a/test/run-unittest.sh b/test/run-unittest.sh index deaf1664b..f04e48722 100755 --- a/test/run-unittest.sh +++ b/test/run-unittest.sh @@ -1,6 +1,6 @@ -#!/bin/bash +#!/usr/bin/env bash -set -v +. $(dirname "${BASH_SOURCE[0]}")/common.sh function log() { echo -e "\033[0;33m[INFO] "$@"\033[0m" @@ -19,11 +19,11 @@ function die() { export -f log export -f die -if [ -z ${DUB} ]; then +if [ -z ${DUB:-} ]; then die 'Error: Variable $DUB must be defined to run the tests.' fi -if [ -z ${DC} ]; then +if [ -z ${DC:-} ]; then log '$DC not defined, assuming dmd...' DC=dmd fi @@ -31,8 +31,8 @@ fi CURR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) for script in $(ls $CURR_DIR/*.sh); do - if [ "$script" = "$(readlink -f ${BASH_SOURCE[0]})" ]; then continue; fi - if [ -e $script.min_frontend ] && [ ! -z "$FRONTEND" -a "$FRONTEND" \< $(cat $script.min_frontend) ]; then continue; fi + if [ "$script" = "$(readlink -f ${BASH_SOURCE[0]})" ] || [ "$(basename $script)" = "common.sh" ]; then continue; fi + if [ -e $script.min_frontend ] && [ ! -z ${FRONTEND:-} -a ${FRONTEND:-} \< $(cat $script.min_frontend) ]; then continue; fi log "Running $script..." DUB=$DUB DC=$DC CURR_DIR="$CURR_DIR" $script || logError "Script failure." done @@ -63,4 +63,4 @@ for pack in $(ls -d $CURR_DIR/*/); do fi done -exit $any_errors +exit ${any_errors:-0} diff --git a/test/test-version-opt.sh b/test/test-version-opt.sh index 293186813..3abf31be6 100755 --- a/test/test-version-opt.sh +++ b/test/test-version-opt.sh @@ -1,3 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash +. $(dirname "${BASH_SOURCE[0]}")/common.sh $DUB --version | grep -qF 'DUB version'