<commit_before>var assert = require('assert'), execFile = require('child_process').execFile, path = require('path');

describe('tern condense output', function() {
  [
    {name: 'simple'},
    {name: 'nodejs', args: ['--plugin', 'node']},
  ].forEach(function(file) {
    it(file.name + ' (with args: ' + (file.args || []).join(' ') + ')', function(done) {
      var want = require('./testdata/' + file.name + '.json');
      var args = ['node_modules/tern/bin/condense'];
      if (file.args) args.push.apply(args, file.args);
      args.push('--plugin', 'def-origin', 'testdata/' + file.name + '.js')
      execFile(process.execPath /* node */, args, function(err, stdout, stderr) {
        if (stderr) console.error(stderr);
        assert.ifError(err);
        var got = JSON.parse(stdout);
        // console.log(JSON.stringify(got, null, 2));
        assert.deepEqual(got, want);
        done();
      });
    });
  });
});
<commit_msg>test runner with EXP writing and DEBUG printing<commit_after>var assert = require('assert'), execFile = require('child_process').execFile, fs = require('fs'), path = require('path');

describe('tern condense output', function() {
  [
    {name: 'simple'},
    {name: 'nodejs', args: ['--plugin', 'node']},
  ].forEach(function(file) {
    it(file.name + ' (with args: ' + (file.args || []).join(' ') + ')', function(done) {
      var expFile = './testdata/' + file.name + '.json';
      var want = require(expFile);
      var args = ['node_modules/tern/bin/condense'];
      if (file.args) args.push.apply(args, file.args);
      args.push('--plugin', 'def-origin', 'testdata/' + file.name + '.js')
      execFile(process.execPath /* node */, args, function(err, stdout, stderr) {
        if (stderr) console.error(stderr);
        assert.ifError(err);
        var got = JSON.parse(stdout);
        if (process.env['EXP']) {
          var pp = JSON.stringify(got, null, 2);
          fs.writeFile(expFile, pp + '\n', function(err) {
            assert.ifError(err);
            assert(false); // don't let test pass when writing expectation
            done();
          });
          return;
        }
        if (process.env['DEBUG']) console.log(JSON.stringify(got, null, 2));
        assert.deepEqual(got, want);
        done();
      });
    });
  });
});

{'fraction_non_alphanumeric': 0.19921875, 'fraction_numerical': 0.0013020833333333333, 'mean_word_length': 2.7237479806138936, 'pattern_counts': {'":': 0, '<': 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': '1472379', 'n_tokens_mistral': 722, 'n_tokens_neox': 715, 'n_words': 158}