sh_do_test: verbose trace + start to remove inferred output_file#8025
sh_do_test: verbose trace + start to remove inferred output_file#8025dlang-bot merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
| $DMD -c -od=${dir} -Xi=compilerInfo compilable/extra-files/emptymain.d > ${output_file} | ||
| rm -f emptymain.json || true | ||
| $DMD -c -od=${dir} -Xi=compilerInfo compilable/extra-files/emptymain.d | ||
| rm -f emptymain.json |
There was a problem hiding this comment.
Not sure why || true was added here. rm -f always exits with 0 and also this tests doesn't check the generated output.
There was a problem hiding this comment.
Cause I didn't know rm -f always returned 0 :)
There was a problem hiding this comment.
I remember I was having troubles trying to check the generated output, I can't remember why though...
|
|
||
| # dmd should not segfault on -X with libraries, but no source files | ||
| out=$("$DMD" -conf= -X foo.a 2>&1) | ||
| [ $? -eq 1 ] || exit 1 |
There was a problem hiding this comment.
That's exactly what -e is for. set -euo pipefail should probably be set by default, but that's a task for another PR.
|
|
||
| rm -rf "${dir:?}"/"$TEST_NAME" | ||
|
|
||
| echo Success |
There was a problem hiding this comment.
We no longer need to write sth. to the output file to create it as it's now created by default and only removed in the error case. Of course, that behavior could be easily changed in the sh_do_test script, but the point is that this is superfluous, was often forgotten in the past and should be handled by the wrapper.
| cat "${output_file}" 1>&2 | ||
| fi | ||
| rm -f "${output_file}" | ||
| } |
There was a problem hiding this comment.
No need for custom rolled error handling anymore. This is the default behavior.
There was a problem hiding this comment.
Depending on how the makefile is written, .DELETE_ON_ERROR might be required.
There was a problem hiding this comment.
Oh this is now mostly handled by the sh_do_test wrapper.
Also removing the output file if an error happened isn't the default behavior because if
- no input changed, then the output will still be the same
- it always the developer to inspect the output file manually
| cat ${output_file} | ||
| rm -f ${output_file} | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
No need for custom error handling anymore.
1ed652e to
786e3de
Compare
marler8997
left a comment
There was a problem hiding this comment.
Definitely an improvement :)
786e3de to
3e02d2b
Compare
ecbd7fc to
d9a7f8e
Compare
|
Pinging @CyberShadow as you seem to be the only one being able to approve this. |
What do you mean? Any committer can approve it. |
Yes, but there aren't so many who feel comfortable with Bash - you and Martin are the only one who I know and Martin is traditionally very busy. |
CyberShadow
left a comment
There was a problem hiding this comment.
Thanks! Looks good overall.
| name=`basename $0 .sh` | ||
| dir=${RESULTS_DIR}/runnable | ||
| dmddir=${RESULTS_DIR}${SEP}runnable | ||
| output_file=${dir}/${name}.sh.out |
There was a problem hiding this comment.
Looks like this script wanted to print its output only on failure? Is its output overly verbose, or something?
There was a problem hiding this comment.
All output is already printed on a failure, so this is just redundant.
|
|
||
| # Test CRLF and mixed line ending handling in D lexer. | ||
|
|
||
| set -e |
There was a problem hiding this comment.
👍
I'd go for the whole -euo pipefail trio. Variables that might be unset should be "declared" at the top of the file, i.e. replace unset variables with empty ones.
There was a problem hiding this comment.
Yes, my plane is to enable the entire -euo pipefail trio by default for all bash scripts in sh_do_test.sh.
This is just an intermediate PR that should lay the ground work for this.
I just added -e here as it's an almost hard-coded reaction whenever I see || exit 1
test/runnable/gdb15729.sh
Outdated
| dir=${RESULTS_DIR}${SEP}runnable | ||
| output_file=${dir}/gdb15729.sh.out | ||
|
|
||
| set -e |
There was a problem hiding this comment.
Flags should probably come right after the shebang, since -u could be added later, and those variable definitions would benefit from -u's checks.
There was a problem hiding this comment.
Done.
FYI: My plan is to add set -eu and maybe even set -o pipefail by default for ALL bash scripts as that would be a sane default.
| cat "${output_file}" 1>&2 | ||
| fi | ||
| rm -f "${output_file}" | ||
| } |
There was a problem hiding this comment.
Depending on how the makefile is written, .DELETE_ON_ERROR might be required.
test/sh_do_test.sh
Outdated
|
|
||
| # redirect stdout + stderr to the output file + keep a reference to the std{out,err} streams for later | ||
| exec 40>&1 | ||
| exec 41>&2 |
There was a problem hiding this comment.
bash has a syntax to assign a free file descriptor and store it in a variable (exec {name_of_fd_var}>&1), which should guarantee that there will not be collisions, but the feature is "relatively" new and not sure if it's available on all test systems.
There was a problem hiding this comment.
Nice! According to this SO answer it's available since available since bash 4.1+ (2009-12-31), so I just gave it a try.
Who knows, maybe it works on all systems
test/sh_do_test.sh
Outdated
| if [ $1 -ne 0 ]; then | ||
| echo ============================== | ||
| echo Test ${script_name} failed. The logged output: | ||
| cat ${output_file} |
There was a problem hiding this comment.
General note, would be nice to see a lot more quoting. This line (and many many others) will fail if the variable contains spaces or some other special characters. ShellCheck helps greatly in identifying such moments.
There was a problem hiding this comment.
FYI, I think if tests contained spaces, there's alot of places that would fail. But I suppose that's not a good reason to perpetuate bad practice.
test/sh_do_test.sh
Outdated
| exec 2>&41 | ||
|
|
||
| if [ $1 -ne 0 ]; then | ||
| echo ============================== |
There was a problem hiding this comment.
General note, printf > echo in scripts.
d9a7f8e to
235b297
Compare
dc811a5 to
1de3cd5
Compare
1de3cd5 to
6052624
Compare
Now that a dedicated Bash wrapper exists, a lot of boilerplate code can be removed from the bash scripts.
This is a start which saves an verbose trace of the bash log in
.logand all stdout and stddev inoutput_file. A trap will print both output when an error occurs.There's a lot more that can be done, see #7928 for ideas.
CC @marler8997 @CyberShadow