Skip to content

Commit

Permalink
Merge pull request #1185 from MartinNowak/improve_test_output
Browse files Browse the repository at this point in the history
improve test output
  • Loading branch information
MartinNowak authored Jul 4, 2017
2 parents 2e83112 + 6e9de34 commit f3255f7
Show file tree
Hide file tree
Showing 45 changed files with 191 additions and 187 deletions.
11 changes: 7 additions & 4 deletions test/0-init-fail-json.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#!/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
}

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
10 changes: 6 additions & 4 deletions test/0-init-fail.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/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
}

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
12 changes: 5 additions & 7 deletions test/0-init-interactive.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
12 changes: 5 additions & 7 deletions test/0-init-multi-json.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
13 changes: 5 additions & 8 deletions test/0-init-multi.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
8 changes: 4 additions & 4 deletions test/0-init-simple-json.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
7 changes: 3 additions & 4 deletions test/0-init-simple.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions test/4-describe-data-1-list.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

4 changes: 2 additions & 2 deletions test/4-describe-data-2-dmd.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions test/4-describe-data-3-zero-delim.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/4-describe-import-paths.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/4-describe-json.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/4-describe-string-import-paths.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 5 additions & 8 deletions test/5-convert-stdout.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
#!/usr/bin/env bash

set -e
. $(dirname "${BASH_SOURCE[0]}")/common.sh

cd ${CURR_DIR}/1-exec-simple

Expand All @@ -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
22 changes: 7 additions & 15 deletions test/5-convert.sh
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

13 changes: 13 additions & 0 deletions test/common.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/ddox.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 11 additions & 4 deletions test/feat663-search.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit f3255f7

Please sign in to comment.