Skip to content

Commit

Permalink
fix test generation
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiovandewaeter committed Jul 18, 2024
1 parent afbad1e commit 138727a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,31 @@ 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: [
(newStatementBlock temporaries anySatisfy: [ :temporary |
temporary name = each variable name ]) ifFalse: [
newStatementBlock addTemporaryNamed: each variable name ] ] ].
valueExporter statementBlock: oldStatementBlock.

^ method
]
22 changes: 11 additions & 11 deletions src/Famix-UnitTest-Exporter/FamixUTSUnitExporter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down

0 comments on commit 138727a

Please sign in to comment.