Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,13 @@ $(RESULTS_DIR)/runnable/%.d.out: runnable/%.d $(RESULTS_DIR)/.created test_tools
$(QUIET) $(RESULTS_DIR)/d_do_test $(<D) $* d

$(RESULTS_DIR)/runnable/%.sh.out: runnable/%.sh $(RESULTS_DIR)/.created test_tools $(DMD)
$(QUIET) echo " ... $(<D)/$*.sh"
$(QUIET) ./$(<D)/$*.sh
$(QUIET) ./sh_do_test.sh $(<D) $*

$(RESULTS_DIR)/compilable/%.d.out: compilable/%.d $(RESULTS_DIR)/.created test_tools $(DMD)
$(QUIET) $(RESULTS_DIR)/d_do_test $(<D) $* d

$(RESULTS_DIR)/compilable/%.sh.out: compilable/%.sh $(RESULTS_DIR)/.created test_tools $(DMD)
$(QUIET) echo " ... $(<D)/$*.sh"
$(QUIET) ./$(<D)/$*.sh
$(QUIET) ./sh_do_test.sh $(<D) $*

$(RESULTS_DIR)/fail_compilation/%.d.out: fail_compilation/%.d $(RESULTS_DIR)/.created test_tools $(DMD)
$(QUIET) $(RESULTS_DIR)/d_do_test $(<D) $* d
Expand Down
9 changes: 4 additions & 5 deletions test/compilable/crlf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

# Test CRLF and mixed line ending handling in D lexer.

name=`basename $0 .sh`
dir=${RESULTS_DIR}/compilable
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is no longer used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, replaced with ${TEST_NAME}

fn=${dir}/${name}.d
fn=${TEST_DIR}/${TEST_NAME}.d
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a next step TEST_FILE could be exported as well.


printf '%s\r\n' \
'#!/usr/bin/env dmd -run' \
Expand Down Expand Up @@ -46,8 +45,8 @@ printf 'static assert(wstr == "%s");\n' 'foo\nbar\nbaz\n' >> ${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
6 changes: 2 additions & 4 deletions test/compilable/ddoc9764.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be quite frequent enough.

export OUTPUT_FILE="${RESULTS_DIR}/${TEST_DIR}/${TEST_NAME}"

could be part of a next step.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is common enough, I'll add it to this PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, wait, this is specific to this test only...it has the .html extension

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's why export OUTPUT_FILE="${RESULTS_DIR}/${TEST_DIR}/${TEST_NAME}" which allows the user to pick the extension, but yeah, let's think about this in the next step.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't sure the best variables to expose...there's combinations of the source dir vs results dir and different extensions...we can figure it out in the next step like you said


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
9 changes: 4 additions & 5 deletions test/compilable/issue17167.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
1 change: 0 additions & 1 deletion test/compilable/jsonNoOutFile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 4 additions & 5 deletions test/compilable/test14894.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions test/compilable/test18367.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions test/compilable/test6461.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
5 changes: 2 additions & 3 deletions test/compilable/test9680.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env bash

name=`basename $0 .sh`
dir=${RESULTS_DIR}/compilable

if [ "${OS}" == "win32" -o "${OS}" == "Windows_NT" ]; then
Expand All @@ -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
Expand All @@ -28,4 +27,4 @@ do
rm ${output_file}{,.2}
done

echo Success >${dir}/`basename $0`.out
echo Success
3 changes: 1 addition & 2 deletions test/compilable/testclidflags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
set -euo pipefail

dir=${RESULTS_DIR}${SEP}compilable
output_file=${dir}/testclidflags.sh.out

unset DFLAGS

Expand All @@ -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
5 changes: 3 additions & 2 deletions test/d_do_test.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/sh_do_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set -u -o pipefail (doesn't have to be done in this PR)

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few more variables which I frequently need, but I think we can easily go step by step here.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A future extension could use source here.
Advantages:

  • use a trap, to show the error of the failure
  • activate set -ue -o pipefail by default
  • activate set +x by default, redirect the debug log into a XYZ.debug file and only show it when there's a failure.

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