<commit_before>var fs = require('mz/fs');
var walk = require('klaw');
var filter = require('through2-filter');
fs.readlinkSync = require('readlink').sync; // a non-broken readlink...

var esprima = require('esprima');
var esprimaToAST = require('../esprima-to-ast.js');

var test262path = fs.readlinkSync(__dirname + '/test262');
var tests = [];

/* Tests whether a given test is negative.
 * Returns: a string if type of failure specified, true, or false
 */
function testNegativity(str) {
  var result = /@negative\s*(\w*)?\s*$/m.exec(str);
  if(result) {
    result = result[1] || true;
  } else {
    result = false;
  }
  return result;
}

function isParserNegativeTest(str) {
  var negative = testNegativity(str);
  if (typeof negative === 'boolean') {
    return negative;
  }
  // Second case testing for an Early (Syntax) Error
  return /(?:SyntaxError|\?!NotEarlyError)/.test(negative);
}

walk(test262path)
.pipe(filter.obj(file => file.stats.isFile() && file.path.endsWith(".js")))
.on('readable', function() {
  var item;
  while((item = this.read())) { tests.push(item.path); }
})
.on('end', function() {
  describe("test262", function() {
    tests.forEach(item => {
      describe(item, function() {

        var source;
        var negative = '';

        before(function(done) {
          fs.readFile(item).then(
            data => {
              source = data;
              negative = isParserNegativeTest(data);
            }
          ).then(done);
        });

        it('parses', function() {
          try {
            esprima.parse(source);
          } catch(e) {
            if (!negative) {
              throw e;
            }
          }
        });

        it('converts', function(done) {
          var prog;
          try {
            prog = esprima.parse(source);
          } catch(e) {}

          console.log(prog);
          esprimaToAST(prog);
        });
      })
    });
  });

  run();
});<commit_msg>remove console.log from test runner<commit_after>var fs = require('mz/fs');
var walk = require('klaw');
var filter = require('through2-filter');
fs.readlinkSync = require('readlink').sync; // a non-broken readlink...

var esprima = require('esprima');
var esprimaToAST = require('../esprima-to-ast.js');

var test262path = fs.readlinkSync(__dirname + '/test262');
var tests = [];

/* Tests whether a given test is negative.
 * Returns: a string if type of failure specified, true, or false
 */
function testNegativity(str) {
  var result = /@negative\s*(\w*)?\s*$/m.exec(str);
  if(result) {
    result = result[1] || true;
  } else {
    result = false;
  }
  return result;
}

function isParserNegativeTest(str) {
  var negative = testNegativity(str);
  if (typeof negative === 'boolean') {
    return negative;
  }
  // Second case testing for an Early (Syntax) Error
  return /(?:SyntaxError|\?!NotEarlyError)/.test(negative);
}

walk(test262path)
.pipe(filter.obj(file => file.stats.isFile() && file.path.endsWith(".js")))
.on('readable', function() {
  var item;
  while((item = this.read())) { tests.push(item.path); }
})
.on('end', function() {
  describe("test262", function() {
    tests.forEach(item => {
      describe(item, function() {

        var source;
        var negative = '';

        before(function(done) {
          fs.readFile(item).then(
            data => {
              source = data;
              negative = isParserNegativeTest(data);
            }
          ).then(done);
        });

        it('parses', function() {
          try {
            esprima.parse(source);
          } catch(e) {
            if (!negative) {
              throw e;
            }
          }
        });

        it('converts', function(done) {
          var prog;
          try {
            prog = esprima.parse(source);
          } catch(e) {}

          esprimaToAST(prog);
        });
      })
    });
  });

  run();
});
{'fraction_non_alphanumeric': 0.1664522768201698, 'fraction_numerical': 0.0072034988422948285, 'mean_word_length': 2.24, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6668126', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1196, 'n_words': 261}