<commit_before>var getFixtures = require("babel-helper-fixtures").multiple;
var parse       = require("../lib").parse;
var test        = require("ava");
var _           = require("lodash");

var fixtures = getFixtures(__dirname + "/fixtures");

_.each(fixtures, function (suites, name) {
  _.each(suites, function (testSuite) {
    _.each(testSuite.tests, function (task) {
      test(name + "/" + testSuite.title + "/" + task.title, !task.disabled && function () {
        try {
          return runTest(task);
        } catch (err) {
          err.message = task.actual.loc + ": " + err.message;
          throw err;
        }
      });
    });
  });
});

function save(test, ast) {
  delete ast.tokens;
  if (!ast.comments.length) delete ast.comments;
  require("fs").writeFileSync(test.expect.loc, JSON.stringify(ast, null, "  "));
}

function runTest(test) {
  var opts = test.options;
  opts.locations = true;
  opts.ranges = true;

  try {
    var ast = parse(test.actual.code, opts);
  } catch (err) {
    if (opts.throws) {
      if (err.message === opts.throws) {
        return;
      } else {
        err.message = "Expected error message: " + opts.throws + ". Got error message: " + err.message;
        throw err;
      }
    }

    throw err;
  }

  if (!test.expect.code) {
    test.expect.loc += "on";
    return save(test, ast);
  }

  if (opts.throws) {
    throw new Error("Expected error message: " + opts.throws + ". But parsing succeeded.");
  } else {
    var mis = misMatch(JSON.parse(test.expect.code), ast);
    if (mis) {
      //save(test, ast);
      throw new Error(mis);
    }
  }
}

function ppJSON(v) {
  return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2);
}

function addPath(str, pt) {
  if (str.charAt(str.length - 1) == ")") {
    return str.slice(0, str.length - 1) + "/" + pt + ")";
  } else {
    return str + " (" + pt + ")";
  }
}
<commit_msg>Fix tests to not save expected output if we expect the test to fail<commit_after>var getFixtures = require("babel-helper-fixtures").multiple;
var parse       = require("../lib").parse;
var test        = require("ava");
var _           = require("lodash");

var fixtures = getFixtures(__dirname + "/fixtures");

_.each(fixtures, function (suites, name) {
  _.each(suites, function (testSuite) {
    _.each(testSuite.tests, function (task) {
      test(name + "/" + testSuite.title + "/" + task.title, !task.disabled && function () {
        try {
          return runTest(task);
        } catch (err) {
          err.message = task.actual.loc + ": " + err.message;
          throw err;
        }
      });
    });
  });
});

function save(test, ast) {
  delete ast.tokens;
  if (!ast.comments.length) delete ast.comments;
  require("fs").writeFileSync(test.expect.loc, JSON.stringify(ast, null, "  "));
}

function runTest(test) {
  var opts = test.options;
  opts.locations = true;
  opts.ranges = true;

  try {
    var ast = parse(test.actual.code, opts);
  } catch (err) {
    if (opts.throws) {
      if (err.message === opts.throws) {
        return;
      } else {
        err.message = "Expected error message: " + opts.throws + ". Got error message: " + err.message;
        throw err;
      }
    }

    throw err;
  }

  if (!test.expect.code && !opts.throws) {
    test.expect.loc += "on";
    return save(test, ast);
  }

  if (opts.throws) {
    throw new Error("Expected error message: " + opts.throws + ". But parsing succeeded.");
  } else {
    var mis = misMatch(JSON.parse(test.expect.code), ast);
    if (mis) {
      //save(test, ast);
      throw new Error(mis);
    }
  }
}

function ppJSON(v) {
  return v instanceof RegExp ? v.toString() : JSON.stringify(v, null, 2);
}

function addPath(str, pt) {
  if (str.charAt(str.length - 1) == ")") {
    return str.slice(0, str.length - 1) + "/" + pt + ")";
  } else {
    return str + " (" + pt + ")";
  }
}

{'fraction_non_alphanumeric': 0.17156105100463678, 'fraction_numerical': 0.0020607934054611026, 'mean_word_length': 2.445430346051464, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '6560390', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1286, 'n_words': 300}