<commit_before>/*
 * grunt-ghost
 * https://github.com/colinwren/grunt-ghost
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

module.exports = function (grunt) {
  'use strict';
  // Create MultiTask 'ghost'
  grunt.registerMultiTask('ghost', 'Runs CasperJS Tests.', function () {
    // Get options object
    var options = this.data.options,
        // Tells Grunt that this asynchronous and that it is finished when
        // "done()" is called
        done = this.async(),
        // Get filepaths from 'src' and sorts alphabetically
        filepaths = this.data.filesSrc.sort(),
        // Create array that will contain all the parameters for CasperJS
        command = ['test'].concat(filepaths),
        // Get spawn function for the CasperJS process creation
        spawn = require('child_process').spawn;

    // If there are no options set options to an empty object
    if (typeof options === 'undefined') {
      options = {};
    }

    // Get CasperJS test options and add them to command array
    if (options.xunit) {
      command.push('--xunit=' + options.xunit);
    }
    if (options.direct) {
      command.push('--direct');
    }
    if (options.includes) {
      command.push('--includes=' + options.includes.join());
    }
    if (options.logLevel) {
      command.push('--log-level=' + options.logLevel);
    }
    if (options.pre) {
      command.push('--pre=' + options.pre.join());
    }
    if (options.post) {
      command.push('--post=' + options.post.join());
    }
    if (options.failFast) {
      command.push('--fail-fast');
    }
    if (options.args) {
      var args = options.args;
      for (var a in args) {
        command.push('--' + a + '=' + args[a]);
      }
    }

    // Function to wrap grunt log output at 80 characters
    var lastSpace;
    function wrap(str) {
      // Will run until there are no spaces in the string (All arguments have
      // spaces after them)
      if (str.indexOf(' ') === -1) {
        return;
      }
      // Finds last space in the first 80 characters of the string
      lastSpace = str.substr(0, 80).lastIndexOf(' ');
      // Writes string until the last space into grunt log
      grunt.log.write(str.substr(0, lastSpace) + '\n');
      // Calls itself with the rest of the string that was no logged
      wrap(str.substr(lastSpace + 1));
    }

    // Additional Options
    // Prints command sent to CasperJS
    if (options.printCommand) {
      wrap('\u001b[1m\u001b[4mCommand:\u001b[0m casperjs ' +
          command.join(' ') + ' \n');
    }

    // Prints filepaths sent to CasperJS in alternating colors
    if (options.printFilePaths) {
      var files = '',
          colors = [
            '\u001b[34m', // Blue
            '\u001b[33m', // Yellow
            '\u001b[36m', // Cyan
            '\u001b[35m', // Magenta
            '\u001b[32m'  // Green
          ];
      // Give file paths alternating colors and add them to 'files' string
      for (var i = 0; i < filepaths.length; i++) {
        files += colors[i % colors.length] + filepaths[i] + ' ';
      }
      // Send to wrap function to be printed
      wrap('\u001b[1m\u001b[4mTesting:\u001b[0m\u001b[1m ' + files + '\n');
    }

    // Create CasperJS process
    var cspr = spawn('casperjs', command);
    cspr.stdout.setEncoding('utf8');
    // On receiving output from CasperJS, print it line by line
    cspr.stdout.on('data', function (data) {
      var lines = data.toString().split(/(\e?\n)/g);
      for (var j = 0; j < lines.length; j++) {
        grunt.log.write(lines[j]);
      }
    });

    // Captures errors from CasperJS and prints them
    cspr.stderr.on('data', function (data) {
      grunt.log.error(data);
      done();
    });

    // On completion print message
    cspr.on('exit', function () {
      done();
    });
  });<commit_msg>Changed spawn helper to Grunt's built-in util for better Windows compatibility<commit_after>/*
 * grunt-ghost
 * https://github.com/colinwren/grunt-ghost
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

module.exports = function (grunt) {
  'use strict';
  // Create MultiTask 'ghost'
  grunt.registerMultiTask('ghost', 'Runs CasperJS Tests.', function () {
    // Get options object
    var options = this.data.options,
        // Tells Grunt that this asynchronous and that it is finished when
        // "done()" is called
        done = this.async(),
        // Get filepaths from 'src' and sorts alphabetically
        filepaths = this.data.filesSrc.sort(),
        // Create array that will contain all the parameters for CasperJS
        command = ['test'].concat(filepaths);

    // If there are no options set options to an empty object
    if (typeof options === 'undefined') {
      options = {};
    }

    // Get CasperJS test options and add them to command array
    if (options.xunit) {
      command.push('--xunit=' + options.xunit);
    }
    if (options.direct) {
      command.push('--direct');
    }
    if (options.includes) {
      command.push('--includes=' + options.includes.join());
    }
    if (options.logLevel) {
      command.push('--log-level=' + options.logLevel);
    }
    if (options.pre) {
      command.push('--pre=' + options.pre.join());
    }
    if (options.post) {
      command.push('--post=' + options.post.join());
    }
    if (options.failFast) {
      command.push('--fail-fast');
    }
    if (options.args) {
      var args = options.args;
      for (var a in args) {
        command.push('--' + a + '=' + args[a]);
      }
    }

    // Function to wrap grunt log output at 80 characters
    var lastSpace;
    function wrap(str) {
      // Will run until there are no spaces in the string (All arguments have
      // spaces after them)
      if (str.indexOf(' ') === -1) {
        return;
      }
      // Finds last space in the first 80 characters of the string
      lastSpace = str.substr(0, 80).lastIndexOf(' ');
      // Writes string until the last space into grunt log
      grunt.log.write(str.substr(0, lastSpace) + '\n');
      // Calls itself with the rest of the string that was no logged
      wrap(str.substr(lastSpace + 1));
    }

    // Additional Options
    // Prints command sent to CasperJS
    if (options.printCommand) {
      wrap('\u001b[1m\u001b[4mCommand:\u001b[0m casperjs ' +
          command.join(' ') + ' \n');
    }

    // Prints filepaths sent to CasperJS in alternating colors
    if (options.printFilePaths) {
      var files = '',
          colors = [
            '\u001b[34m', // Blue
            '\u001b[33m', // Yellow
            '\u001b[36m', // Cyan
            '\u001b[35m', // Magenta
            '\u001b[32m'  // Green
          ];
      // Give file paths alternating colors and add them to 'files' string
      for (var i = 0; i < filepaths.length; i++) {
        files += colors[i % colors.length] + filepaths[i] + ' ';
      }
      // Send to wrap function to be printed
      wrap('\u001b[1m\u001b[4mTesting:\u001b[0m\u001b[1m ' + files + '\n');
    }

    grunt.util.spawn({
      cmd: 'casperjs',
      args: command
    }, function (error, result, code) {
      grunt.log.writeln(result.stdout);
      if (error) {
        grunt.fail.fatal();
      }
      done();
    });
  });
{'fraction_non_alphanumeric': 0.14401762357152692, 'fraction_numerical': 0.01900041305245766, 'mean_word_length': 2.105600684053014, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '2076487', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2243, 'n_words': 633}