diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index 134b587..799755b 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -45,32 +45,42 @@ return path; } -// lockfile based on atomic mkdir -struct LockFile -{ - bool opCast(T:bool)() { return !!path; } - ~this() { if (path) rmdir(path); } - string path; -} +/** + Obtain a lock for a file at the given path. If the file cannot be locked + within the given duration, an exception is thrown. The file will be created + if it does not yet exist. Deleting the file is not safe as another process + could create a new file with the same name. + The returned lock will get unlocked upon destruction. -auto tryLockFile(string path) + Params: + path = path to file that gets locked + timeout = duration after which locking failed + Returns: + The locked file or an Exception on timeout. +*/ +auto lockFile(string path, Duration timeout) { - import std.file; - if (collectException(mkdir(path))) - return LockFile(null); - return LockFile(path); -} + import std.datetime, std.stdio : File; + import std.algorithm : move; -auto lockFile(string path, Duration wait) -{ - import std.datetime, std.file; + // Just a wrapper to hide (and destruct) the locked File. + static struct LockFile + { + // The Lock can't be unlinked as someone could try to lock an already + // opened fd while a new file with the same name gets created. + // Exclusive filesystem locks (O_EXCL, mkdir) could be deleted but + // aren't automatically freed when a process terminates, see #1149. + private File f; + } + + auto file = File(path, "w"); auto t0 = Clock.currTime(); auto dur = 1.msecs; while (true) { - if (!collectException(mkdir(path))) - return LockFile(path); - enforce(Clock.currTime() - t0 < wait, "Failed to lock '"~path~"'."); + if (file.tryLock()) + return LockFile(move(file)); + enforce(Clock.currTime() - t0 < timeout, "Failed to lock '"~path~"'."); if (dur < 1024.msecs) // exponentially increase sleep time dur *= 2; Thread.sleep(dur); diff --git a/test/0-init-fail-json.sh b/test/0-init-fail-json.sh index 63ebb5a..069014e 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 @@ 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 db594b2..c440a57 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 @@ 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 65065f3..945838b 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 @@ } 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 c9fd92d..239c419 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 @@ 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 a03694e..8432b96 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 @@ 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 a18bd3d..2a7ec8a 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 @@ 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 6b25f5a..f4fee2e 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 @@ } 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 aefbf78..3cfe5dc 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 @@ --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 "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 3f30769..d323bc5 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 2d6738b..aee4d08 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 ba03205..375bc40 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 5641595..21f5105 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 aa64979..c1106a6 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 86cba02..ae7b491 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 @@ 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 fac1360..5cdbaa9 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 @@ 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 0000000..b43c656 --- /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 "[ERROR] $SOURCE_FILE:$1 $msg" + exit $rc +} +trap 'die $LINENO' ERR diff --git a/test/ddox.sh b/test/ddox.sh index c68e023..44f836e 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 1f6f3a4..4778a51 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 5c23bef..f689fdd 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; then - echo "Non-interactive remove should fail" 1>&2 - exit 1 +if $DUB remove dub --non-interactive 2>/dev/null; then + 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 7bcd443..96080f1 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 3665a5e..1233e76 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 a159216..dc7c009 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 2b26447..0c23eb2 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,8 +14,7 @@ ${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 if ${DUB} "issue103-single-file-package-error.d" 2> /dev/null; then diff --git a/test/issue1091-bogus-rebuild.sh b/test/issue1091-bogus-rebuild.sh index 689f572..ae440eb 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 fb88526..c6b27f2 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 69b7f0f..db87794 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 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 a1af6bd..19258ce 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 fe0ad5f..306bca7 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 d7e90b7..b8fc5e7 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 8f85c09..698ef63 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 8c16aa6..15e07d2 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 44b07d4..712a9f6 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 d1cfadd..d49bdd3 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 @@ 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 cdf2cde..24b84b7 100755 --- a/test/issue686-multiple-march.sh +++ b/test/issue686-multiple-march.sh @@ -1,7 +1,5 @@ -#!/bin/sh +#!/usr/bin/env bash -set -e - +. $(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 434ca02..a91d738 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 @@ # 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 2785cdb..bddf078 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 85ab84e..ec2291e 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 ec9e935..5e81e35 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 38c393e..b71b268 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 @@ # 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 8edc10f..d00bb62 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 @@ 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 f35d58c..f3be79c 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 6aa477a..387521b 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 1d5355c..8b548a3 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 1bb40f7..312c9ea 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 @@ export -f log export -f die -if [ -z ${DUB} ]; then +if [ -z ${DUB:-} ]; then die '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 @@ -32,8 +32,8 @@ 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 @@ -68,4 +68,4 @@ fi done -exit $any_errors +exit ${any_errors:-0} diff --git a/test/test-version-opt.sh b/test/test-version-opt.sh index 2931868..3abf31b 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'