<commit_before>/*
 * macros.js: Test macros hook.io module
 *
 * (C) 2011 <NAME>, <NAME>
 * MIT LICENCE
 *
 */

var assert = require('assert'),
    path = require('path'),
    spawn = require('child_process').spawn,
    eyes = require('eyes'),
    request = require('request'),
    carapace = require('../../lib/carapace');

var macros = exports;

macros.assertUse = function (plugins, vows) {
  var names = plugins.map(function (p) { return path.basename(p, '.js') });
  
  var context = {
    topic: function () {
      //
      // should be an array
      // we have to do this because carapace, preloads these plugins
      //
      var scripts = plugins.map(function (plugin) {
        return carapace.load(plugin);
      });
      
      carapace.use(scripts, this.callback.bind(null, null));
    },
    "should have load the plugin(s)": function () {
      assert.isArray(plugins);
      names.forEach(function (name) {
        assert.isFunction(carapace[name]);
      });
    }
  };
  
  return extendContext(context, vows);
};

macros.assertRun = function (script, argv, vows) {
  var context = {
    topic: function () {
      carapace.on('carapace::running', this.callback.bind(carapace, null));
      carapace.argv = argv || [];
      carapace.script = script;
      carapace.run();
    },
    "should fire the `carapace::running` event": function () {
      assert.equal(carapace.event, 'carapace::running');
    },
    "should rewrite process.argv transparently": function () {
      assert.equal(process.argv[1], script);
    }
  };
  
  return extendContext(context, vows);
};

macros.assertSpawn = function (PORT, script, argv, vows) {
  argv = argv.slice(0);
  
  var context = {
    topic: function () {
      var that = this,
          child = spawn(carapace.bin, ['--hook-port', PORT, script].concat(argv));
      child.stdout.once('data', that.callback.bind(null, null, child));
    },
    "should respond with the proper wrapped script output": function (_, child, data) {
      assert.notEqual(data.toString().indexOf(script), -1);
    }
  }
  <commit_msg>[test] Don't prefix events in `macros.assertRun`<commit_after>/*
 * macros.js: Test macros hook.io module
 *
 * (C) 2011 <NAME>, <NAME>
 * MIT LICENCE
 *
 */

var assert = require('assert'),
    path = require('path'),
    spawn = require('child_process').spawn,
    eyes = require('eyes'),
    request = require('request'),
    carapace = require('../../lib/carapace');

var macros = exports;

macros.assertUse = function (plugins, vows) {
  var names = plugins.map(function (p) { return path.basename(p, '.js') });
  
  var context = {
    topic: function () {
      //
      // should be an array
      // we have to do this because carapace, preloads these plugins
      //
      var scripts = plugins.map(function (plugin) {
        return carapace.load(plugin);
      });
      
      carapace.use(scripts, this.callback.bind(null, null));
    },
    "should have load the plugin(s)": function () {
      assert.isArray(plugins);
      names.forEach(function (name) {
        assert.isFunction(carapace[name]);
      });
    }
  };
  
  return extendContext(context, vows);
};

macros.assertRun = function (script, argv, vows) {
  var context = {
    topic: function () {
      carapace.on('running', this.callback.bind(carapace, null));
      carapace.argv = argv || [];
      carapace.script = script;
      carapace.run();
    },
    "should fire the `carapace::running` event": function () {
      assert.equal(carapace.event, 'running');
    },
    "should rewrite process.argv transparently": function () {
      assert.equal(process.argv[1], script);
    }
  };
  
  return extendContext(context, vows);
};

macros.assertSpawn = function (PORT, script, argv, vows) {
  argv = argv.slice(0);
  
  var context = {
    topic: function () {
      var that = this,
          child = spawn(carapace.bin, ['--hook-port', PORT, script].concat(argv));
      child.stdout.once('data', that.callback.bind(null, null, child));
    },
    "should respond with the proper wrapped script output": function (_, child, data) {
      assert.notEqual(data.toString().indexOf(script), -1);
    }
  }
  
{'fraction_non_alphanumeric': 0.15904191616766467, 'fraction_numerical': 0.0033532934131736527, 'mean_word_length': 2.786038077969175, 'pattern_counts': {'":': 8, '<': 7, '<?xml version=': 0, '>': 7, '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': '731700', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1321, 'n_words': 307}