var path = require('path');
var expect = require('chai').expect;
var test = require('../..').test;
var exec = require('child_process').exec;
var files = path.normalize(path.join(__dirname, '..', 'files'));

var cmd = 'test';
var missing = 'missing.txt';
var regular = path.join(files, 'regular.txt');
var directory = path.join(files, 'directory');

function run(args, callback) {
  args.unshift(cmd);
  var command = args.join(' ');
  return exec(command,
    function (error, stdout, stderr) {
      if (error !== null) {
        return callback(false);
      }
      callback(true);
  });
}

describe('cli-util:', function() {
  it('should test file exists (false)', function(done) {
    var result = false;
    var expr = '-e';
    var value = missing;
    var args = [expr, value];
    run(args, function(expected) {
      expect(result).to.eql(expected);
      var res = test(expr, value);
      expect(res).to.eql(expected);
      test(expr, value, function(res) {
        expect(res).to.eql(expected);
        done();
      });
    });
  });
  it('should test file exists (true)', function(done) {
    var result = true;
    var expr = '-e';
    var value = regular;
    var args = [expr, value];
    run(args, function(expected) {
      expect(result).to.eql(expected);
      var res = test(expr, value);
      expect(res).to.eql(expected);
      test(expr, value, function(res) {
        expect(res).to.eql(expected);
        done();
      });
    });
  });
  it('should test file exists and is a regular file - missing (false)',
    function(done) {
      var result = false;
      var expr = '-f';
      var value = missing;
      var args = [expr, value];
      run(args, function(expected) {
        expect(result).to.eql(expected);
        var res = test(expr, value);
        expect(res).to.eql(expected);
        test(expr, value, function(res) {
          expect(res).to.eql(expected);
          done();
        });
      });
    }
  );
  it('should test file exists and is a regular file - directory (false)',
    function(done) {
      var result = false;
      var expr = '-f';
      var value = directory;
      var args = [expr, value];
      run(args, function(expected) {
        expect(result).to.eql(expected);
        var res = test(expr, value);
        expect(res).to.eql(expected);
        test(expr, value, function(res) {
          expect(res).to.eql(expected);
          done();
        });
      });
    }
  );
  it('should test file exists and is a regular file (true)', function(done) {
    var result = true;
    var expr = '-f';
    var value = regular;
    var args = [expr, value];
    run(args, function(expected) {
      expect(result).to.eql(expected);
      var res = test(expr, value);
      expect(res).to.eql(expected);
      test(expr, value, function(res) {
        expect(res).to.eql(expected);
        done();
      });
    });
  });
})

@@ -198,16 +198,52 @@
 iles'));
+%0Avar etc = '/etc';%0Avar dev = '/dev';
 %0A%0Avar cm
@@ -279,24 +279,45 @@
 ssing.txt';%0A
+var directory = etc;%0A
 var regular 
@@ -332,76 +332,112 @@
 oin(
-files, 'regular.txt');%0Avar directory = path.join(files, 'directory')
+etc, 'passwd');%0Avar block = path.join(dev, 'vn0');%0Avar character = path.join(dev, 'zero');%0Avar tty = '1'
 ;%0A%0Af
@@ -2971,11 +2971,1389 @@
 ;%0A  %7D);%0A
+  it('should test block file - missing (false)',%0A    function(done) %7B%0A      var result = false;%0A      var expr = '-b';%0A      var value = missing;%0A      var args = %5Bexpr, value%5D;%0A      run(args, function(expected) %7B%0A        expect(result).to.eql(expected);%0A        var res = test(expr, value);%0A        expect(res).to.eql(expected);%0A        test(expr, value, function(res) %7B%0A          expect(res).to.eql(expected);%0A          done();%0A        %7D);%0A      %7D);%0A    %7D%0A  );%0A  it('should test block file - regular (false)',%0A    function(done) %7B%0A      var result = false;%0A      var expr = '-b';%0A      var value = regular;%0A      var args = %5Bexpr, value%5D;%0A      run(args, function(expected) %7B%0A        expect(result).to.eql(expected);%0A        var res = test(expr, value);%0A        expect(res).to.eql(expected);%0A        test(expr, value, function(res) %7B%0A          expect(res).to.eql(expected);%0A          done();%0A        %7D);%0A      %7D);%0A    %7D%0A  );%0A  it('should test block file (true)',%0A    function(done) %7B%0A      var result = true;%0A      var expr = '-b';%0A      var value = block;%0A      var args = %5Bexpr, value%5D;%0A      run(args, function(expected) %7B%0A        expect(result).to.eql(expected);%0A        var res = test(expr, value);%0A        expect(res).to.eql(expected);%0A        test(expr, value, function(res) %7B%0A          expect(res).to.eql(expected);%0A          done();%0A        %7D);%0A      %7D);%0A    %7D%0A  );%0A
 %7D)%0A

Add block file tests.