Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute tests that match a regular expression only?

Tags:

scala

sbt

In sbt 0.10.1, I frequently use test-only to narrow down the number of my tests.

sbt> test-only com.example.MySpec 

However, I want to narrow down such that I only run tests whose name/description matches a regular expression. Is there some syntax to achieve something like this?

sbt> test-only .*someRexExp.* 
like image 920
tobym Avatar asked Aug 09 '11 14:08

tobym


People also ask

How do I test a regular expression?

To test a regular expression, first search for errors such as non-escaped characters or unbalanced parentheses. Then test it against various input strings to ensure it accepts correct strings and regex wrong ones. A regex tester tool is a great tool that does all of this.

What will the \$ regular expression match?

\$ will help to find the character "$" available in the content based on the expression flags assigned to the regular expression.

Which is faster regex match or regex test?

The match() method retrieves the matches when matching a string against a regular expression. Use . test if you want a faster boolean check.


1 Answers

Full regular expressions are not supported by testOnly. Wildcards are supported, however.

sbt> testOnly com.example.*Spec 

Only the asterisk * is interpreted specially here and not the periods. This will select all tests beginning with com.example. and ending with Spec.

Or just all test Specs:

sbt> testOnly *Spec 

testOnly and other testing information is documented here: http://www.scala-sbt.org/release/docs/Detailed-Topics/Testing

like image 61
Mark Harrah Avatar answered Oct 02 '22 13:10

Mark Harrah