/**
 * Module dependencies.
 */

var util = require('util');
var program = require('../')
  , should = require('should');

var oldProcessExit = process.exit;
var oldConsoleError = console.error;

program
  .version('0.0.1')
  .option('-p, --pepper', 'add pepper');

var consoleErrors = [];
process.exit = function () {
};
console.error = function () {
  consoleErrors.push(util.format.apply(util, arguments));
};

program.parse('node test -m'.split(' '));
consoleErrors.length.should.equal(3);

// test subcommand
var consoleErrors = [];
program
  .command('sub')
  .action(function () {
  });
program.parse('node test sub -m'.split(' '));
consoleErrors.length.should.equal(3);

consoleErrors = [];
program
  .version('0.0.1')
  .option('-p, --pepper', 'add pepper');

program
  .allowUnknownOption()
  .parse('node test -m'.split(' '));
consoleErrors.length.should.equal(0);

// test subcommand
var consoleErrors = [];
program
  .command('sub')
  .allowUnknownOption()
  .action(function () {
  });
program.parse('node test sub -m'.split(' '));
consoleErrors.length.should.equal(3);

process.exit = oldProcessExit;
console.error = oldConsoleError;


@@ -29,17 +29,19 @@
  */%0A
-%0A
 var 
-util
+program
  = r
@@ -52,368 +52,256 @@
 re('
-util');%0Avar program = require('../')%0A  , should = require('should');%0A%0Avar oldProcessExit = process.exit;%0Avar oldConsoleError = console.error;%0A%0Aprogram%0A  .version('0.0.1')%0A  .option('-p, --pepper', 'add pepper');%0A%0Avar consoleErrors = %5B%5D;%0Aprocess.exit = function () %7B%0A%7D;%0Aconsole.error = function () %7B%0A  consoleErrors.push(util.format.apply(util, arguments));%0A%7D;%0A
+../')%0A    , sinon = require('sinon').sandbox.create()%0A    , should = require('should');%0A%0Avar stubError = sinon.stub(console, 'error');%0Avar stubExit = sinon.stub(process, 'exit');%0A%0Aprogram%0A  .version('0.0.1')%0A  .option('-p, --pepper', 'add pepper');
 %0Apro
@@ -339,36 +339,36 @@
 (' '));%0A
-consoleErrors.length
+%0AstubError.callCount
 .should.
@@ -374,24 +374,25 @@
 .equal(3);%0A%0A
+%0A
 // test subc
@@ -398,38 +398,33 @@
 command%0A
-var consoleErrors = %5B%5D
+resetStubStatus()
 ;%0Aprogra
@@ -523,65 +523,139 @@
 ));%0A
-consoleErrors.length.should.equal(3);%0A%0AconsoleErrors = %5B%5D
+%0AstubError.callCount.should.equal(3);%0AstubExit.calledOnce.should.be.true();%0A%0A// command with %60allowUnknownOption%60%0AresetStubStatus()
 ;%0Apr
@@ -717,25 +717,24 @@
 d pepper');%0A
-%0A
 program%0A  .a
@@ -794,88 +794,143 @@
 ));%0A
-consoleErrors.length.should.equal(0);%0A%0A// test subcommand%0Avar consoleErrors = %5B%5D
+%0AstubError.callCount.should.equal(0);%0AstubExit.calledOnce.should.be.false();%0A%0A// subcommand with %60allowUnknownOption%60%0AresetStubStatus()
 ;%0Apr
@@ -946,24 +946,25 @@
 command('sub
+2
 ')%0A  .allowU
@@ -1028,32 +1028,33 @@
 e('node test sub
+2
  -m'.split(' '))
@@ -1059,28 +1059,28 @@
 ));%0A
-consoleErrors.length
+%0AstubError.callCount
 .sho
@@ -1093,74 +1093,121 @@
 ual(
-3);%0A%0Aprocess.exit = oldProcessExit;%0Aconsole.error = oldConsoleError
+0);%0AstubExit.calledOnce.should.be.false();%0A%0A%0Afunction resetStubStatus() %7B%0A  stubError.reset();%0A  stubExit.reset()
 ;%0A
+%7D
 %0A

refactor test with sinion stub