<commit_before>module.exports = function () {

  var execFile = require('child_process').execFile;
  var path = require('path');
  var git = require("nodegit");
  var fs = require('fs');
  var assert = require('assert')

  var helpers = require('../support/helpers');
  var normalizeText = helpers.normalizeText;
  var getAdditionalErrorText = helpers.getAdditionalErrorText;

  this.Given(/^I clone the contentascode "([^"]*)" branch$/,  {timeout: 10000}, function (branch, callback) {
    var world = this;

    var url = "https://github.com/iilab/contentascode";
    var clonePath = path.join(world.tmpDir, "proj");

    function options(){
        var nodegitOptions = {
            checkoutBranch: branch,
            fetchOpts: {
              callbacks: {
                certificateCheck: function() {
                  return 1;
              }
            }
          }
        };

        return nodegitOptions;
    }

    // Clone a given repository into a temporary folder.
    git.Clone(url, clonePath, options())
    // Look up this known commit.
    .then(function(repo) {
//      console.log(repo instanceof git.Repository);
//      console.log('hi!')
      callback();
    })
    .catch(function(err) { 
      callback(err); 
    });
  });

  this.Given(/^I run "([^"]*)"$/, {timeout: 100000}, function (command, callback) {

    var executable = command.split(' ')[0];
    command = command.split(' ').slice(1);
    var world = this;
    var cwd = path.join(world.tmpDir, "proj");

    if (!folderExists(cwd)) {
      fs.mkdirSync(cwd);
    }
    execFile(executable, command, {cwd: cwd, env: process.env}, function (error, stdout, stderr) {
       world.lastRun = {
         error:  error,
         stdout: stdout, //colors.strip(stdout),
         stderr: stderr
       };
       if (error) {
        console.log(stdout)
        console.log(stderr)
        callback(error);
       }
       callback();
     });

  });


  this.Then(/^I should( not)? see "([^"]*)"$/, function (negate, text) {
    // Write code here that turns the phrase above into concrete actions
    assert.equal(this.lastRun.stdout.indexOf(text) > -1, !negate, 
        'Expected output to contain the following:\n' + text + '\n' +
        'Got:\n' + normalizeText(this.lastRun.stdout) + '\n' +
        getAdditionalErrorText(this.lastRun));

  });

  // this.Then(/^I run "([^"]*)" I should( not)? see "([^"]*)"$/, {timeout: 5000}, function (command, negate, output, callback) {

  //   var executable = command.split(' ')[0];
  //   command = command.split(' ').slice(1);
  //   var world = this;
  //   var cwd = path.join(world.tmpDir, "proj");

  //   if (!folderExists(cwd)) {
  //     fs.mkdirSync(cwd);
  //   }

  //   execFile(executable, command, {cwd: cwd, env: process.env}, function (error, stdout, stderr) {
  //      world.lastRun = {
  //        error:  error,
  //        stdout: stdout, //colors.strip(stdout),
  //        stderr: stderr
  //      };
  //      if (error) {
  //       console.log(stdout)
  //       console.log(stderr)
  //       callback(error);
  //      }
  //      assert.equal(stdout.indexOf(output) > -1, !negate);
  //      callback();
  //    });

  // });

  this.Then(/^I should( not)? have a "([^"]*)" file$/, function (negate, file) {
    assert.equal(fileExists(path.join(this.tmpDir, "proj", file)), !negate);
  });

  this.Then(/^I should( not)? have a "([^"]*)" folder$/, function (negate, file) {
    assert.equal(folderExists(path.join(this.tmpDir, "proj", file)), !negate,
        'Expected folder to ' + negate ? 'not exist' : 'exit' + '\n' +
        getAdditionalErrorText(this.lastRun));
  });

  this.Then(/^I should have a "([^"]*)" file with(out)? "([^"]*)"$/, function (file, negate, text, callback) {
    // Write code here that turns the phrase above into concrete actions
    var world = this;
    var cwd = path.join(world.tmpDir, "repo");
    var absoluteFilePath = path.join(world.tmpDir, "proj", file);
    fs.readFile(absoluteFilePath, 'utf8', function (err, content){
      if (err) { return callback(err); }

      var fileContent = normalizeText(content);
      expectedContent = normalizeText(text);

      assert.equal(fileContent.indexOf(expectedContent) > -1, !negate);
      callback();
    });<commit_msg>Fixing error message string formatting<commit_after>module.exports = function () {

  var execFile = require('child_process').execFile;
  var path = require('path');
  var git = require("nodegit");
  var fs = require('fs');
  var assert = require('assert')

  var helpers = require('../support/helpers');
  var normalizeText = helpers.normalizeText;
  var getAdditionalErrorText = helpers.getAdditionalErrorText;

  this.Given(/^I clone the contentascode "([^"]*)" branch$/,  {timeout: 10000}, function (branch, callback) {
    var world = this;

    var url = "https://github.com/iilab/contentascode";
    var clonePath = path.join(world.tmpDir, "proj");

    function options(){
        var nodegitOptions = {
            checkoutBranch: branch,
            fetchOpts: {
              callbacks: {
                certificateCheck: function() {
                  return 1;
              }
            }
          }
        };

        return nodegitOptions;
    }

    // Clone a given repository into a temporary folder.
    git.Clone(url, clonePath, options())
    // Look up this known commit.
    .then(function(repo) {
//      console.log(repo instanceof git.Repository);
//      console.log('hi!')
      callback();
    })
    .catch(function(err) { 
      callback(err); 
    });
  });

  this.Given(/^I run "([^"]*)"$/, {timeout: 100000}, function (command, callback) {

    var executable = command.split(' ')[0];
    command = command.split(' ').slice(1);
    var world = this;
    var cwd = path.join(world.tmpDir, "proj");

    if (!folderExists(cwd)) {
      fs.mkdirSync(cwd);
    }
    execFile(executable, command, {cwd: cwd, env: process.env}, function (error, stdout, stderr) {
       world.lastRun = {
         error:  error,
         stdout: stdout, //colors.strip(stdout),
         stderr: stderr
       };
       if (error) {
        console.log(stdout)
        console.log(stderr)
        callback(error);
       }
       callback();
     });

  });

  this.Then(/^I should( not)? see "([^"]*)"$/, function (negate, text) {
    // Write code here that turns the phrase above into concrete actions
    assert.equal(this.lastRun.stdout.indexOf(text) > -1, !negate, 
        'Expected output to contain the following:\n' + text + '\n' +
        'Got:\n' + normalizeText(this.lastRun.stdout) + '\n' +
        getAdditionalErrorText(this.lastRun));

  });

  this.Then(/^I should( not)? have a "([^"]*)" file$/, function (negate, file) {
    assert.equal(fileExists(path.join(this.tmpDir, "proj", file)), !negate);
  });

  this.Then(/^I should( not)? have a "([^"]*)" folder$/, function (negate, file) {
    assert.equal(folderExists(path.join(this.tmpDir, "proj", file)), !negate,
        'Expected folder ' + file + ' to ' + ( negate ? 'not exist' : 'exit' ) + '\n' + 
        getAdditionalErrorText(this.lastRun));
  });

  this.Then(/^I should have a "([^"]*)" file with(out)? "([^"]*)"$/, function (file, negate, text, callback) {
    // Write code here that turns the phrase above into concrete actions
    var world = this;
    var cwd = path.join(world.tmpDir, "repo");
    var absoluteFilePath = path.join(world.tmpDir, "proj", file);
    fs.readFile(absoluteFilePath, 'utf8', function (err, content){
      if (err) { return callback(err); }

      var fileContent = normalizeText(content);
      expectedContent = normalizeText(text);

      assert.equal(fileContent.indexOf(expectedContent) > -1, !negate);
      callback();
    });
{'fraction_non_alphanumeric': 0.17041343669250647, 'fraction_numerical': 0.005297157622739018, 'mean_word_length': 2.552547039926572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '812600', 'n_tokens_mistral': 2520, 'n_tokens_neox': 2386, 'n_words': 566}