Skip to content

Commit

Permalink
feat: update to new syntest-core api
Browse files Browse the repository at this point in the history
  • Loading branch information
dstallenberg committed Sep 13, 2023
1 parent 6f53126 commit 8a64c35
Show file tree
Hide file tree
Showing 19 changed files with 269 additions and 428 deletions.
23 changes: 0 additions & 23 deletions libraries/analysis-javascript/lib/cfg/ControlFlowGraphVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,29 +300,6 @@ export class ControlFlowGraphVisitor extends AbstractSyntaxTreeVisitor {
return node;
}

// private _isSpecial(path: NodePath): boolean {
// return (
// path.isFunction() ||
// path.isClass() ||
// path.isConditional() ||
// path.isLoop() ||
// path.isBlock() ||
// // terminating statements
// path.isBreakStatement() ||
// path.isContinueStatement() ||
// path.isReturnStatement() ||
// path.isThrowStatement() ||
// // exports
// path.isExportAllDeclaration() ||
// path.isExportDeclaration() ||
// path.isExportDefaultDeclaration() ||
// path.isExportDefaultSpecifier() ||
// path.isExportNamedDeclaration() ||
// path.isExportNamespaceSpecifier() ||
// path.isExportSpecifier()
// );
// }

private _createEdge(
source: Node,
target: Node,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ export class VisitState {
const metaTracker = T.callExpression(T.identifier(this.metaVarName), [
T.stringLiteral(`${branchName}`),
T.objectExpression([
T.objectProperty(
T.stringLiteral("condition_ast"),
T.stringLiteral("TODO we should remove the condition asts entirely")
),
T.objectProperty(
T.stringLiteral("condition"),
T.stringLiteral(testAsCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class BranchDistance extends CoreBranchDistance {
}

calculate(
_conditionAST: string, // deprecated
condition: string,
variables: Record<string, unknown>,
trueOrFalse: boolean
Expand Down
24 changes: 12 additions & 12 deletions libraries/search-javascript/lib/search/JavaScriptExecutionResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

import { Datapoint, ExecutionResult } from "@syntest/search";
import { Trace, ExecutionResult } from "@syntest/search";

export enum JavaScriptExecutionStatus {
PASSED,
Expand All @@ -42,7 +42,7 @@ export class JavaScriptExecutionResult implements ExecutionResult {
* ARRAY of traces of the execution.
* @protected
*/
protected _traces: Datapoint[];
protected _traces: Trace[];

/**
* Duration of the execution.
Expand All @@ -51,10 +51,10 @@ export class JavaScriptExecutionResult implements ExecutionResult {
protected _duration: number;

/**
* Exception of execution.
* Error of execution.
* @protected
*/
protected _exception: string;
protected _error: Error | undefined;

/**
* Constructor.
Expand All @@ -66,14 +66,14 @@ export class JavaScriptExecutionResult implements ExecutionResult {
*/
public constructor(
status: JavaScriptExecutionStatus,
traces: Datapoint[],
traces: Trace[],
duration: number,
exception?: string | undefined
error?: Error | undefined
) {
this._status = status;
this._traces = traces;
this._duration = duration;
this._exception = exception;
this._error = error;
}

/**
Expand Down Expand Up @@ -132,22 +132,22 @@ export class JavaScriptExecutionResult implements ExecutionResult {
/**
* @inheritDoc
*/
public getExceptions(): string {
return this._exception;
public getError(): Error {
return this._error;
}

/**
* @inheritDoc
*/
public getTraces(): Datapoint[] {
public getTraces(): Trace[] {
return this._traces;
}

/**
* @inheritDoc
*/
public hasExceptions(): boolean {
return this._exception !== null && this._exception !== undefined;
public hasError(): boolean {
return this._error !== null && this._error !== undefined;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export class ExecutionInformationIntegrator {
const children = root.getChildren();

for (const child of children) {
if (testResult.exception && testResult.exception.includes(child.name)) {
if (
testResult.error &&
testResult.error.message &&
testResult.error.message.includes(child.name)
) {
this._typeModel.addExecutionScore(
child.variableIdentifier,
child.typeIdentifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import * as path from "node:path";

import { Datapoint, EncodingRunner, ExecutionResult } from "@syntest/search";
import { Trace, EncodingRunner, ExecutionResult } from "@syntest/search";
import { getLogger, Logger } from "@syntest/logging";

import {
Expand Down Expand Up @@ -112,7 +112,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
if (data.message === "done") {
childProcess.removeAllListeners();
clearTimeout(timeout);

if (!data.instrumentationData) {
return reject("no instrumentation data found");
}
Expand Down Expand Up @@ -161,7 +160,7 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
// If one of the executions failed, log it
this.executionInformationIntegrator.process(testCase, test, stats);

const traces: Datapoint[] = this._extractTraces(
const traces: Trace[] = this._extractTraces(
instrumentationData,
metaData
);
Expand All @@ -171,7 +170,7 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
test.status,
traces,
test.duration,
test.exception
test.error
);
} catch (error) {
if (error === "timeout") {
Expand Down Expand Up @@ -201,8 +200,8 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {
private _extractTraces(
instrumentationData: InstrumentationData,
metaData: MetaData
): Datapoint[] {
const traces: Datapoint[] = [];
): Trace[] {
const traces: Trace[] = [];

for (const key of Object.keys(instrumentationData)) {
for (const functionKey of Object.keys(instrumentationData[key].fnMap)) {
Expand Down Expand Up @@ -254,7 +253,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {

hits: hits[0],

condition_ast: meta?.condition_ast,
condition: meta?.condition,
variables: meta?.variables,
});
Expand All @@ -273,7 +271,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {

hits: hits[index],

condition_ast: meta?.condition_ast,
condition: meta?.condition,
variables: meta?.variables,
});
Expand All @@ -289,7 +286,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {

hits: hits[1],

condition_ast: meta?.condition_ast,
condition: meta?.condition,
variables: meta?.variables,
});
Expand All @@ -306,7 +302,6 @@ export class JavaScriptRunner implements EncodingRunner<JavaScriptTestCase> {

hits: hits[0] ? 0 : 1,

condition_ast: meta?.condition_ast,
condition: meta?.condition,
variables: meta?.variables,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type Suite = {

export type Test = {
status: JavaScriptExecutionStatus;
exception?: string;
error?: Error | undefined;
duration: number;
};

Expand Down Expand Up @@ -118,11 +118,16 @@ async function runMocha(silent: boolean, paths: string[], timeout: number) {
} else {
status = JavaScriptExecutionStatus.FAILED;
}

return {
status: status,
exception:
error:
status === JavaScriptExecutionStatus.FAILED
? test.err.message
? {
name: test.err.name,
message: test.err.message,
stack: test.err.stack,
}
: undefined,
duration: test.duration,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0.5);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(
0.5
);
});

it("2 == 1 false", () => {
Expand All @@ -45,9 +45,7 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(0);
});

it("1 == 1 true", () => {
Expand All @@ -60,9 +58,7 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(0);
});

it("1 == 1 false", () => {
Expand All @@ -75,9 +71,9 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0.5);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(
0.5
);
});

it("0 == -1 true", () => {
Expand All @@ -90,9 +86,9 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0.5);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(
0.5
);
});

it("0 == -1 false", () => {
Expand All @@ -105,9 +101,7 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(0);
});

// string
Expand All @@ -121,9 +115,7 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(0);
});

it("'a' == 'a' false", () => {
Expand All @@ -136,9 +128,9 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0.5);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(
0.5
);
});

it("'a' == 'b' true", () => {
Expand All @@ -152,7 +144,7 @@ describe("BranchDistance a == b test", () => {
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
calculator.calculate(condition, variables, trueOrFalse)
).to.be.closeTo(0.3333, 0.001);
});

Expand All @@ -166,9 +158,7 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(0);
});

// number string mix
Expand All @@ -182,9 +172,7 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(0);
});

it("0 == '0' false", () => {
Expand All @@ -197,8 +185,8 @@ describe("BranchDistance a == b test", () => {
"0123456789abcdefghijklmnopqrstuvxyz"
);

expect(
calculator.calculate("", condition, variables, trueOrFalse)
).to.equal(0.5);
expect(calculator.calculate(condition, variables, trueOrFalse)).to.equal(
0.5
);
});
});
Loading

0 comments on commit 8a64c35

Please sign in to comment.