-
Notifications
You must be signed in to change notification settings - Fork 518
Run a single test by name #36
Comments
Yes, we should add this feature. |
As an extension to this pull request it may be useful to filter tests by name using a regexp or a glob-style expression. |
I'm currently using this: dougm@0b25d8a With an Emacs mode to run the tests: https://github.com/dougm/bats-mode/blob/master/bats-mode.el There's a key-binding to run a single bats test, wherever the cursor is currently at. Any thoughts on the bats change above? Not sure the best way to do this, so I didn't mess with the options parser in bin/bats yet. |
Looks good and working to me. |
@ahippo I'd like a command-line option too, but afaict the options parser in bin/bats only handles boolean options. So I just wanted to get the concept working and check if I'm on the right path before making any changes to options parser. |
Yeah, you're right. |
@dougm This seems like a very useful feature. I hope it gets added soon. It would be cool to see a feature where BATS could do test grouping similar to TestNG. |
@harschware Just opened PR #117 - I've continued to use it myself as-is via bats-mode.el since |
Here is a simple shell script you can customize to run a single test: #!/bin/bash
batsdir=$(dirname $(readlink -f bats))
echo $batsdir
export PATH=$batsdir:$PATH
in=$1
a_test=$2
if [[ ! -e "$in" ]]
then
echo "not found: '$in'"
exit 2
fi
out=$(mktemp)
bats-preprocess < $in > $out
if [[ -z "$a_test" ]] || ! grep -q "^$a_test" $out
then
echo "test '$a_test' not found in $in"
echo "available test are:"
grep -o -E '^test_[^ ]+' $out
exit 1
fi
echo "temp_file: $out"
export BATS_TEST_SOURCE=$out
bats-exec-test $in $a_test As you can see bats as already almost all for that, but you need to preprocess the file yourself, and pass the filename via Not extensively tested… list test available: $ ./one_test.sh bats-preprocess.bats
/home/sylvain/code/bats/test/internal
test '' not found in bats-preprocess.bats
available test are:
test_preprocess_myself()
test_dummy_test() run one by its encoded name $ ./one_test.sh bats-preprocess.bats test_dummy_test
/home/sylvain/code/bats/test/internal
temp_file: /tmp/tmp.qJ5hM2Rl0O
1..1
ok 1 dummy test enjoy. |
Thanks, @Sylvain303 ! One little fix: should be |
All my tests take multiple minutes to run. I categorize them into separate files but it would still be nice to provide a string of a test name to only run that test to
bats
.The text was updated successfully, but these errors were encountered: