Skip to content

Commit 03af1a6

Browse files
committed
Improve tests generation + regenerate all tests
1 parent 9f9e215 commit 03af1a6

File tree

2 files changed

+320
-258
lines changed

2 files changed

+320
-258
lines changed

src/FAST-Python-Tools-Tests/FASTPyImporterTestGenerator.class.st

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ FASTPyImporterTestGenerator >> generateAssertionsFor: entity pushing: pushString
2323

2424
| propertiesToAssert |
2525
indentation := indentation + 1.
26+
27+
propertiesToAssert := entity mooseDescription allProperties select: [ :property | self shouldSelectProperty: property of: entity ]. "Sorting properties in order to always have the same order."
28+
propertiesToAssert sort: #name ascending.
29+
2630
stream
2731
cr;
2832
tab: indentation;
2933
nextPutAll: 'stack push: ';
3034
nextPutAll: pushString;
3135
nextPutAll: '.';
3236
cr;
33-
tab: indentation.
34-
35-
stream
37+
tab: indentation;
3638
nextPutAll: 'self assert: self topEntity sourceCode equals: ';
3739
print: entity sourceCode withInternalLineEndings;
3840
nextPutAll: (entity sourceCode lines size > 1
@@ -41,12 +43,17 @@ FASTPyImporterTestGenerator >> generateAssertionsFor: entity pushing: pushString
4143
cr;
4244
tab: indentation;
4345
nextPutAll: 'self assert: (self topEntity isOfType: ';
44-
nextPutAll: entity class name;
45-
nextPutAll: ').';
46-
cr;
47-
tab: indentation.
46+
nextPutAll: entity class name.
47+
48+
49+
(shouldPop not and: [ propertiesToAssert isEmpty ])
50+
ifTrue: [ stream nextPut: $) ]
51+
ifFalse: [
52+
stream
53+
nextPutAll: ').';
54+
cr;
55+
tab: indentation ].
4856

49-
propertiesToAssert := entity mooseDescription allProperties select: [ :property | self shouldSelectProperty: property of: entity ].
5057
propertiesToAssert do: [ :property |
5158
| result selector skipPop |
5259
result := property getRawFrom: entity.
@@ -71,10 +78,10 @@ FASTPyImporterTestGenerator >> generateAssertionsFor: entity pushing: pushString
7178
cr;
7279
tab: indentation.
7380
result doWithIndex: [ :child :index |
74-
self
75-
generateAssertionsFor: child
76-
pushing: '(stack top ' , selector , ' at: ' , index asString , ')'
77-
popAtTheEnd: (skipPop not or: [ result size ~= index ]) ] ] ]
81+
self
82+
generateAssertionsFor: child
83+
pushing: '(stack top ' , selector , ' at: ' , index asString , ')'
84+
popAtTheEnd: (skipPop not or: [ result size ~= index ]) ] ] ]
7885
ifFalse: [ "When we have a relation to a collection of entities we do recursively do the testing."
7986
(result isMooseObject and: [ result isMooseEntity ])
8087
ifTrue: [
@@ -90,19 +97,18 @@ FASTPyImporterTestGenerator >> generateAssertionsFor: entity pushing: pushString
9097
nextPutAll: selector;
9198
nextPutAll: ' isNotNil.';
9299
cr.
93-
self
94-
generateAssertionsFor: result
95-
pushing: 'self topEntity ' , selector
96-
popAtTheEnd: skipPop not ]
100+
self generateAssertionsFor: result pushing: 'self topEntity ' , selector popAtTheEnd: skipPop not ]
97101
ifFalse: [
98102
stream
99103
nextPutAll: 'self assert: self topEntity ';
100104
nextPutAll: selector;
101105
nextPutAll: ' equals: ';
102-
store: result;
103-
nextPutAll: '.';
104-
cr;
105-
tab: indentation ] ] ].
106+
store: result.
107+
skipPop ifFalse: [
108+
stream
109+
nextPut: $.;
110+
cr;
111+
tab: indentation ] ] ] ].
106112

107113
shouldPop ifTrue: [
108114
stream
@@ -115,17 +121,24 @@ FASTPyImporterTestGenerator >> generateAssertionsFor: entity pushing: pushString
115121
{ #category : 'test generation' }
116122
FASTPyImporterTestGenerator >> generateTestNamed: aString fromCode: code protocol: protocol [
117123

118-
| model |
124+
| model methodName |
119125
model := self testCase new parse: code.
126+
methodName := ('test' , aString capitalized) asSymbol.
120127

121128
stream
122-
nextPutAll: 'test';
123-
nextPutAll: aString capitalized;
129+
nextPutAll: methodName;
130+
cr;
131+
tab;
132+
nextPutAll: '<generated>';
124133
cr;
125134
tab;
126135
nextPutAll: '"Generated as regression test by ';
127136
print: thisContext homeMethod;
128-
nextPutAll: ' "';
137+
cr;
138+
tab;
139+
nextPutAll: 'Regenerate executing: self regenerateTest: ';
140+
print: methodName;
141+
nextPutAll: ' "';
129142
cr;
130143
cr;
131144
tab;
@@ -135,7 +148,7 @@ FASTPyImporterTestGenerator >> generateTestNamed: aString fromCode: code protoco
135148
cr;
136149
cr.
137150

138-
model allEntityTypes do: [ :type |
151+
(model allEntityTypes sorted: #class ascending) do: [ :type |
139152
stream
140153
tab;
141154
nextPutAll: 'self assert: (fast allWithType: ';
@@ -147,10 +160,7 @@ FASTPyImporterTestGenerator >> generateTestNamed: aString fromCode: code protoco
147160

148161
model rootEntities size = 1 ifFalse: [ self error: 'FAST generator was thought with only 1 top entity?' ].
149162

150-
self
151-
generateAssertionsFor: model rootEntities anyOne genericChildren first
152-
pushing: 'fast rootEntities anyOne genericChildren first'
153-
popAtTheEnd: false.
163+
self generateAssertionsFor: model rootEntities anyOne genericChildren first pushing: 'fast rootEntities anyOne genericChildren first' popAtTheEnd: false.
154164

155165
self testCase compile: stream contents classified: protocol
156166
]
@@ -163,6 +173,15 @@ FASTPyImporterTestGenerator >> initialize [
163173
stream := '' writeStream
164174
]
165175

176+
{ #category : 'test generation' }
177+
FASTPyImporterTestGenerator >> regenerateTest: aCompiledMethod [
178+
179+
| sourceCode |
180+
sourceCode := aCompiledMethod ast statements first arguments first value.
181+
182+
self generateTestNamed: (aCompiledMethod selector withoutPrefix: 'test') fromCode: sourceCode protocol: aCompiledMethod protocol
183+
]
184+
166185
{ #category : 'asserting' }
167186
FASTPyImporterTestGenerator >> shouldSelectProperty: property of: entity [
168187

0 commit comments

Comments
 (0)