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

Add --fgrep. Use grep for RegExp, fgrep for str #1579

Merged
merged 1 commit into from Mar 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion bin/_mocha
Expand Up @@ -65,8 +65,9 @@ program
.option('-b, --bail', "bail after first test failure")
.option('-d, --debug', "enable node's debugger, synonym for node --debug")
.option('-g, --grep <pattern>', 'only run tests matching <pattern>')
.option('-f, --fgrep <string>', 'only run tests containing <string>')
.option('-gc, --expose-gc', 'expose gc extension')
.option('-i, --invert', 'inverts --grep matches')
.option('-i, --invert', 'inverts --grep and --fgrep matches')
.option('-r, --require <name>', 'require the given module')
.option('-s, --slow <ms>', '"slow" test threshold in milliseconds [75]')
.option('-t, --timeout <ms>', 'set test-case timeout in milliseconds [2000]')
Expand Down Expand Up @@ -266,6 +267,10 @@ mocha.suite.bail(program.bail);

if (program.grep) mocha.grep(new RegExp(program.grep));

// --fgrep

if (program.fgrep) mocha.grep(program.fgrep);

// --invert

if (program.invert) mocha.invert();
Expand Down
3 changes: 2 additions & 1 deletion lib/mocha.js
Expand Up @@ -76,7 +76,8 @@ function Mocha(options) {
options = options || {};
this.files = [];
this.options = options;
this.grep(options.grep);
if (options.grep) this.grep(new RegExp(options.grep));
if (options.fgrep) this.grep(options.fgrep);
this.suite = new exports.Suite('', new exports.Context);
this.ui(options.ui);
this.bail(options.bail);
Expand Down
1 change: 1 addition & 0 deletions support/tail.js
Expand Up @@ -140,6 +140,7 @@ mocha.run = function(fn){

var query = Mocha.utils.parseQuery(global.location.search || '');
if (query.grep) mocha.grep(new RegExp(query.grep));
if (query.fgrep) mocha.grep(query.fgrep);
if (query.invert) mocha.invert();

return Mocha.prototype.run.call(mocha, function(err){
Expand Down
17 changes: 12 additions & 5 deletions test/grep.js
Expand Up @@ -3,13 +3,20 @@ var Mocha = require('../');
describe('Mocha', function(){
describe('"grep" option', function(){
it('should add a RegExp to the mocha.options object', function(){
var mocha = new Mocha({ grep: /foo/ });
mocha.options.grep.toString().should.equal('/foo/');
var mocha = new Mocha({ grep: /foo.*/ });
mocha.options.grep.toString().should.equal('/foo.*/');
})

it('should convert grep string to a RegExp', function(){
var mocha = new Mocha({ grep: 'foo' });
mocha.options.grep.toString().should.equal('/foo/');
it('should convert string to a RegExp', function(){
var mocha = new Mocha({ grep: 'foo.*' });
mocha.options.grep.toString().should.equal('/foo.*/');
})
})

describe('"fgrep" option', function(){
it('should escape and convert string to a RegExp', function(){
var mocha = new Mocha({ fgrep: 'foo.*' });
mocha.options.grep.toString().should.equal('/foo\\.\\*/');
})
})

Expand Down