Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mbland
Copy link
Contributor

@mbland mbland commented Jul 18, 2018

Closes #106. This enables the user to execute a subset of tests that match a regular expression.

Also does a couple other things (might be easier to review commit-by-commit):

  • Updates argument parsing to maintain performance and semantics, but to allow the --filter option to take an argument (the previous algorithm wouldn't).
  • Fixes a small bug where IFS= was missing from help().
  • Rename encode_name to bats_encode_test_name to avoid collisions.

Bland, Mike added 3 commits July 15, 2018 23:06
Touch-ups to use more convenient Bash syntax.
This is in preparation for adding the --filter option, which will
require consuming the argument that follows it.
Closes #106. This enables the user to execute a subset of tests that
match a regular expression.
@mbland mbland requested a review from a team July 18, 2018 21:07
@ghost ghost assigned mbland Jul 18, 2018
@ghost ghost added the review label Jul 18, 2018
@mbland mbland mentioned this pull request Jul 18, 2018
Copy link
Member

@sublimino sublimino left a comment

Choose a reason for hiding this comment

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

Working for me in testing, a question of case sensitivity (and an orthogonal one on usage/help that can be deferred)

version
printf 'Usage: bats [-c] [-r] [-p | -t] <test> [<test> ...]\n'
printf '%s\n' \
'Usage: bats [-h] [-c] [-f <regex>] [-r] [-p | -t] <test> [<test> ...]'
Copy link
Member

Choose a reason for hiding this comment

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

While we're here I've been wondering if we should unify the two help outputs - I rarely want to see the short options without long info. What do you think about moving the version and the Usage: headers to help() and always showing that? /cc @jasonkarns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've kept version separate, but consolidated usage() and help() into usage(). How's that?

esac
done
fi
while [[ "$#" -ne 0 ]]; do
Copy link
Member

Choose a reason for hiding this comment

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

This block looks much cleaner 👍

printf '%s() { bats_test_begin "%s" %d; %s\n' "$encoded_name" "$name" \
"$index" "$body"

if [[ -z "$BATS_TEST_FILTER" || "$name" =~ $BATS_TEST_FILTER ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should be case insensitive? It's certainly more convenient that way, as the only way I know of altering Bash regex case sensitivity is out-of-pattern, e.g. shopt -s nocasematch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm leaning against case insensitivity, but not strongly. Is it really significantly inconvenient for you, @sublimino? If it isn't, yet the case sensitivity reveals itself as a point of friction for users, perhaps we could add it later.

Copy link
Member

Choose a reason for hiding this comment

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

It's a minor annoyance with the first time I tested this PR, that's all :) I'll feed back after I've used it in anger

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So are you good to go with this update? Feel free to merge if you like, or wait if you want @jasonkarns or others to chime in. (On the changes as they are, as well as whether I should throw in case insensitivity.)

I know I still owe @jasonkarns feedback on #124 as well... But after digging into this and queuing up some other cleanups and changes on top of this on Saturday, I gave myself a break on Sunday.

Copy link
Contributor

Choose a reason for hiding this comment

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

For what my two cents is worth, I don't think we gain much from having case insensitivity here. That said, if it is a friction point for users later, we could implement an --ifilter option to allow the user to decide whether they want case insensitivity or not. As far as actually doing case insensitivity, shopt -s nocasematch may be the only way we can do it without explicitly requiring Bash 4+. We also would run the risk of name collisions, and would need to have detection logic for that in the event it is used. On the whole, I'm not sure that case insensitivity support gives us enough back to offset the implementation effort.

All of that said, the rest of this looks good to me.

Bland, Mike added 5 commits July 21, 2018 11:52
Per @sublimino's suggestion in #126, `usage()` and `help()` have been
combined into `usage()`. Also updates the format of the `Usage:` stanza
to make it more readable.

Also adds the `BATS_VERSION` environment variable, which seems like a
reasonable item to export. This implementation is in conflict with
the change @jasonkarns made in #124, though as small change to that
PR should bring it in line.
This was causing the extended syntax tests to fail when running via
`bats -f extended test` because none of the tests run under those cases
matched `BATS_TEST_FILTER`.

Also removed some vestigial `emit_debug_output` calls, and replaced
`bats_trim_filename` with a direct string prefix removal expression when
computing `RELATIVE_FIXTURE_ROOT`.
This is a little cleaner in a sense, and allows us to add other options
more easily in the future.
Also updates the README and adds a few entries to the "Unreleased"
section of the CHANGELOG.
Now that the filter is passed through as a command line flag,
BATS_TEST_FILTER no longer exists.
@mbland
Copy link
Contributor Author

mbland commented Jul 21, 2018

FYI, I've also pushed commits to remove BATS_TEST_FILTER in favor of passing the filter through to bats-exec-{suite,test} via a command line flag (which required refactoring those programs' command line parsing), and to update the documentation (including the copyright dates).

Bland, Mike added 2 commits July 21, 2018 19:07
`BATS_PERFORM_TEST_FLAGS` will make it easier to pass flags through when
implementing features in the near future.

Also added some comments to explain what's happening with bats-exec-test
re-invoking itself via `bats_perform_tests`.
All manner of builds started failing on Bash versions < 4.4 (admittedly
I didn't test using 3.2.57(1)-release before pushing):

- https://travis-ci.org/bats-core/bats-core/builds/406704189
- https://travis-ci.org/bats-core/bats-core/builds/406704230

Chapter and verse from https://tiswww.case.edu/php/chet/bash/CHANGES:

> This document details the changes between this version, bash-4.4-rc2,
> and the previous version, bash-4.4-beta2.
>
> 3.  New Features in Bash
>
> a.  Using ${a[@]} or ${a[*]} with an array without any assigned
>     elements when the nounset option is enabled no longer throws an
>     unbound variable error.

This sidesteps the issue by using `BATS_PERFORM_TEST_CMD` to building
the re-invoked bats-exec-test command, ensuring the array won't be
empty.
@mbland
Copy link
Contributor Author

mbland commented Aug 2, 2018

In the interest of keeping things moving, I'm going to merge this now and submit my next cleanup PR.

@jasonkarns, I've literally put time on my calendar for Saturday morning to take a look at #124 and take it for a test drive. I'm thinking we can use it to release v1.2.0 by early next week.

@mbland mbland merged commit cdd0dd8 into master Aug 2, 2018
@mbland mbland deleted the test-filter branch August 2, 2018 12:32
@ghost ghost removed the review label Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants