Skip to content

Move common BASH test logic to wrapper#7928

Merged
wilzbach merged 1 commit intodlang:masterfrom
marler8997:betterBashTests
Feb 27, 2018
Merged

Move common BASH test logic to wrapper#7928
wilzbach merged 1 commit intodlang:masterfrom
marler8997:betterBashTests

Conversation

@marler8997
Copy link
Copy Markdown
Contributor

@marler8997 marler8997 commented Feb 20, 2018

This PR creates a wrapper to hold common logic/settings for all BASH tests. Currently, this wrapper will pipe stdout/stderr to the test output file, and when a failure occurs, will dump the output file with a message saying the test failed (just like d_do_test does with .d tests).

It also exports common variables to the test script, currently

  • ${TEST_DIR} (i.e. compilable/runnable)
  • ${TEST_NAME} being the base name of the test.

TODO:

Maybe set -euo pipefail and/or set -x in wrapper?

@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @marler8997! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

# duplicate d_do_test output
echo >> ${output_file}
echo ============================== >> ${output_file}
echo Test failed >> ${output_file}
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.

It's good to state here which test failed as the tests might run in high parallelism.

@marler8997 marler8997 force-pushed the betterBashTests branch 3 times, most recently from ce1fae7 to d7e3b3e Compare February 21, 2018 01:54
@marler8997 marler8997 force-pushed the betterBashTests branch 3 times, most recently from 503596f to e7e8b69 Compare February 21, 2018 17:05
Copy link
Copy Markdown
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

I'm strongly voting for this. Redefining the same variables in the bash scripts has become quite a pain.
Thanks a lot @marler8997 for pushing this!

I even have a few idea to make this more useful (a few more default exported variables, a default debug trap, default set -eu o pipefail, ...), but I'm more than happy to do this in a quick follow-up.

CC @MartinNowak @CyberShadow

# 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}

name=`basename $0 .sh`
dir=${RESULTS_DIR}/compilable
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.

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


# 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.

@@ -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)

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.

@wilzbach
Copy link
Copy Markdown
Contributor

Maybe set -euo pipefail and/or set -x in wrapper?

Yes, we should do this, but I think your PR is already a good start and makes a good base for future improvements like this one (or the other potential ones I have mentioned).

@marler8997
Copy link
Copy Markdown
Contributor Author

Ok yeah, we can merge as is and I'll let you enhance it (you're better at BASH anyway)

@wilzbach wilzbach added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Feb 23, 2018
@wilzbach
Copy link
Copy Markdown
Contributor

No one has objected to this change within one week, it's not critical DMD code, but just affects the test suite and we need to move on -> merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:72h no objection -> merge The PR will be merged if there are no objections raised.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants