<commit_before>/*
 * grunt-contrib-nodeunit
 * http://gruntjs.com/
 *
 * Copyright (c) 2014 "Cowboy" <NAME>, contributors
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  // Nodejs libs.
  var path = require('path');
  var util = require('util');
  var fs = require('fs');

  // External libs.
  var nodeunit = require('nodeunit');
  var hooker = require('hooker');

  // ==========================================================================
  // BETTER ERROR DISPLAY
  // ==========================================================================

  // Much nicer error formatting than what comes with nodeunit.
  var betterErrors = function (assertion) {
    var e = assertion.error;
    if (!e || !('actual' in e) || !('expected' in e)) { return assertion; }

    // Temporarily override the global "inspect" property because logging
    // the entire global object is just silly.
    var globalInspect = global.inspect;
    global.inspect = function() { return '[object global]'; };

    e._message = e.message;

    // Pretty-formatted objects.
    var actual = util.inspect(e.actual, false, 10, true);
    var expected = util.inspect(e.expected, false, 10, true);

    var indent = function(str) {
      return (''+str).split('\n').map(function(s) { return '  ' + s; }).join('\n');
    };

    var stack;
    var multiline = (actual + expected).indexOf('\n') !== -1;
    if (multiline) {
      stack = [
        'Actual:', indent(actual),
        'Operator:', indent(e.operator),
        'Expected:', indent(expected),
      ].join('\n');
    } else {
      stack = e.name + ': ' + actual + ' ' + e.operator + ' ' + expected;
    }

    e.stack = stack + '\n' + e.stack.split('\n').slice(1).join('\n');

    // Restore the global "inspect" property.
    global.inspect = globalInspect;
    return assertion;
  };

  // Reformat stack trace to remove nodeunit scripts, fix indentation, etc.
  var cleanStack = function(error) {
    error._stack = error.stack;
    // Show a full stack trace?
    var fullStack = grunt.option('verbose') || grunt.option('stack');
    // Reformat stack trace output.
    error.stack = error.stack.split('\n').map(function(line) {
      if (line[0] === ' ') {
        // Remove nodeunit script srcs from non-verbose stack trace.
        if (!fullStack && line.indexOf(path.join('node_modules', 'nodeunit') + path.sep) !== -1) {
          return '';
        }
        // Remove leading spaces.
        line = line.replace(/^ {4}(?=at)/, '');<commit_msg>Check error.stack exists (Fixes #30)<commit_after>/*
 * grunt-contrib-nodeunit
 * http://gruntjs.com/
 *
 * Copyright (c) 2014 "Cowboy" <NAME>, contributors
 * Licensed under the MIT license.
 */

'use strict';

module.exports = function(grunt) {

  // Nodejs libs.
  var path = require('path');
  var util = require('util');
  var fs = require('fs');

  // External libs.
  var nodeunit = require('nodeunit');
  var hooker = require('hooker');

  // ==========================================================================
  // BETTER ERROR DISPLAY
  // ==========================================================================

  // Much nicer error formatting than what comes with nodeunit.
  var betterErrors = function (assertion) {
    var e = assertion.error;
    if (!e || !('actual' in e) || !('expected' in e)) { return assertion; }

    // Temporarily override the global "inspect" property because logging
    // the entire global object is just silly.
    var globalInspect = global.inspect;
    global.inspect = function() { return '[object global]'; };

    e._message = e.message;

    // Pretty-formatted objects.
    var actual = util.inspect(e.actual, false, 10, true);
    var expected = util.inspect(e.expected, false, 10, true);

    var indent = function(str) {
      return (''+str).split('\n').map(function(s) { return '  ' + s; }).join('\n');
    };

    var stack;
    var multiline = (actual + expected).indexOf('\n') !== -1;
    if (multiline) {
      stack = [
        'Actual:', indent(actual),
        'Operator:', indent(e.operator),
        'Expected:', indent(expected),
      ].join('\n');
    } else {
      stack = e.name + ': ' + actual + ' ' + e.operator + ' ' + expected;
    }

    if (e.stack) {
      stack += '\n' + e.stack.split('\n').slice(1).join('\n');
    }

    e.stack = stack;

    // Restore the global "inspect" property.
    global.inspect = globalInspect;
    return assertion;
  };

  // Reformat stack trace to remove nodeunit scripts, fix indentation, etc.
  var cleanStack = function(error) {
    error._stack = error.stack;
    // Show a full stack trace?
    var fullStack = grunt.option('verbose') || grunt.option('stack');
    // Reformat stack trace output.
    error.stack = error.stack.split('\n').map(function(line) {
      if (line[0] === ' ') {
        // Remove nodeunit script srcs from non-verbose stack trace.
        if (!fullStack && line.indexOf(path.join('node_modules', 'nodeunit') + path.sep) !== -1) {
          return '';
        }
        // Remove leading spaces.
        line = line.replace(/^ {4}(?=at)/, '');
{'fraction_non_alphanumeric': 0.2171372930866602, 'fraction_numerical': 0.005452775073028238, 'mean_word_length': 2.835698282300224, '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': '1155211', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1519, 'n_words': 411}