Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow single test to be specified as an argument to run-nio-alloc-counter-tests.sh. #1214

Merged
merged 3 commits into from Nov 7, 2019
Merged

Allow single test to be specified as an argument to run-nio-alloc-counter-tests.sh. #1214

merged 3 commits into from Nov 7, 2019

Conversation

marlimox
Copy link
Contributor

@marlimox marlimox commented Nov 1, 2019

Motivation:

run-nio-alloc-counter-tests.sh currently runs all tests. When writing or
debugging a test, you commonly want to run a single test. At the moment the
common practice is to edit the script to hardcode a test to run, which is
annoying and error-prone.

Modifications:

Add an optional argument to the script to specify the test to run.

Result:

$ ./run-nio-alloc-counter-tests.sh

runs all tests.

$ ./run-nio-alloc-counter-tests.sh test_decode_1000_ws_frames.swift

runs only test_decode_1000_ws_frames.swift.

@Lukasa Lukasa requested a review from weissi November 1, 2019 08:22
@Lukasa Lukasa added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Nov 1, 2019
@Lukasa Lukasa added this to the 2.10.0 milestone Nov 1, 2019
Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Thanks, that's a great addition. Some bash nitpicking :)

@@ -18,25 +18,24 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

tmp_dir="/tmp"

function die() {
Copy link
Member

Choose a reason for hiding this comment

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

could we leave this in so we get better error messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah for sure. The reason I removed it is that it didn't seem like it was actually providing better error messages. For example, if you specify an unknown flag, you get the following output:

$ ./run-nio-alloc-counter-tests.sh -d
./run-nio-alloc-counter-tests.sh: illegal option -- d
ERROR: unknown option ?

The ? in this case is $opt, which is always "?" because it doesn't know what the option is. All of the useful information is contained in the first line, which is the error message from getopts.

Removing the only call to die (and then the die function itself because it's no longer used) gives the following output, which seemed a bit cleaner and less confusing:

$ ./run-nio-alloc-counter-tests.sh -d
./run-nio-alloc-counter-tests.sh: illegal option -- d

Happy to revert back to the previous code if you prefer though!

Copy link
Member

Choose a reason for hiding this comment

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

oh I see, getopts actually prints an error itself. I'm happy with that then.

while getopts "t:" opt; do
case "$opt" in
t)
tmp_dir="$OPTARG"
;;
\?)
Copy link
Member

Choose a reason for hiding this comment

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

why this change?

Copy link
Contributor Author

@marlimox marlimox Nov 6, 2019

Choose a reason for hiding this comment

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

My thinking was most of the examples of getopts I've seen use * to handle the unknown case, as it's idiomatic with the default branch in a case block in general.

With \?, you have to remember that getopts will set the flag variable to ? if it doesn't recognise a flag, so it's the unknown case you're handling with this branch. You also have to remember that you don't need a separate default branch for the case, because the variable will always be ? if a flag is unknown.

Compared to a list of flags and then a default * case, that seemed less clear and harder to remember at first glance.

I don't feel strongly about it though, happy to revert.

;;
esac
done

shift $((OPTIND-1))

test_pattern="${1:-test_*.swift}"
Copy link
Member

@weissi weissi Nov 4, 2019

Choose a reason for hiding this comment

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

I think a better way to do this (which also doesn't break on newlines) is to start with

tests_to_run=( "$here"/test_*.swift )

and if we only run one test, then we can override this with all the arguments that we were given:

if [[ $OPTIND != $# ]]; then # put the right maths to figure out 'no arguments'
    tests_to_run=$@ # override the tests to just contain the ones specified on the command line
fi

then, below we can use ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah great suggestion. I only handled specifying a single test argument, as that was the use case I kept running into. But there's no reason not to allow multiple tests to be specified, and this is a good implementation for that.

I'll update!

Copy link
Contributor Author

@marlimox marlimox Nov 6, 2019

Choose a reason for hiding this comment

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

Ah I think I might have misunderstood the intention here. Your suggestion will still only run one test right? It will just treat all of the remaining arguments as a single test argument?

If I change "${tests_to_run[@]}" to ${tests_to_run[@]} below, then it will allow running multiple tests. Was that what you were picturing? (This won't handle whitespace in filenames however.)

"$here/../../allocation-counter-tests-framework/run-allocation-counter.sh" \
-p "$here/../../.." \
-m NIO -m NIOHTTP1 -m NIOWebSocket \
-s "$here/shared.swift" \
-t "$tmp_dir" \
"$here"/test_*.swift
"$here"/$test_pattern
Copy link
Member

Choose a reason for hiding this comment

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

"${tests_to_run[@]}"

Marli Oshlack and others added 3 commits November 6, 2019 15:51
…nter-tests.sh.

Motivation:

run-nio-alloc-counter-tests.sh currently runs all tests. When writing or
debugging a test, you commonly want to run a single test. At the moment the
common practice is to edit the script to hardcode a test to run, which is
annoying and error-prone.

Modifications:

Add an optional argument to the script to specify the test to run.

Result:

$ ./run-nio-alloc-counter-tests.sh

runs all tests.

$ ./run-nio-alloc-counter-tests.sh test_decode_1000_ws_frames.swift

runs only test_decode_1000_ws_frames.swift.
@weissi
Copy link
Member

weissi commented Nov 6, 2019

@swift-nio-bot test this please

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

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

thank you very much! LGTM

@weissi weissi merged commit bc661cb into apple:master Nov 7, 2019
@weissi weissi modified the milestones: 2.10.0, 2.11.0 Nov 7, 2019
@marlimox marlimox deleted the script_param branch November 7, 2019 14:57
@weissi weissi modified the milestones: 2.11.0, 2.10.1 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants