Skip to content

Commit

Permalink
chore: fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
dstallenberg committed Dec 11, 2023
2 parents 707cf14 + 3f32471 commit ece86ac
Show file tree
Hide file tree
Showing 19 changed files with 366 additions and 257 deletions.
2 changes: 0 additions & 2 deletions libraries/analysis-javascript/lib/RootContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ export class RootContext extends FrameworkRootContext<t.Node> {
get rootPath(): string {
return this._rootPath;
}

// eslint-disable-next-line sonarjs/cognitive-complexity
@cache("source")
@resolvePath()
override getSource(filePath: string): Result<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export class ControlFlowGraphVisitor extends AbstractSyntaxTreeVisitor {
this._createEdge(this._nodes.get(parent), node, this._edgeType)
);
}

this._edgeType = EdgeType.NORMAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class InferenceTypeModelFactory extends TypeModelFactory {

constructor() {
super();

this._typeModel = new TypeModel();
this._idToBindingIdMap = new Map();
}
Expand Down Expand Up @@ -905,8 +904,9 @@ export class InferenceTypeModelFactory extends TypeModelFactory {
originalInvolved: string[]
) {
const [objectId, propertyId] = involved;
const [, originalProperty] = originalInvolved;
const [originalObject, originalProperty] = originalInvolved;

const objectElement = elementMap.get(originalObject);
const propertyElement = elementMap.get(originalProperty);

if (propertyElement === undefined) {
Expand All @@ -922,6 +922,15 @@ export class InferenceTypeModelFactory extends TypeModelFactory {
// add array type to object
this._typeModel.addElementType(objectId, relation.id);

if (
objectElement &&
objectElement.type === ElementType.Identifier &&
objectElement.name === "arguments"
) {
// e.g. arguments[0]
// TODO get function parent and add the argument (impossible right now)
}

break;
}
case ElementType.StringLiteral: {
Expand Down
2 changes: 1 addition & 1 deletion libraries/analysis-javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@syntest/analysis-javascript",
"version": "0.2.0-beta.8",
"version": "0.2.0-beta.9",
"description": "SynTest Analysis JavaScript is a library for doing analysis of the JavaScript language",
"keywords": [
"syntest",
Expand Down
4 changes: 2 additions & 2 deletions libraries/instrumentation-javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@syntest/instrumentation-javascript",
"version": "0.2.0-beta.0",
"version": "0.2.0-beta.1",
"description": "SynTest Instrumentation JavaScript is a library for instrumenting JavaScript code",
"keywords": [
"syntest",
Expand Down Expand Up @@ -51,7 +51,7 @@
"@babel/core": "7.20.12",
"@babel/traverse": "7.20.12",
"@istanbuljs/schema": "^0.1.3",
"@syntest/analysis-javascript": "^0.2.0-beta.8",
"@syntest/analysis-javascript": "^0.2.0-beta.9",
"@syntest/ast-visitor-javascript": "^0.2.0-beta.4",
"@syntest/diagnostics": "^0.1.0-beta.0",
"@syntest/storage": "^0.3.0-beta.2",
Expand Down
42 changes: 0 additions & 42 deletions libraries/search-javascript/lib/criterion/BranchDistanceVisitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,48 +314,6 @@ export class BranchDistanceVisitor extends AbstractSyntaxTreeVisitor {
this._isDistanceMap.set(path.toString(), false);
};

// public ObjectExpression: (path: NodePath<t.ObjectExpression>) => void = (path) => {
// this._valueMap.set(this._getNodeId(path), )
// this._isDistanceMap.set(this._getNodeId(path), false);
// }

// public Identifier: (path: NodePath<t.Identifier>) => void = (path) => {
// if (this._variables[path.node.name] === undefined) {
// // we dont know what this variable is...
// this._valueMap.set(this._getNodeId(path), undefined);
// } else {
// this._valueMap.set(
// this._getNodeId(path),
// this._variables[path.node.name]
// );
// }
// this._isDistanceMap.set(this._getNodeId(path), false);
// };

// public MemberExpression: (path: NodePath<t.MemberExpression>) => void = (
// path
// ) => {
// const result = generate(path.node);
// const value = this._variables[result.code];
// // might be undefined
// this._valueMap.set(this._getNodeId(path), value);
// this._isDistanceMap.set(this._getNodeId(path), false);
// };
// public Identifier: (path: NodePath<t.Identifier>) => void = (path) => {
// if (this._variables[path.node.name] === undefined) {
// // we dont know what this variable is...
// // should never happen??
// this._valueMap.set(path.toString(), undefined);
// throw new ImplementationError(shouldNeverHappen('BranchDistanceVisitor'))
// } else {
// this._valueMap.set(
// path.toString(),
// this._variables[path.node.name]
// );
// }
// this._isDistanceMap.set(path.toString(), false);
// };

public UpdateExpression: (path: NodePath<t.UpdateExpression>) => void = (
path
) => {
Expand Down
19 changes: 8 additions & 11 deletions libraries/search-javascript/lib/testbuilding/JavaScriptDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class JavaScriptDecoder implements Decoder<JavaScriptTestCase, string> {
private targetRootDirectory: string;

constructor(targetRootDirectory: string) {
JavaScriptDecoder.LOGGER = getLogger(JavaScriptDecoder.name);
this.targetRootDirectory = targetRootDirectory;

JavaScriptDecoder.LOGGER = getLogger(JavaScriptDecoder.name);
Expand Down Expand Up @@ -77,15 +78,13 @@ export class JavaScriptDecoder implements Decoder<JavaScriptTestCase, string> {
// delete statements after
errorDecoding = decodings[index];
decodings = decodings.slice(0, index);
}

if (decodings.length === 0) {
JavaScriptDecoder.LOGGER.warn(
"No statements in test case after error reduction"
);
continue;
// throw new ImplementationError(
// );
}
if (decodings.length === 0) {
JavaScriptDecoder.LOGGER.warn(
"No statements in test case after error reduction"
);
continue;
}

const metaCommentBlock = this.generateMetaComments(testCase);
Expand Down Expand Up @@ -237,9 +236,7 @@ export class JavaScriptDecoder implements Decoder<JavaScriptTestCase, string> {
continue;
}

// TODO dirty hack because json.parse does not allow undefined/NaN
// TODO undefined/NaN can happen in arrays
// TODO should not be within quotes
// Dirty hack because json.parse does not allow undefined/NaN
stringified = stringified.replaceAll(
/undefined(?=[^"]*(?:"[^"]*"[^"]*)*$)/g,
"null"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ async function runMocha(silent: boolean, paths: string[], timeout: number) {

const cache = new Set();

// This is to prevent circular references
// TODO this actually removes all repeating values which is not good
process.send(
JSON.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
stringAlphabet: string,
stringMaxLength: number,
deltaMutationProbability: number,
exploreIllegalValues: boolean
exploreIllegalValues: boolean,
addRemoveArgumentProbability: number,
addArgumentProbability: number,
removeArgumentProbability: number
) {
super(
subject,
Expand All @@ -94,7 +97,10 @@ export class JavaScriptRandomSampler extends JavaScriptTestCaseSampler {
stringAlphabet,
stringMaxLength,
deltaMutationProbability,
exploreIllegalValues
exploreIllegalValues,
addRemoveArgumentProbability,
addArgumentProbability,
removeArgumentProbability
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export abstract class JavaScriptTestCaseSampler extends EncodingSampler<JavaScri

private _exploreIllegalValues: boolean;

protected _addRemoveArgumentProbability: number;
protected _addArgumentProbability: number;
protected _removeArgumentProbability: number;

private _statementPool: StatementPool | null;

private _functionCallGenerator: FunctionCallGenerator;
Expand Down Expand Up @@ -106,7 +110,10 @@ export abstract class JavaScriptTestCaseSampler extends EncodingSampler<JavaScri
stringAlphabet: string,
stringMaxLength: number,
deltaMutationProbability: number,
exploreIllegalValues: boolean
exploreIllegalValues: boolean,
addRemoveArgumentProbability: number,
addArgumentProbability: number,
removeArgumentProbability: number
) {
super(subject);
this._constantPoolManager = constantPoolManager;
Expand All @@ -127,6 +134,10 @@ export abstract class JavaScriptTestCaseSampler extends EncodingSampler<JavaScri
this._stringMaxLength = stringMaxLength;
this._deltaMutationProbability = deltaMutationProbability;
this._exploreIllegalValues = exploreIllegalValues;

this._addRemoveArgumentProbability = addRemoveArgumentProbability;
this._addArgumentProbability = addArgumentProbability;
this._removeArgumentProbability = removeArgumentProbability;
}

get rootContext() {
Expand All @@ -140,43 +151,64 @@ export abstract class JavaScriptTestCaseSampler extends EncodingSampler<JavaScri
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
this._constructorCallGenerator = new ConstructorCallGenerator(
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
this._methodCallGenerator = new MethodCallGenerator(
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
this._getterGenerator = new GetterGenerator(
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
this._setterGenerator = new SetterGenerator(
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
this._constantObjectGenerator = new ConstantObjectGenerator(
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
this._objectFunctionCallGenerator = new ObjectFunctionCallGenerator(
this,
rootContext,
this._statementPoolEnabled,
this._statementPoolProbability
this._statementPoolProbability,
this._addRemoveArgumentProbability,
this._addArgumentProbability,
this._removeArgumentProbability
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,26 @@ export abstract class Generator<S extends Statement> {
protected _statementPoolEnabled: boolean;
protected _statementPoolProbability: number;

protected _addRemoveArgumentProbability: number;
protected _addArgumentProbability: number;
protected _removeArgumentProbability: number;

constructor(
sampler: JavaScriptTestCaseSampler,
rootContext: RootContext,
statementPoolEnabled: boolean,
statementPoolProbability: number
statementPoolProbability: number,
addRemoveArgumentProbability: number,
addArgumentProbability: number,
removeArgumentProbability: number
) {
this._sampler = sampler;
this._rootContext = rootContext;
this._statementPoolEnabled = statementPoolEnabled;
this._statementPoolProbability = statementPoolProbability;
this._addRemoveArgumentProbability = addRemoveArgumentProbability;
this._addArgumentProbability = addArgumentProbability;
this._removeArgumentProbability = removeArgumentProbability;
}

abstract generate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,21 @@ export abstract class CallGenerator<S extends Statement> extends Generator<S> {
}

// 50/50 to either maybe remove or add an argument
if (prng.nextBoolean(0.5)) {
if (prng.nextBoolean(this._addRemoveArgumentProbability)) {
// remove args
arguments_.pop();
for (let index = 0; index < arguments_.length; index++) {
if (prng.nextBoolean(0.05)) {
// TODO make this a config parameter
arguments_.pop();
if (!prng.nextBoolean(this._removeArgumentProbability)) {
break;
}
arguments_.pop();
}
} else {
// add args
for (let index = 0; index < 10; index++) {
if (prng.nextBoolean(0.05)) {
// TODO make this a config parameter
arguments_.push(
this.sampler.sampleArgument(depth + 1, "anon", "anon")
);
if (!prng.nextBoolean(this._addArgumentProbability)) {
break;
}
arguments_.push(this.sampler.sampleArgument(depth + 1, "anon", "anon"));
}
}

Expand Down
6 changes: 3 additions & 3 deletions libraries/search-javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@syntest/search-javascript",
"version": "0.2.0-beta.8",
"version": "0.2.0-beta.10",
"description": "SynTest JavaScript is a tool for automatically generating test cases for the JavaScript language",
"keywords": [
"syntest",
Expand Down Expand Up @@ -53,11 +53,11 @@
"@babel/preset-env": "7.19.1",
"@babel/register": "7.18.9",
"@syntest/analysis": "^0.3.0-beta.1",
"@syntest/analysis-javascript": "^0.2.0-beta.8",
"@syntest/analysis-javascript": "^0.2.0-beta.9",
"@syntest/ast-visitor-javascript": "^0.2.0-beta.4",
"@syntest/cfg": "^0.5.0-beta.0",
"@syntest/diagnostics": "^0.1.0-beta.0",
"@syntest/instrumentation-javascript": "^0.2.0-beta.0",
"@syntest/instrumentation-javascript": "^0.2.0-beta.1",
"@syntest/logging": "^0.2.0-beta.2",
"@syntest/prng": "^0.2.0-beta.2",
"@syntest/search": "^0.5.0-beta.10",
Expand Down
Loading

0 comments on commit ece86ac

Please sign in to comment.