<commit_before>/* jshint node:true, mocha:true, expr:true */
/**
 * @author kecso / https://github.com/kecso
 */

var testFixture = require('../_globals.js'),
    gmeConfig = testFixture.getGmeConfig();

describe('merge CLI test', function () {
    'use strict';
    var filename = require('path').normalize('src/bin/merge.js'),
        mergeCli = require('../../src/bin/merge'),
        applyCLI = require('../../src/bin/apply'),
        logger = testFixture.logger.fork('merge.CLI'),
        database,
        projectName = 'mergeCliTest',
        oldProcessExit = process.exit,
        oldConsoleLog = console.log,
        oldConsoleError = console.error,
        oldProcessStdoutWrite = process.stdout.write,
        oldConsoleWarn = console.warn,
        suppressLogAndExit = function (saveBuffer) {
            process.exit = function (code) {
                // TODO: would be nice to send notifications for test
                if (saveBuffer) {
                    saveBuffer.code = code;
                }
            };
            console.log = function () {
                //oldConsoleLog(args);
                var i;
                if (saveBuffer) {
                    saveBuffer.log = saveBuffer.log || '';
                    for (i = 0; i < arguments.length; i++) {
                        saveBuffer.log += arguments[i] + ' ';
                    }
                    saveBuffer.log += '\n';
                }
            };
            console.error = function () {
                //oldConsoleError(args);
                var i;
                if (saveBuffer) {
                    saveBuffer.error = saveBuffer.error || '';
                    for (i = 0; i < arguments.length; i++) {
                        saveBuffer.error += arguments[i] + ' ';
                    }
                    saveBuffer.error += '\n';
                }
            };
            console.warn = console.error;
            process.stdout.write = function () {
                var i;
                if (saveBuffer) {
                    saveBuffer.log = saveBuffer.log || '';
                    for (i = 0; i < arguments.length; i++) {
                        saveBuffer.log += arguments[i] + ' ';
                    }
                    saveBuffer.log += '\n';
                }
            };
        },
        restoreLogAndExit = function () {
            console.log = oldConsoleLog;
            console.error = oldConsoleError;
            console.warn = oldConsoleWarn;
            process.stdout.write = oldProcessStdoutWrite;
            process.exit = oldProcessExit;
        },
        addTest = function (parameters) {
            it(parameters.id, function (done) {
                var buffer = {log: '', error: '', code: 0};
                suppressLogAndExit(buffer);
                mergeCli.main(['node', filename, parameters.params])
                    .then(function () {
                        restoreLogAndExit();
                        buffer.code.should.be.eql(parameters.code || 0);
                        buffer.error.should.be.empty;
                        if (parameters.out) {
                            buffer.log.should.contain(parameters.out);
                        }
                        done();
                    })
                    .catch(function (err) {
                        restoreLogAndExit();
                        if (err instanceof SyntaxError) {
                            done();
                        } else {
                            done(err);
                        }
                    });
            });
        };
    before(function (done) {
        var oldDone = done;

        testFixture.clearDBAndGetGMEAuth(gmeConfig, ['PluginManagerBase', projectName])
            .then(function (gmeAuth_) {
                var gmeAuth;
                gmeAuth = gmeAuth_;
                database = testFixture.getMongoStorage(logger, gmeConfig, gmeAuth);
                database.openDatabase(function (err) {
                    if (err) {
                        done(err);
                        return;
                    }

                    done = function (error) {
                        database.closeDatabase(function (err) {
                            oldDone(error || err);
                        });
                    };
                    database.deleteProject({projectName: projectName}, function (err) {
                        if (err) {
                            done(err);
                            return;
                        }

                        testFixture.openContext(database, gmeConfig, logger, {
                                projectName: projectName,
                                branchName: 'master',
                                createProject: true,
                                projectSeed: './test/bin/merge/base.json'
                            }, function (err, result) {
                                if (err) {
                                    done(err);
                                    return;
                                }
                                console.log(err, result);
                                result.project.createBranch('other', result.commitHash, function (err) {<commit_msg>#370 remove extra log in tests<commit_after>/* jshint node:true, mocha:true, expr:true */
/**
 * @author kecso / https://github.com/kecso
 */

var testFixture = require('../_globals.js'),
    gmeConfig = testFixture.getGmeConfig();

describe('merge CLI test', function () {
    'use strict';
    var filename = require('path').normalize('src/bin/merge.js'),
        mergeCli = require('../../src/bin/merge'),
        applyCLI = require('../../src/bin/apply'),
        logger = testFixture.logger.fork('merge.CLI'),
        database,
        projectName = 'mergeCliTest',
        oldProcessExit = process.exit,
        oldConsoleLog = console.log,
        oldConsoleError = console.error,
        oldProcessStdoutWrite = process.stdout.write,
        oldConsoleWarn = console.warn,
        suppressLogAndExit = function (saveBuffer) {
            process.exit = function (code) {
                // TODO: would be nice to send notifications for test
                if (saveBuffer) {
                    saveBuffer.code = code;
                }
            };
            console.log = function () {
                //oldConsoleLog(args);
                var i;
                if (saveBuffer) {
                    saveBuffer.log = saveBuffer.log || '';
                    for (i = 0; i < arguments.length; i++) {
                        saveBuffer.log += arguments[i] + ' ';
                    }
                    saveBuffer.log += '\n';
                }
            };
            console.error = function () {
                //oldConsoleError(args);
                var i;
                if (saveBuffer) {
                    saveBuffer.error = saveBuffer.error || '';
                    for (i = 0; i < arguments.length; i++) {
                        saveBuffer.error += arguments[i] + ' ';
                    }
                    saveBuffer.error += '\n';
                }
            };
            console.warn = console.error;
            process.stdout.write = function () {
                var i;
                if (saveBuffer) {
                    saveBuffer.log = saveBuffer.log || '';
                    for (i = 0; i < arguments.length; i++) {
                        saveBuffer.log += arguments[i] + ' ';
                    }
                    saveBuffer.log += '\n';
                }
            };
        },
        restoreLogAndExit = function () {
            console.log = oldConsoleLog;
            console.error = oldConsoleError;
            console.warn = oldConsoleWarn;
            process.stdout.write = oldProcessStdoutWrite;
            process.exit = oldProcessExit;
        },
        addTest = function (parameters) {
            it(parameters.id, function (done) {
                var buffer = {log: '', error: '', code: 0};
                suppressLogAndExit(buffer);
                mergeCli.main(['node', filename, parameters.params])
                    .then(function () {
                        restoreLogAndExit();
                        buffer.code.should.be.eql(parameters.code || 0);
                        buffer.error.should.be.empty;
                        if (parameters.out) {
                            buffer.log.should.contain(parameters.out);
                        }
                        done();
                    })
                    .catch(function (err) {
                        restoreLogAndExit();
                        if (err instanceof SyntaxError) {
                            done();
                        } else {
                            done(err);
                        }
                    });
            });
        };
    before(function (done) {
        var oldDone = done;

        testFixture.clearDBAndGetGMEAuth(gmeConfig, ['PluginManagerBase', projectName])
            .then(function (gmeAuth_) {
                var gmeAuth;
                gmeAuth = gmeAuth_;
                database = testFixture.getMongoStorage(logger, gmeConfig, gmeAuth);
                database.openDatabase(function (err) {
                    if (err) {
                        done(err);
                        return;
                    }

                    done = function (error) {
                        database.closeDatabase(function (err) {
                            oldDone(error || err);
                        });
                    };
                    database.deleteProject({projectName: projectName}, function (err) {
                        if (err) {
                            done(err);
                            return;
                        }

                        testFixture.openContext(database, gmeConfig, logger, {
                                projectName: projectName,
                                branchName: 'master',
                                createProject: true,
                                projectSeed: './test/bin/merge/base.json'
                            }, function (err, result) {
                                if (err) {
                                    done(err);
                                    return;
                                }
                                result.project.createBranch('other', result.commitHash, function (err) {
{'fraction_non_alphanumeric': 0.10612555968371916, 'fraction_numerical': 0.001238449080689721, 'mean_word_length': 1.0061150391744698, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1270279', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2367, 'n_words': 459}