UNPKG

@syntest/core

Version:

The common core of the SynTest Framework

462 lines 16.7 kB
"use strict"; /* * Copyright 2020-2023 Delft University of Technology and SynTest contributors * * This file is part of SynTest Framework - SynTest Core. * * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Configuration = exports.CONFIG = void 0; const Yargs = require("yargs"); const path = require("path"); const shell = require("shelljs"); class Configuration { initialize(argumentValues) { if (exports.CONFIG) { throw Error("Already initialized the config singleton!"); } exports.CONFIG = argumentValues; } loadFile(cwd) { cwd = cwd || process.env.SYNTEST_CWD || process.cwd(); const configPath = path.join(cwd, ".syntest.js"); let config; // Catch syntestjs syntax errors if (shell.test("-e", configPath)) { try { config = require(configPath); } catch (error) { throw new Error(error); } // Config is optional } else { config = {}; } return config; } processArguments(yargs, args) { const config = this.loadFile(); const configuredArgs = yargs.config(config); return configuredArgs.wrap(configuredArgs.terminalWidth()).parseSync(args); } configureOptions(programName) { const yargs = Yargs.usage(`Usage: ${programName} [options]`) .example(`${programName} -r ./src`, "Running the tool with target directory 'src'") .example(`${programName} -r ./src --population_size 10`, "Setting the population size") .epilog("visit https://syntest.org for more documentation"); // Here we chain all the configure functions to create a single options object that contains everything. const options1 = this.configureGeneralOptions(yargs); const options2 = this.configureTargetOptions(options1); const options3 = this.configureStorageOptions(options2); const options4 = this.configureAlgorithmOptions(options3); const options5 = this.configureBudgetOptions(options4); const options6 = this.configureLoggingOptions(options5); const options7 = this.configurePostProcessingOptions(options6); const options8 = this.configureSamplingOptions(options7); const options9 = this.configureResearchModeOptions(options8); // In case there are hidden options we hide them from the help menu. return options9.showHidden(false); } configureGeneralOptions(yargs) { return (yargs // plugins .option("plugins", { alias: ["p"], array: true, default: [], description: "List of dependencies or paths to plugins to load", group: "General options:", hidden: false, type: "string", }) // ui .option("user-interface", { alias: [], default: "regular", description: "The user interface you use", group: "General options:", hidden: false, type: "string", })); } configureTargetOptions(yargs) { return yargs.options({ // Files "target-root-directory": { alias: ["r"], demandOption: true, description: "The root directory where all targets are in", group: "File options:", hidden: false, normalize: true, type: "string", }, include: { alias: ["i"], default: ["./src/**/*.*"], description: "Files/Directories to include", group: "File options:", hidden: false, normalize: true, type: "array", }, exclude: { alias: ["e"], default: [], description: "Files/Directories to exclude", group: "File options:", hidden: false, normalize: true, type: "array", }, }); } configureStorageOptions(yargs) { return yargs.options({ // directories "statistics-directory": { alias: [], default: "syntest/statistics", description: "The path where the csv should be saved", group: "Directory options:", hidden: false, normalize: true, type: "string", }, "log-directory": { alias: [], default: "syntest/logs", description: "The path where the logs should be saved", group: "Directory options:", hidden: false, normalize: true, type: "string", }, "final-suite-directory": { alias: [], default: "syntest/tests", description: "The path where the final test suite should be saved", group: "Directory options:", hidden: false, normalize: true, type: "string", }, "temp-test-directory": { alias: [], default: ".syntest/tests", description: "Path to the temporary test directory", group: "Directory options:", hidden: false, normalize: true, type: "string", }, "temp-log-directory": { alias: [], default: ".syntest/logs", description: "Path to the temporary log directory", group: "Directory options:", hidden: false, normalize: true, type: "string", }, "temp-instrumented-directory": { alias: [], default: ".syntest/instrumented", description: "Path to the temporary instrumented directory", group: "Directory options:", hidden: false, normalize: true, type: "string", }, }); } configureAlgorithmOptions(yargs) { return (yargs // algorithm settings .options({ algorithm: { alias: ["a"], default: "DynaMOSA", description: "Algorithm to be used by the tool.", group: "Algorithm options:", hidden: false, type: "string", }, "population-size": { alias: [], default: 50, description: "Size of the population.", group: "Algorithm options:", hidden: false, type: "number", }, crossover: { alias: [], default: "", description: "Crossover operator to be used by the tool.", group: "Algorithm options:", hidden: false, type: "string", }, sampler: { alias: [], default: "random", description: "Sampler to be used by the tool.", group: "Algorithm options:", hidden: false, type: "string", }, "termination-triggers": { alias: [], default: ["signal"], description: "Termination trigger to be used by the tool.", group: "Algorithm options:", hidden: false, type: "string", }, })); } configureBudgetOptions(yargs) { return (yargs // time settings .options({ "total-time-budget": { alias: ["t"], default: 3600, description: "Total time budget", group: "Budget options:", hidden: false, type: "number", }, "search-time-budget": { alias: [], default: 3600, description: "Search time budget", group: "Budget options:", hidden: false, type: "number", }, "iteration-budget": { alias: ["b"], default: Number.MAX_SAFE_INTEGER, description: "Iteration budget", group: "Budget options:", hidden: false, type: "number", }, "evaluation-budget": { alias: [], default: Number.MAX_SAFE_INTEGER, description: "Evaluation budget", group: "Budget options:", hidden: false, type: "number", }, })); } configureLoggingOptions(yargs) { return (yargs // logging .options({ "console-log-level": { alias: [], choices: ["debug", "error", "warn", "info", "verbose", "silly"], default: "debug", description: "Log level of the tool", group: "Logging options:", hidden: false, type: "string", }, "log-to-file": { alias: [], default: ["info", "warn", "error"], description: "Which levels should be logged to file", group: "Logging options:", hidden: false, type: "array", }, })); } configurePostProcessingOptions(yargs) { return (yargs // post processing .options({ "test-minimization": { alias: [], default: false, description: "Minimize test cases at the end of the search", group: "Postprocess options:", hidden: false, type: "boolean", }, })); } configureSamplingOptions(yargs) { return (yargs // random number generator settings .options({ seed: { alias: ["s"], default: null, description: "Seed to be used by the pseudo random number generator.", group: "Sampling options:", hidden: false, type: "string", }, // sampling settings "max-depth": { alias: [], default: 5, description: "Max depth of an individual's gene tree.", group: "Sampling options:", hidden: false, type: "number", }, "max-action-statements": { alias: [], default: 5, description: "Max number of top level action statements in an individual's gene tree.", group: "Sampling options:", hidden: false, type: "number", }, "constant-pool": { alias: [], default: false, description: "Enable constant pool.", group: "Sampling options:", hidden: false, type: "boolean", }, // mutation settings "explore-illegal-values": { alias: [], default: false, description: "Allow primitives to become values outside of the specified bounds.", group: "Sampling options:", hidden: false, type: "boolean", }, // probability settings "resample-gene-probability": { alias: [], default: 0.01, description: "Probability a gene gets resampled from scratch.", group: "Sampling options:", hidden: false, type: "number", }, "delta-mutation-probability": { alias: [], default: 0.8, description: "Probability a delta mutation is performed.", group: "Sampling options:", hidden: false, type: "number", }, "sample-existing-value-probability": { alias: [], default: 0.5, description: "Probability the return value of a function is used as argument for another function.", group: "Sampling options:", hidden: false, type: "number", }, "crossover-probability": { alias: [], default: 0.8, description: "Probability crossover happens at a certain branch point.", group: "Sampling options:", hidden: false, type: "number", }, "constant-pool-probability": { alias: [], default: 0.5, description: "Probability to sample from the constant pool instead creating random values", group: "Sampling options:", hidden: false, type: "number", }, "sample-function-output-as-argument": { alias: [], default: 0.5, description: "Probability to sample the output of a function as an argument.", group: "Sampling options:", hidden: false, type: "number", }, // gene defaults "string-alphabet": { alias: [], default: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", description: "The alphabet to be used by the string gene.", group: "Sampling options:", hidden: false, type: "string", }, "string-max-length": { alias: [], default: 100, description: "Maximal length of the string gene.", group: "Sampling options:", hidden: false, type: "number", }, "numeric-max-value": { alias: [], default: Number.MAX_SAFE_INTEGER, description: "Max value used by the numeric gene.", group: "Sampling options:", hidden: false, type: "number", }, })); } configureResearchModeOptions(yargs) { return (yargs // Research mode options // TODO should be moved to research mode plugin .options({ configuration: { alias: [], default: "", description: "The name of the configuration.", group: "Research mode options:", hidden: false, type: "string", }, "output-properties": { alias: [], default: [ "timestamp", "targetName", "coveredBranches", "totalBranches", "fitnessEvaluations", ], description: "The values that should be written to csv", group: "Research mode options:", hidden: false, type: "array", }, })); } } exports.Configuration = Configuration; const configured = new Configuration().configureOptions(""); const parsed = configured.parseSync(["-r", "./src"]); //# sourceMappingURL=Configuration.js.map