From 138727a4b7dce0e94f645f2c86a08a598de0a033 Mon Sep 17 00:00:00 2001 From: fabiovandewaeter Date: Thu, 18 Jul 2024 16:51:01 +0200 Subject: [PATCH] fix test generation --- .../FamixPharoUTHelperSetUpStrategy.class.st | 27 +++++++++++-------- .../FamixUTSUnitExporter.class.st | 22 +++++++-------- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/Famix-UnitTest-Exporter/FamixPharoUTHelperSetUpStrategy.class.st b/src/Famix-UnitTest-Exporter/FamixPharoUTHelperSetUpStrategy.class.st index f646569..8980d6a 100644 --- a/src/Famix-UnitTest-Exporter/FamixPharoUTHelperSetUpStrategy.class.st +++ b/src/Famix-UnitTest-Exporter/FamixPharoUTHelperSetUpStrategy.class.st @@ -53,20 +53,24 @@ FamixPharoUTHelperSetUpStrategy >> makeHelperMethodFor: value on: aFamixUTExport oldStatementBlock := valueExporter statementBlock. method := RBMethodNode new body: (newStatementBlock := RBSequenceNode new). + newStatementBlock addNode: (RBAssignmentNode + variable: (RBVariableNode named: 'vars') + value: (RBMessageNode + receiver: (RBVariableNode named: #Dictionary) + selector: #new)). + + node := (valueExporter statementBlock: newStatementBlock) ensureVisited: value. - newStatementBlock addNode: - (((node isMessage and: [ node receiver isAssignment ]) or: [ - node isCascade and: [ node messages first receiver isAssignment ] ]) - ifTrue: [ node ] - ifFalse: [ - RBAssignmentNode new - value: node; - variable: (RBVariableNode named: - (aFamixUTExporter valueExporter varNameFor: value)) ]). - newStatementBlock addNode: - (RBReturnNode value: (valueExporter makeVariableExpression: value)). + + "newStatementBlock addNode: + (RBReturnNode value: (valueExporter makeVariableExpression: value))." + newStatementBlock addNode: (RBReturnNode value: (RBMessageNode + receiver: (RBVariableNode named: 'vars') + selector: #at: + arguments: + { (RBLiteralNode value: (valueExporter varNameFor: value)) })). "Add necessary temporary variables" newStatementBlock allChildren do: [ :each | each isAssignment ifTrue: [ @@ -74,5 +78,6 @@ FamixPharoUTHelperSetUpStrategy >> makeHelperMethodFor: value on: aFamixUTExport temporary name = each variable name ]) ifFalse: [ newStatementBlock addTemporaryNamed: each variable name ] ] ]. valueExporter statementBlock: oldStatementBlock. + ^ method ] diff --git a/src/Famix-UnitTest-Exporter/FamixUTSUnitExporter.class.st b/src/Famix-UnitTest-Exporter/FamixUTSUnitExporter.class.st index 2c57318..1a28d70 100644 --- a/src/Famix-UnitTest-Exporter/FamixUTSUnitExporter.class.st +++ b/src/Famix-UnitTest-Exporter/FamixUTSUnitExporter.class.st @@ -129,21 +129,21 @@ FamixUTSUnitExporter >> exportMethod: aFamixUTMethod [ { #category : #exporting } FamixUTSUnitExporter >> exportMethodSetUp: aFamixUTSetUp [ - self flag: #TODO. (self methodSetUpStrategy export: aFamixUTSetUp on: self) with: aFamixUTSetUp values do: [ :ast :value | - | name | - name := self valueExporter varNameDict - at: value - ifAbsentPut: [ valueExporter varNameFor: value ]. + | name node | + node := ast. + ((ast isMessage and: [ ast receiver name = #self ]) or: [ + ast isLiteralNode ]) ifFalse: [ + self flag: #TODO. "prevent this from happening" + statementBlock statements: statementBlock statements allButLast. + node := ast arguments second ]. + name := self valueExporter varNameFor: value. self statementBlock addNode: - ((ast isCascade and: [ ast messages first receiver isAssignment ]) - ifTrue: [ ast ] - ifFalse: [ - RBAssignmentNode - variable: (RBVariableNode named: name) - value: ast ]) ] + (RBAssignmentNode + variable: (RBVariableNode named: name) + value: node) ] ] { #category : #'instance creation' }