Coder Social home page Coder Social logo

Run a single test by name about bats HOT 10 OPEN

mitchellh avatar mitchellh commented on August 27, 2024 8
Run a single test by name

from bats.

Comments (10)

sstephenson avatar sstephenson commented on August 27, 2024

Yes, we should add this feature.

from bats.

ahippo avatar ahippo commented on August 27, 2024

As an extension to this pull request it may be useful to filter tests by name using a regexp or a glob-style expression.

from bats.

dougm avatar dougm commented on August 27, 2024

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.

from bats.

ahippo avatar ahippo commented on August 27, 2024

Looks good and working to me.
I was initially thinking of a command-line option for bats, but environment variables are ok for me too.

from bats.

dougm avatar dougm commented on August 27, 2024

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

from bats.

ahippo avatar ahippo commented on August 27, 2024

Yeah, you're right.
But at least adding a long option like --regex="qqq" seems pretty simple. (due to '=', it's a single argument)
Handling of --regex "qqq" or -r "qqq" requires much more changes though.

from bats.

harschware avatar harschware commented on August 27, 2024

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

from bats.

dougm avatar dougm commented on August 27, 2024

@harschware Just opened PR #117 - I've continued to use it myself as-is via bats-mode.el since

from bats.

Sylvain303 avatar Sylvain303 commented on August 27, 2024

Here is a simple shell script you can customize to run a single test:
$ cat one_test.sh

#!/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 export BATS_TEST_SOURCE

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.

from bats.

glikson avatar glikson commented on August 27, 2024

Thanks, @Sylvain303 ! One little fix: should be "readlink -f $(which bats)" (at least it helped me run it in my env).

from bats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.