<commit_before>/// <reference path="../../typings/all.d.ts" />
require('source-map-support').install();

import chai = require('chai');
import spawn = require('child_process');
import tmp = require('tmp');
import path = require('path');
import ncp = require('ncp');
import fs = require('fs');

const BIN = path.join(__dirname, '../../../bin/tagit');

const assert = chai.assert;

function run(args = [], cb:Function = null) {
    var process = spawn.spawn(BIN, [].concat(args));
    var stdout = '', stderr = '';
    process.stdout.on('data', function (data) {
        stdout += data.toString();
    });
    process.stderr.on('data', function (data) {
        stderr += data.toString();
    });

    process.on('close', function (code) {
        if (typeof cb == 'function') {
            return cb(null, code, stdout, stderr);
        }
    });
}

describe("when not yet initialized", function () {
    var workDir;
    var cleanupWorkDir;

    beforeEach(function (done) {
        tmp.dir({unsafeCleanup: true}, function (err, path, cleanupCallback) {
            if (err) throw err;
            workDir = path;
            cleanupWorkDir = cleanupCallback;
            process.chdir(workDir);
            done();
        });
    });

    afterEach(function () {
        cleanupWorkDir();
    });

    it('should print help when no args', function (done) {
        run([], function (err, code, stdout) {
            assert.include(stdout, 'Usage');
            assert.include(stdout, 'Commands');
            assert.include(stdout, 'Options');
            done();
        });
    });

    it('should create file structore on init', function (done) {
        run(['init', workDir], function () {
            fs.stat(path.join(workDir, '.tagit'), function (err, stat) {
                if (err) throw err;
                assert.isTrue(stat.isDirectory());
                fs.stat(path.join(workDir, '.tagit/data.json'), function (err, stat) {
                    assert.isTrue(stat.isFile());
                    done();
                });
            });
        })
    });

    describe("when initialized", function () {
        beforeEach(function (done) {
            ncp.ncp(path.join(__dirname, '../../../src/test/fixtures'), workDir, function (err) {
                if (err) throw err;
                run(['init', workDir], done);
            });
        });

        it('should fail to init already initialized directories', function (done) {
            run(['init', workDir], function (err, code, stdout) {
                assert.notEqual(code, 0);
                done();
            });
        });

        it('shouldn\'t list any tag', function (done) {
            run(['tags'], function (err, code, stdout) {
                assert.equal(stdout, '');
                assert.equal(code, 0);<commit_msg>Remove unnecesary newline, cleanup warnings<commit_after>/// <reference path="../../typings/all.d.ts" />
require('source-map-support').install();

import chai = require('chai');
import spawn = require('child_process');
import tmp = require('tmp');
import path = require('path');
import ncp = require('ncp');
import fs = require('fs');

const BIN = path.join(__dirname, '../../../bin/tagit');
const assert = chai.assert;

function run(args = [], cb:Function = null) {
    var process = spawn.spawn(BIN, [].concat(args));
    var stdout = '', stderr = '';
    process.stdout.on('data', function (data) {
        stdout += data.toString();
    });
    process.stderr.on('data', function (data) {
        stderr += data.toString();
    });

    process.on('close', function (code) {
        if (typeof cb == 'function') {
            return cb(null, code, stdout, stderr);
        }
    });
}

describe("when not yet initialized", function () {
    var workDir;
    var cleanupWorkDir;

    beforeEach(function (done) {
        tmp.dir({unsafeCleanup: true}, function (err, path, cleanupCallback) {
            if (err) throw err;
            workDir = path;
            cleanupWorkDir = cleanupCallback;
            process.chdir(workDir);
            done();
        });
    });

    afterEach(function () {
        cleanupWorkDir();
    });

    it('should print help when no args', function (done) {
        run([], function (err, code, stdout) {
            assert.include(stdout, 'Usage');
            assert.include(stdout, 'Commands');
            assert.include(stdout, 'Options');
            done();
        });
    });

    it('should create file structore on init', function (done) {
        run(['init', workDir], function () {
            fs.stat(path.join(workDir, '.tagit'), function (err, stat) {
                if (err) throw err;
                assert.isTrue(stat.isDirectory());
                fs.stat(path.join(workDir, '.tagit/data.json'), function (err, stat) {
                    assert.isTrue(stat.isFile());
                    done();
                });
            });
        })
    });

    describe("when initialized", function () {
        beforeEach(function (done) {
            ncp.ncp(path.join(__dirname, '../../../src/test/fixtures'), workDir, function (err) {
                if (err) throw err;
                run(['init', workDir], done);
            });
        });

        it('should fail to init already initialized directories', function (done) {
            run(['init', workDir], function (err, code) {
                assert.notEqual(code, 0);
                done();
            });
        });

        it('shouldn\'t list any tag', function (done) {
            run(['tags'], function (err, code, stdout) {
                assert.equal(stdout, '');
                assert.equal(code, 0);
{'fraction_non_alphanumeric': 0.16740243687091647, 'fraction_numerical': 0.0007063393960798164, 'mean_word_length': 1.9889182058047494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4911614', 'n_tokens_mistral': 1602, 'n_tokens_neox': 1553, 'n_words': 378}