Skip to content

Commit

Permalink
feat: make objectives types configurable (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstallenberg committed Dec 11, 2023
1 parent e42987c commit 7330730
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 38 deletions.
107 changes: 71 additions & 36 deletions tools/javascript/lib/JavaScriptLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,18 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
`${timeInMs}`
);

if (this.targets.length === 0) {
// Shut server down
this.userInterface.printError(
`No targets where selected! Try changing the 'target-include' parameter`
);
await this.exit();
// eslint-disable-next-line unicorn/no-process-exit
process.exit();
}
const selectionSettings: TableObject = {
headers: ["Setting", "Value"],
rows: [
["Target Root Directory", this.arguments_.targetRootDirectory],
["Target Include", `${this.arguments_.targetInclude.join(", ")}`],
["Target Exclude", `${this.arguments_.targetExclude.join(", ")}`],
["Analysis Include", `${this.arguments_.analysisInclude.join(", ")}`],
["Analysis Exclude", `${this.arguments_.analysisExclude.join(", ")}`],
],
};

this.userInterface.printTable("SELECTION SETTINGS", selectionSettings);

const itemization: ItemizationItem[] = [];

Expand All @@ -263,20 +266,17 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
}),
});
}

this.userInterface.printItemization("TARGETS", itemization);

const selectionSettings: TableObject = {
headers: ["Setting", "Value"],
rows: [
["Target Root Directory", this.arguments_.targetRootDirectory],
["Target Include", `${this.arguments_.targetInclude.join(", ")}`],
["Target Exclude", `${this.arguments_.targetExclude.join(", ")}`],
["Analysis Include", `${this.arguments_.analysisInclude.join(", ")}`],
["Analysis Exclude", `${this.arguments_.analysisExclude.join(", ")}`],
],
};
this.userInterface.printTable("SELECTION SETTINGS", selectionSettings);
if (this.targets.length === 0) {
// Shut down
this.userInterface.printError(
`No targets where selected! Try changing the 'target-include' parameter`
);
await this.exit();
// eslint-disable-next-line unicorn/no-process-exit
process.exit();
}

const settings: TableObject = {
headers: ["Setting", "Value"],
Expand Down Expand Up @@ -461,6 +461,7 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
(p, c) => p + c.length,
0
);

JavaScriptLauncher.LOGGER.info("Splitting started");
finalEncodings = await testSplitter.execute(finalEncodings);

Expand Down Expand Up @@ -513,7 +514,6 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
0
);
JavaScriptLauncher.LOGGER.info("De-Duplication started");

finalEncodings = await deDuplicator.execute(finalEncodings);

const timeInMs = (Date.now() - start) / 1000;
Expand All @@ -536,6 +536,7 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
secondaryObjectives,
objectives
);

const start = Date.now();
JavaScriptLauncher.LOGGER.info("Meta-Commenting started");
finalEncodings = await metaCommenter.execute(finalEncodings);
Expand Down Expand Up @@ -567,6 +568,7 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
this.storageManager.clearTemporaryDirectory([
this.arguments_.testDirectory,
]);

// get final results
paths = suiteBuilder.createSuite(
finalEncodings,
Expand All @@ -576,7 +578,6 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
false,
false
);

const results = await suiteBuilder.runSuite(finalEncodings, paths, false);
const summaryTotal = suiteBuilder.summariseResults(results, this.targets);
if (summaryTotal.failures > 0) {
Expand All @@ -590,6 +591,7 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {
rows: [],
footers: ["Average"],
};

let coveredStatements = 0;
let coveredBranches = 0;
let coveredFunctions = 0;
Expand Down Expand Up @@ -724,40 +726,73 @@ export class JavaScriptLauncher extends Launcher<JavaScriptArguments> {

const cfp = unwrap(result);

const functionObjectives =
extractFunctionObjectivesFromProgram<JavaScriptTestCase>(cfp);

const branchObjectives =
extractBranchObjectivesFromProgram<JavaScriptTestCase>(
cfp,
new ApproachLevelCalculator(),
new BranchDistanceCalculator(
this.arguments_.syntaxForgiving,
this.arguments_.stringAlphabet
)
),
this.arguments_.functionObjectivesEnabled
? functionObjectives
: undefined
);
const pathObjectives = extractPathObjectivesFromProgram<JavaScriptTestCase>(
cfp,
new ApproachLevelCalculator(),
new BranchDistanceCalculator(
this.arguments_.syntaxForgiving,
this.arguments_.stringAlphabet
)
),
this.arguments_.functionObjectivesEnabled ? functionObjectives : undefined
);
const functionObjectives =
extractFunctionObjectivesFromProgram<JavaScriptTestCase>(cfp);

this.userInterface.printTable("Objective Counts", {
headers: ["Type", "Count"],
headers: ["Type", "Count", "Enabled"],
rows: [
["branch", `${branchObjectives.length}`],
["path", `${pathObjectives.length}`],
["function", `${functionObjectives.length}`],
[
"function",
`${functionObjectives.length}`,
String(this.arguments_.functionObjectivesEnabled),
],
[
"branch",
`${branchObjectives.length}`,
String(this.arguments_.branchObjectivesEnabled),
],
[
"path",
`${pathObjectives.length}`,
String(this.arguments_.pathObjectivesEnabled),
],
],
});

const currentSubject = new JavaScriptSubject(target, [
// ...branchObjectives,
// ...functionObjectives,
...pathObjectives,
]);
if (
!this.arguments_.functionObjectivesEnabled &&
!this.arguments_.branchObjectivesEnabled &&
!this.arguments_.pathObjectivesEnabled
) {
JavaScriptLauncher.LOGGER.warn("All objectives are disabled!");
}

const objectives: ObjectiveFunction<JavaScriptTestCase>[] = [];

if (this.arguments_.functionObjectivesEnabled) {
objectives.push(...functionObjectives);
}
if (this.arguments_.branchObjectivesEnabled) {
objectives.push(...branchObjectives);
}
if (this.arguments_.pathObjectivesEnabled) {
objectives.push(...pathObjectives);
}

const currentSubject = new JavaScriptSubject(target, objectives);

const rootTargets = currentSubject
.getActionableTargets()
Expand Down
37 changes: 35 additions & 2 deletions tools/javascript/lib/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function getTestCommand(
const commandGroup = "Type Inference Options:";
const samplingGroup = "Sampling Options:";
const executorGroup = "Test Execution Options:";
const debuggingGroup = "Debugging Options:";
const objectivesGroup = "Objective Options:";

options.set("incorporate-execution-information", {
alias: [],
Expand Down Expand Up @@ -174,7 +176,7 @@ export function getTestCommand(
alias: [],
default: true,
description: "Whether we allow 'odd' syntax or throw an error.",
group: "Debugging",
group: debuggingGroup,
hidden: false,
type: "boolean",
});
Expand All @@ -183,7 +185,34 @@ export function getTestCommand(
alias: [],
default: true,
description: "Whether we show the test output in the logs.",
group: "Debugging",
group: debuggingGroup,
hidden: false,
type: "boolean",
});

options.set("function-objectives-enabled", {
alias: [],
default: true,
description: "Whether we use function objectives.",
group: objectivesGroup,
hidden: false,
type: "boolean",
});

options.set("branch-objectives-enabled", {
alias: [],
default: true,
description: "Whether we use branch objectives.",
group: objectivesGroup,
hidden: false,
type: "boolean",
});

options.set("path-objectives-enabled", {
alias: [],
default: true,
description: "Whether we use path objectives.",
group: objectivesGroup,
hidden: false,
type: "boolean",
});
Expand Down Expand Up @@ -227,4 +256,8 @@ export type TestCommandOptions = {

syntaxForgiving: boolean;
silenceTestOutput: boolean;

functionObjectivesEnabled: boolean;
branchObjectivesEnabled: boolean;
pathObjectivesEnabled: boolean;
};

0 comments on commit 7330730

Please sign in to comment.