<commit_before>/* globals describe, it */
'use strict';

const assert = require('assert');
const co = require('co');
const fs = require('fs');
const path = require('path');
const tremble = require('../index');
const uuid = require('uuid');

describe('promise interface', function() {
  this.timeout(20000);
  it(
    'should clone, run a command, return 0 exit code, leave nothing behind',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      var exitCode = yield tremble({
        repository: require('../package.json').repository.url,
        branch: 'master',
        directory: dir,
        command: 'bash -c "exit 0"'
      });
      assert.equal(exitCode, 0);
      assert.throws(() => {
        fs.statSync(dir);
      }, e => (e.code === 'ENOENT'), 'Directory is still present !');
    })
  );

  it(
    'should clone, run a command, return 100 exit code, leave nothing behind',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      var exitCode = yield tremble({
        repository: require('../package.json').repository.url,
        branch: 'master',
        directory: dir,
        command: 'bash -c "exit 100"'
      });
      assert.equal(exitCode, 100);
      assert.throws(() => {
        fs.statSync(dir);
      }, e => (e.code === 'ENOENT'), 'Directory is still present !');
    })
  );

  it(
    'should clone, error, not run the command, still leave nothing behind',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      try {
        yield tremble({
          repository: require('../package.json').repository.url,
          branch: 'non-existent-branch',
          directory: dir,
          command: 'bash -c "exit 0"'
        });
      } catch (e) {
        /*
        Ok there was an error ! (No need for checking error type, the only
        difference with previous tests is the non-existent-branch.
        */
        assert.throws(() => {
          fs.statSync(dir);
        }, e => (e.code === 'ENOENT'), 'Directory is still present !');

        return;
      }

      // Assert not reached
      throw new Error('no error were raised by tremble');
    })
  );
});
<commit_msg>add test for correct working directory<commit_after>/* globals describe, it */
'use strict';

const assert = require('assert');
const co = require('co');
const fs = require('fs');
const path = require('path');
const tremble = require('../index');
const uuid = require('uuid');

describe('promise interface', function() {
  this.timeout(20000);
  it(
    'should clone, run a command, return 0 exit code, leave nothing behind',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      var exitCode = yield tremble({
        repository: require('../package.json').repository.url,
        branch: 'master',
        directory: dir,
        command: 'bash -c "exit 0"'
      });
      assert.equal(exitCode, 0);
      assert.throws(() => {
        fs.statSync(dir);
      }, e => (e.code === 'ENOENT'), 'Directory is still present !');
    })
  );

  it(
    'should clone, run a command, return 100 exit code, leave nothing behind',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      var exitCode = yield tremble({
        repository: require('../package.json').repository.url,
        branch: 'master',
        directory: dir,
        command: 'bash -c "exit 100"'
      });
      assert.equal(exitCode, 100);
      assert.throws(() => {
        fs.statSync(dir);
      }, e => (e.code === 'ENOENT'), 'Directory is still present !');
    })
  );

  it(
    'should clone, error, not run the command, still leave nothing behind',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      try {
        yield tremble({
          repository: require('../package.json').repository.url,
          branch: 'non-existent-branch',
          directory: dir,
          command: 'bash -c "exit 0"'
        });
      } catch (e) {
        /*
        Ok there was an error ! (No need for checking error type, the only
        difference with previous tests is the non-existent-branch.
        */
        assert.throws(() => {
          fs.statSync(dir);
        }, e => (e.code === 'ENOENT'), 'Directory is still present !');

        return;
      }

      // Assert not reached
      throw new Error('no error were raised by tremble');
    })
  );

  it(
    'should run the command inside the repository',
    co.wrap(function *() {
      const dir = path.join(__dirname, 'data/tmp', uuid.v4());
      var exitCode = yield tremble({
        repository: require('../package.json').repository.url,
        branch: 'master',
        directory: dir,
        command: 'bash -c "test $(pwd) = ' + dir + '"'
      });
      assert.equal(exitCode, 0);
    })
  );
});

{'fraction_non_alphanumeric': 0.1635399673735726, 'fraction_numerical': 0.00897226753670473, 'mean_word_length': 2.311951384199865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6910990', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1436, 'n_words': 423}