<commit_before>'use strict';

var path       = require ('path');
var should     = require ('should'); /* jshint ignore:line */
var shellcraft = require ('../');

var runShellCraft = function (callback) {
  var ext = path.join (__dirname, 'lib/extensions.js');
  shellcraft.registerExtension (ext, function () {
    shellcraft.begin ({}, callback);
  });
};

process.exit = function (code) {
  throw new Error (code);
};

beforeEach (function (done) {
  delete process.argv;
  process.argv = ['node', 'test'];
  done ();
});

describe ('command: test# <arg>', function () {
  it ('test0 should retrieve the argument', function (done) {
    process.argv[2] = 'test0';
    process.argv[3] = 'the argument';

    runShellCraft (function () {
      done ();
    });
  });

  it ('test1 should fail because the argument is missing', function (done) {
    process.argv[2] = 'test1';

    try {
      runShellCraft (function () {
        done ();
      });
    } catch (ex) {
      ex.message.should.be.equal ('1');
    }
    done ();
  });
});

describe ('command: test# [arg]', function () {
  it ('test2 should not fail if the argument is missing', function (done) {
    process.argv[2] = 'test2';
    /* no argument provided to test2... */

    runShellCraft (function () {
      done ();
    });
  });

  it ('test3 should fail if the number of arguments is greater than 1', function (done) {
    process.argv[2] = 'test3';
    process.argv[3] = 'arg1';
    process.argv[4] = 'arg2'; /* this argument should be dropped */

    runShellCraft (function () {
      done ();
    });
  });

  it ('test4 should retrieve the argument', function (done) {
    process.argv[2] = 'test4';
    process.argv[3] = 'the argument';

    runShellCraft (function () {
      done ();
    });
  });
});<commit_msg>Fixes tests accordingly to the last bug fixed about the bad aysnc shutdown.<commit_after>'use strict';

var path   = require ('path');
var should = require ('should'); /* jshint ignore:line */

var runShellCraft = function (args, callback) {
  var fork = require ('child_process').fork;

  var prog = fork (path.join (__dirname, './sc.js'), args, {silent: true});
  prog
    .on ('error', callback)
    .on ('close', callback);
};

describe ('command: test# <arg>', function () {
  it ('test0 should retrieve the argument', function (done) {
    var args = [
      'test0',
      'the argument'
    ];

    runShellCraft (args, function () {
      done ();
    });
  });

  it ('test1 should fail because the argument is missing', function (done) {
    var args = ['test1'];

    runShellCraft (args, function (code) {
      code.should.be.equal (1);
      done ();
    });
  });
});

describe ('command: test# [arg]', function () {
  it ('test2 should not fail if the argument is missing', function (done) {
    var args = ['test2'];
    /* no argument provided to test2... */

    runShellCraft (args, function () {
      done ();
    });
  });

  it ('test3 should fail if the number of arguments is greater than 1', function (done) {
    var args = [
      'test3',
      'arg1',
      'arg2' /* this argument should be dropped */
    ];

    runShellCraft (args, function () {
      done ();
    });
  });

  it ('test4 should retrieve the argument', function (done) {
    var args = [
      'test4',
      'the argument'
    ];

    runShellCraft (args, function () {
      done ();
    });
  });
});
{'fraction_non_alphanumeric': 0.1698057680988817, 'fraction_numerical': 0.011477339611536198, 'mean_word_length': 2.710698689956332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1486492', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1044, 'n_words': 327}