<commit_before>/*
 * Copyright 2012 <NAME>.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var TestCampaign = require('./test-campaign/campaign.js');
var TestServer = require('./test-server/server.js');
var optimist = require('optimist');
var fs = require('fs');
var yaml = require('js-yaml');
var Logger = require('./logging/logger.js');
var ConsoleLogger = require('./logging/console-logger.js');
var ConsoleReport = require('./reports/console-report.js');
var JsonConsole = require('./reports/json-console.js');
var JsonReport = require('./reports/json-report.js');
var JsonLogReport = require('./reports/json-log-report.js');
var colors = require('colors');
var writeReports = require('./reports/write-reports.js');
var merge = require('./merge.js');
var childProcesses = require('./child-processes');
var exitProcess = require('./exit-process.js');

var readConfigFile = function (configFile, logger) {
    var configFileContent;
    try {
        configFileContent = fs.readFileSync(configFile, "utf8");
    } catch (e) {
        logger.logError("Error while opening the configuration file: %s", [e]);
        return false;
    }
    try {
        return (/\.ya?ml$/i).test(configFile) ? yaml.load(configFileContent) : JSON.parse(configFileContent);
    } catch (e) {
        logger.logError("Unable to parse configuration file %s : %s", [configFile, e]);
        return false;
    }
};

var run = function () {
    var opt = optimist.usage('Usage: $0 [options] [config.yml|config.json]').boolean(['json-console', 'help', 'server-only', 'version', 'colors', 'ignore-errors', 'ignore-failures']).string(['phantomjs-path']).describe({
        'log-level': 'Level of logging: integer from 0 (no logging) to 4 (debug).',
        'port': 'Port used for the web server. If set to 0, an available port is automatically selected.',
        'json-console': 'When enabled, JSON objects will be sent to stdout to provide information about tests.',
        'heartbeats': 'Delay (in ms) for heartbeats messages sent when --json-console is enabled. Use 0 to disable them.',
        'server-only': 'Only starts the web server, and configure it for the test campaign but do not start the campaign.',
        'phantomjs-instances': 'Number of instances of PhantomJS to start.',
        'phantomjs-path': 'Path to PhantomJS executable.',
        'browser': 'Path to any browser executable to execute the tests. Can be repeated multiple times.',
        'ignore-errors': 'When enabled, test errors (not including failures) will not cause this process to return a non-zero value.',
        'ignore-failures': 'When enabled, test failures (anticipated errors) will not cause this process to return a non-zero value.',
        'help': 'Displays this help message and exits.',
        'colors': 'Uses colors (disable with --no-colors).',
        'version': 'Displays the version number and exits.'
    }).alias({
        'j': 'json-console',
        'p': 'port'
    })['default']({
        'heartbeats': 2000,
        'port': 0,
        'log-level': 3,
        'colors': true,
        'phantomjs-instances': 0,<commit_msg>Configurable number of PhantomJS instances from the includer's package.json<commit_after>/*
 * Copyright 2012 Amadeus s.a.s.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var TestCampaign = require('./test-campaign/campaign.js');
var TestServer = require('./test-server/server.js');
var optimist = require('optimist');
var fs = require('fs');
var yaml = require('js-yaml');
var Logger = require('./logging/logger.js');
var ConsoleLogger = require('./logging/console-logger.js');
var ConsoleReport = require('./reports/console-report.js');
var JsonConsole = require('./reports/json-console.js');
var JsonReport = require('./reports/json-report.js');
var JsonLogReport = require('./reports/json-log-report.js');
var colors = require('colors');
var writeReports = require('./reports/write-reports.js');
var merge = require('./merge.js');
var childProcesses = require('./child-processes');
var exitProcess = require('./exit-process.js');

var readConfigFile = function (configFile, logger) {
    var configFileContent;
    try {
        configFileContent = fs.readFileSync(configFile, "utf8");
    } catch (e) {
        logger.logError("Error while opening the configuration file: %s", [e]);
        return false;
    }
    try {
        return (/\.ya?ml$/i).test(configFile) ? yaml.load(configFileContent) : JSON.parse(configFileContent);
    } catch (e) {
        logger.logError("Unable to parse configuration file %s : %s", [configFile, e]);
        return false;
    }
};

var run = function () {
    var opt = optimist.usage('Usage: $0 [options] [config.yml|config.json]').boolean(['json-console', 'help', 'server-only', 'version', 'colors', 'ignore-errors', 'ignore-failures']).string(['phantomjs-path']).describe({
        'log-level': 'Level of logging: integer from 0 (no logging) to 4 (debug).',
        'port': 'Port used for the web server. If set to 0, an available port is automatically selected.',
        'json-console': 'When enabled, JSON objects will be sent to stdout to provide information about tests.',
        'heartbeats': 'Delay (in ms) for heartbeats messages sent when --json-console is enabled. Use 0 to disable them.',
        'server-only': 'Only starts the web server, and configure it for the test campaign but do not start the campaign.',
        'phantomjs-instances': 'Number of instances of PhantomJS to start.',
        'phantomjs-path': 'Path to PhantomJS executable.',
        'browser': 'Path to any browser executable to execute the tests. Can be repeated multiple times.',
        'ignore-errors': 'When enabled, test errors (not including failures) will not cause this process to return a non-zero value.',
        'ignore-failures': 'When enabled, test failures (anticipated errors) will not cause this process to return a non-zero value.',
        'help': 'Displays this help message and exits.',
        'colors': 'Uses colors (disable with --no-colors).',
        'version': 'Displays the version number and exits.'
    }).alias({
        'j': 'json-console',
        'p': 'port'
    })['default']({
        'heartbeats': 2000,
        'port': 0,
        'log-level': 3,
        'colors': true,
        'phantomjs-instances': process.env.npm_package_config_phantomjsInstances || 0,
{'fraction_non_alphanumeric': 0.13784665579119088, 'fraction_numerical': 0.005709624796084829, 'mean_word_length': 3.516267648864334, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7092854', 'n_tokens_mistral': 2069, 'n_tokens_neox': 1986, 'n_words': 739}