<commit_before>'use strict';

var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');
var assert = require('assert');
var cp = require('child_process');

// Sets directory to output coverage data to
// Incremented every time getRunner() is called.
var covCount = 1;
var isIstanbul = process.env.running_under_istanbul;

/**
 * Gets an array containing the routine to run the jade CLI. If this file is
 * being processed with istanbul then this function will return a routine
 * asking istanbul to store coverage data to a unique directory
 * (cov-pt<covCount>/).
 */
function getRunner() {
  var jadeExe = __dirname + '/../bin/jade.js';

  if (!isIstanbul) return ['node', jadeExe];
  else {
    return ['istanbul', 'cover',
            '--print',  'none',
            '--report', 'none',
            '--root',   process.cwd(),
            '--dir',    process.cwd() + '/cov-pt' + (covCount++),
            jadeExe,
            '--'];
  }
}

function run(args, stdin, callback) {
  if (arguments.length === 2) {
    callback = stdin;
    stdin    = null;
  }
  var runner = getRunner().join(' ');
  cp.exec((stdin || '') + runner + ' ' + args, {
    cwd: __dirname + '/temp'
  }, callback);
}

mkdirp.sync(__dirname + '/temp/inputs/level-1-1');
mkdirp.sync(__dirname + '/temp/inputs/level-1-2');
mkdirp.sync(__dirname + '/temp/outputs');

describe('command line with HTML output', function () {
  if (isIstanbul) {
    this.timeout(8000);
    this.slow(6000);
  } else {
    this.slow(250);
  }
  it('jade --no-debug input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    fs.writeFileSync(__dirname + '/temp/input.html', '<p>output not written</p>');
    run('--no-debug input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/input.html', 'utf8');
      assert(html === '<div class="foo">bar</div>');
      done();
    });
  });
  it('jade --no-debug -E special-html input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    fs.writeFileSync(__dirname + '/temp/input.special-html', '<p>output not written</p>');
    run('--no-debug -E special-html input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/input.special-html', 'utf8');
      assert(html === '<div class="foo">bar</div>');
      done();
    });
  });
  it('jade --no-debug --obj "{\'loc\':\'str\'}" input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo= loc');
    fs.writeFileSync(__dirname + '/temp/input.html', '<p>output not written</p>');
    run('--no-debug --obj "{\'loc\':\'str\'}" input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/input.html', 'utf8');
      assert(html === '<div class="foo">str</div>');
      done();
    });
  });
  it('cat input.jade | jade --no-debug', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    run('--no-debug', 'cat input.jade | ', function (err, stdout, stderr) {
      if (err) return done(err);
      assert(stdout === '<div class="foo">bar</div>');
      done();
    });
  });
  it('jade --no-debug --out outputs input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    fs.writeFileSync(__dirname + '/temp/input.html', '<p>output not written</p>');
    run('--no-debug --out outputs input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/outputs/input.html', 'utf8');
      assert(html === '<div class="foo">bar</div>');
      done();
    });
  });
  context('when input is directory', function () {
    it('jade --no-debug --out outputs inputs', function (done) {
      fs.writeFileSync(__dirname + '/temp/inputs/input.jade', '.foo bar-1');
      fs.writeFileSync(__dirname + '/temp/inputs/level-1-1/input.jade', '.foo bar-1-1');
      fs.writeFileSync(__dirname + '/temp/inputs/level-1-2/input.jade', '.foo bar-1-2');
      fs.writeFileSync(__dirname + '/temp/input.js', 'throw new Error("output not written");');
      run('--no-debug --out outputs inputs', function (err) {
        if (err) return done(err);
        var html = fs.readFileSync(__dirname + '/temp/outputs/input.html', 'utf8');
        assert(html === '<div class="foo">bar-1</div>');
        var html = fs.readFileSync(__dirname + '/temp/outputs/level-1-1/input.html', 'utf8');
        assert(html === '<div class="foo">bar-1-1</div>');
        var html = fs.readFileSync(__dirname + '/temp/outputs/level-1-2/input.html', 'utf8');
        assert(html === '<div class="foo">bar-1-2</div>');
        done();
      });
    });
  });
});

describe('command line with client JS output', function () {
  if (isIstanbul) {
    this.timeout(8000);
    this.slow(6000);
  } else {<commit_msg>"poison" the output so that it can be detected if sub directory files did not change.<commit_after>'use strict';

var fs = require('fs');
var mkdirp = require('mkdirp');
var path = require('path');
var assert = require('assert');
var cp = require('child_process');

// Sets directory to output coverage data to
// Incremented every time getRunner() is called.
var covCount = 1;
var isIstanbul = process.env.running_under_istanbul;

/**
 * Gets an array containing the routine to run the jade CLI. If this file is
 * being processed with istanbul then this function will return a routine
 * asking istanbul to store coverage data to a unique directory
 * (cov-pt<covCount>/).
 */
function getRunner() {
  var jadeExe = __dirname + '/../bin/jade.js';

  if (!isIstanbul) return ['node', jadeExe];
  else {
    return ['istanbul', 'cover',
            '--print',  'none',
            '--report', 'none',
            '--root',   process.cwd(),
            '--dir',    process.cwd() + '/cov-pt' + (covCount++),
            jadeExe,
            '--'];
  }
}

function run(args, stdin, callback) {
  if (arguments.length === 2) {
    callback = stdin;
    stdin    = null;
  }
  var runner = getRunner().join(' ');
  cp.exec((stdin || '') + runner + ' ' + args, {
    cwd: __dirname + '/temp'
  }, callback);
}

mkdirp.sync(__dirname + '/temp/inputs/level-1-1');
mkdirp.sync(__dirname + '/temp/inputs/level-1-2');
mkdirp.sync(__dirname + '/temp/outputs');

describe('command line with HTML output', function () {
  if (isIstanbul) {
    this.timeout(8000);
    this.slow(6000);
  } else {
    this.slow(250);
  }
  it('jade --no-debug input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    fs.writeFileSync(__dirname + '/temp/input.html', '<p>output not written</p>');
    run('--no-debug input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/input.html', 'utf8');
      assert(html === '<div class="foo">bar</div>');
      done();
    });
  });
  it('jade --no-debug -E special-html input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    fs.writeFileSync(__dirname + '/temp/input.special-html', '<p>output not written</p>');
    run('--no-debug -E special-html input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/input.special-html', 'utf8');
      assert(html === '<div class="foo">bar</div>');
      done();
    });
  });
  it('jade --no-debug --obj "{\'loc\':\'str\'}" input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo= loc');
    fs.writeFileSync(__dirname + '/temp/input.html', '<p>output not written</p>');
    run('--no-debug --obj "{\'loc\':\'str\'}" input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/input.html', 'utf8');
      assert(html === '<div class="foo">str</div>');
      done();
    });
  });
  it('cat input.jade | jade --no-debug', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    run('--no-debug', 'cat input.jade | ', function (err, stdout, stderr) {
      if (err) return done(err);
      assert(stdout === '<div class="foo">bar</div>');
      done();
    });
  });
  it('jade --no-debug --out outputs input.jade', function (done) {
    fs.writeFileSync(__dirname + '/temp/input.jade', '.foo bar');
    fs.writeFileSync(__dirname + '/temp/input.html', '<p>output not written</p>');
    run('--no-debug --out outputs input.jade', function (err) {
      if (err) return done(err);
      var html = fs.readFileSync(__dirname + '/temp/outputs/input.html', 'utf8');
      assert(html === '<div class="foo">bar</div>');
      done();
    });
  });
  context('when input is directory', function () {
    it('jade --no-debug --out outputs inputs', function (done) {
      fs.writeFileSync(__dirname + '/temp/inputs/input.jade', '.foo bar 1');
      fs.writeFileSync(__dirname + '/temp/inputs/level-1-1/input.jade', '.foo bar 1-1');
      fs.writeFileSync(__dirname + '/temp/inputs/level-1-2/input.jade', '.foo bar 1-2');
      fs.writeFileSync(__dirname + '/temp/outputs/input.html', 'BIG FAT HEN 1');
      fs.writeFileSync(__dirname + '/temp/outputs/level-1-1/input.html', 'BIG FAT HEN 1-1');
      fs.writeFileSync(__dirname + '/temp/outputs/level-1-2/input.html', 'BIG FAT HEN 1-2');
      run('--no-debug --out outputs inputs', function (err) {
        if (err) return done(err);
        var html = fs.readFileSync(__dirname + '/temp/outputs/input.html', 'utf8');
        assert(html === '<div class="foo">bar 1</div>');
        var html = fs.readFileSync(__dirname + '/temp/outputs/level-1-1/input.html', 'utf8');
        assert(html === '<div class="foo">bar 1-1</div>');
        var html = fs.readFileSync(__dirname + '/temp/outputs/level-1-2/input.html', 'utf8');
        assert(html === '<div class="foo">bar 1-2</div>');
        done();
      });
    });
  });
});

describe('command line with client JS output', function () {
  if (isIstanbul) {
    this.timeout(8000);
    this.slow(6000);
  } else {
{'fraction_non_alphanumeric': 0.20339820211399784, 'fraction_numerical': 0.010767559024004742, 'mean_word_length': 2.993688362919132, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '4472030', 'n_tokens_mistral': 3434, 'n_tokens_neox': 3357, 'n_words': 786}