From a0d1f08f3857e4d1732db8923b176c1f5bb45bc5 Mon Sep 17 00:00:00 2001 From: Jonathan Marler Date: Thu, 22 Feb 2018 03:22:58 -0700 Subject: [PATCH] Created sh_do_test to wrap BASH tests with common logic/settings --- test/Makefile | 6 ++---- test/compilable/crlf.sh | 9 ++++----- test/compilable/ddoc9764.sh | 6 ++---- test/compilable/issue17167.sh | 9 ++++----- test/compilable/jsonNoOutFile.sh | 1 - test/compilable/test14894.sh | 9 ++++----- test/compilable/test18367.sh | 3 --- test/compilable/test6461.sh | 6 ++---- test/compilable/test9680.sh | 5 ++--- test/compilable/testclidflags.sh | 3 +-- test/d_do_test.d | 5 +++-- test/sh_do_test.sh | 29 +++++++++++++++++++++++++++++ 12 files changed, 53 insertions(+), 38 deletions(-) create mode 100755 test/sh_do_test.sh diff --git a/test/Makefile b/test/Makefile index 656dab3eb794..af8679c1f419 100644 --- a/test/Makefile +++ b/test/Makefile @@ -216,15 +216,13 @@ $(RESULTS_DIR)/runnable/%.d.out: runnable/%.d $(RESULTS_DIR)/.created test_tools $(QUIET) $(RESULTS_DIR)/d_do_test $(> ${fn} printf 'enum dstr = q"(\r\nfoo\r\nbar\nbaz\r\n)";\n' >> ${fn} printf 'static assert(dstr == "%s");\n' '\nfoo\nbar\nbaz\n' >> ${fn} -$DMD -c -D -Dd${dir} -m${MODEL} -of${dir}/${name}a${OBJ} ${fn} || exit 1 +$DMD -c -D -Dd${TEST_DIR} -m${MODEL} -of${TEST_DIR}/${TEST_NAME}a${OBJ} ${fn} || exit 1 -rm -f ${dir}/${name}a${OBJ} ${dir}/${name}.html ${fn} +rm -f ${TEST_DIR}/${TEST_NAME}a${OBJ} ${TEST_DIR}/${TEST_NAME}.html ${fn} -echo Success >${dir}/`basename $0`.out +echo Success diff --git a/test/compilable/ddoc9764.sh b/test/compilable/ddoc9764.sh index 6839346522fe..f8875e73f4dc 100755 --- a/test/compilable/ddoc9764.sh +++ b/test/compilable/ddoc9764.sh @@ -1,11 +1,9 @@ #!/usr/bin/env bash -name=`basename $0 .sh` -dir=${RESULTS_DIR}/compilable -output_file=${dir}/${name}.html +output_file=${RESULTS_DIR}/${TEST_DIR}/${TEST_NAME}.html rm -f ${output_file} $DMD -m${MODEL} -D -o- compilable/extra-files/ddoc9764.dd -Df${output_file} -compilable/extra-files/ddocAny-postscript.sh 9764 && touch ${dir}/`basename $0`.out +compilable/extra-files/ddocAny-postscript.sh 9764 && touch ${TEST_DIR}/${TEST_NAME}.out diff --git a/test/compilable/issue17167.sh b/test/compilable/issue17167.sh index 86549202cc19..0c058dfa4a93 100755 --- a/test/compilable/issue17167.sh +++ b/test/compilable/issue17167.sh @@ -5,12 +5,11 @@ set -euo pipefail # Test that file paths larger than 248 characters can be used # Test CRLF and mixed line ending handling in D lexer. -name=$(basename "$0" .sh) dir=${RESULTS_DIR}/compilable/ -test_dir=${dir}/${name}/uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu +test_dir=${dir}/${TEST_NAME}/uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu [[ -d $test_dir ]] || mkdir -p "$test_dir" -bin_base=${test_dir}/${name} +bin_base=${test_dir}/${TEST_NAME} bin="$bin_base$OBJ" src="$bin_base.d" @@ -19,6 +18,6 @@ echo 'void main() {}' > "${src}" # Only compile, not link, since optlink can't handle long file names $DMD -m"${MODEL}" "${DFLAGS}" -c -of"${bin}" "${src}" || exit 1 -rm -rf "${dir:?}"/"$name" +rm -rf "${dir:?}"/"$TEST_NAME" -echo Success >"${dir}"/"$(basename $0)".out +echo Success diff --git a/test/compilable/jsonNoOutFile.sh b/test/compilable/jsonNoOutFile.sh index 4cf2a435d4c2..c3284f7496f7 100755 --- a/test/compilable/jsonNoOutFile.sh +++ b/test/compilable/jsonNoOutFile.sh @@ -4,4 +4,3 @@ dir=${RESULTS_DIR}/compilable output_file=${dir}/jsonNoOutFile.sh.out $DMD -c -od=${dir} -Xi=compilerInfo compilable/extra-files/emptymain.d > ${output_file} rm -f emptymain.json || true - diff --git a/test/compilable/test14894.sh b/test/compilable/test14894.sh index e2daec095a41..dd54fd062be3 100755 --- a/test/compilable/test14894.sh +++ b/test/compilable/test14894.sh @@ -1,13 +1,12 @@ #!/usr/bin/env bash -name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable src=compilable/extra-files -$DMD -c -m${MODEL} -of${dir}/${name}a${OBJ} -I${src} ${src}/${name}a.d || exit 1 +$DMD -c -m${MODEL} -of${dir}/${TEST_NAME}a${OBJ} -I${src} ${src}/${TEST_NAME}a.d || exit 1 -$DMD -unittest -m${MODEL} -od${dir} -I${src} ${src}/${name}main.d ${dir}/${name}a${OBJ} || exit 1 +$DMD -unittest -m${MODEL} -od${dir} -I${src} ${src}/${TEST_NAME}main.d ${dir}/${TEST_NAME}a${OBJ} || exit 1 -rm -f ${dir}/{${name}a${OBJ} ${name}main${EXE} ${name}main${OBJ}} +rm -f ${dir}/{${TEST_NAME}a${OBJ} ${TEST_NAME}main${EXE} ${TEST_NAME}main${OBJ}} -echo Success >${dir}/`basename $0`.out +echo Success diff --git a/test/compilable/test18367.sh b/test/compilable/test18367.sh index fb3adf7c5e61..e3d5f35742ae 100755 --- a/test/compilable/test18367.sh +++ b/test/compilable/test18367.sh @@ -2,9 +2,6 @@ set -u -o pipefail -name=$(basename "$0" .sh) -dir=${RESULTS_DIR}/compilable/ - # dmd should not segfault on -X with libraries, but no source files out=$("$DMD" -conf= -X foo.a 2>&1) [ $? -eq 1 ] || exit 1 diff --git a/test/compilable/test6461.sh b/test/compilable/test6461.sh index e2ad1d31d415..d81a61a14493 100755 --- a/test/compilable/test6461.sh +++ b/test/compilable/test6461.sh @@ -1,8 +1,7 @@ #!/usr/bin/env bash -name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable -src=compilable/extra-files/${name} +src=compilable/extra-files/${TEST_NAME} if [ "${OS}" == "win32" -o "${OS}" == "win64" ]; then LIBEXT=.lib @@ -17,5 +16,4 @@ $DMD -m${MODEL} -od${dir} -I${src} ${src}/main.d ${dir}/a${LIBEXT} ${dir}/b${LIB rm -f ${dir}/{a${LIBEXT} b${LIBEXT} main${EXE} main${OBJ}} -echo Success >${dir}/`basename $0`.out - +echo Success diff --git a/test/compilable/test9680.sh b/test/compilable/test9680.sh index a03dd1b7eb66..a0e382645073 100755 --- a/test/compilable/test9680.sh +++ b/test/compilable/test9680.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -name=`basename $0 .sh` dir=${RESULTS_DIR}/compilable if [ "${OS}" == "win32" -o "${OS}" == "Windows_NT" ]; then @@ -11,7 +10,7 @@ fi for kind in "${kinds[@]}" do - file_name=${name}${kind} + file_name=${TEST_NAME}${kind} src_file=compilable/extra-files/${file_name}.d expect_file=compilable/extra-files/${file_name}.out output_file=${dir}/${file_name}.out @@ -28,4 +27,4 @@ do rm ${output_file}{,.2} done -echo Success >${dir}/`basename $0`.out +echo Success diff --git a/test/compilable/testclidflags.sh b/test/compilable/testclidflags.sh index 13bd7b763a6a..4fc880e74ae8 100755 --- a/test/compilable/testclidflags.sh +++ b/test/compilable/testclidflags.sh @@ -3,7 +3,6 @@ set -euo pipefail dir=${RESULTS_DIR}${SEP}compilable -output_file=${dir}/testclidflags.sh.out unset DFLAGS @@ -14,4 +13,4 @@ unset DFLAGS ( DFLAGS="-O -D" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O -D" ( DFLAGS="-O '-Ifoo bar' -c" "$DMD" -v foo.d 2> /dev/null || true) | grep -q "DFLAGS -O '-Ifoo bar' -c" -echo Success >${output_file} +echo Success diff --git a/test/d_do_test.d b/test/d_do_test.d index c7a5d2cf1153..896ec578982c 100755 --- a/test/d_do_test.d +++ b/test/d_do_test.d @@ -792,10 +792,11 @@ int tryMain(string[] args) f.writeln(); f.writeln("=============================="); - f.writeln("Test failed: ", e.msg); + f.writef("Test %s/%s.%s failed: ", input_dir, test_name, test_extension); + f.writeln(e.msg); f.close(); - writeln("Test failed. The logged output:"); + writefln("Test %s/%s.%s failed. The logged output:", input_dir, test_name, test_extension); writeln(cast(string)std.file.read(output_file)); std.file.remove(output_file); return Result.return1; diff --git a/test/sh_do_test.sh b/test/sh_do_test.sh new file mode 100755 index 000000000000..e4a2693d8f29 --- /dev/null +++ b/test/sh_do_test.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +if [ "${RESULTS_DIR}" == "" ]; then + echo Note: this program is normally called through the Makefile, it + echo is not meant to be called directly by the user. + exit 1 +fi + +# TEST_DIR should be one of compilable, fail_compilation or runnable +export TEST_DIR=$1 +export TEST_NAME=$2 +script_name=${TEST_DIR}/${TEST_NAME}.sh + +echo " ... ${script_name}" + +output_file=${RESULTS_DIR}/${script_name}.out +rm -f ${output_file} + +./${script_name} > ${output_file} 2>&1 +if [ $? -ne 0 ]; then + # duplicate d_do_test output + echo >> ${output_file} + echo ============================== >> ${output_file} + echo Test ${script_name} failed >> ${output_file} + + echo Test ${script_name} failed. The logged output: + cat ${output_file} + exit 1 +fi