Skip to content

Commit 2606cba

Browse files
committed
Reorganizing extensions in tests
1 parent 26998ed commit 2606cba

36 files changed

+1602
-1583
lines changed

src/AST-Core-Tests/OCCodeSnippetScriptingTest.class.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Class {
22
#name : 'OCCodeSnippetScriptingTest',
3-
#superclass : 'OCCodeSnippetTest',
3+
#superclass : 'OCCompileCodeSnippetTest',
44
#category : 'AST-Core-Tests-Snippets',
55
#package : 'AST-Core-Tests',
66
#tag : 'Snippets'

src/AST-Core-Tests/OCCodeSnippetTest.class.st

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -47,115 +47,3 @@ OCCodeSnippetTest >> snippet: anObject [
4747

4848
snippet := anObject
4949
]
50-
51-
{ #category : 'tests' }
52-
OCCodeSnippetTest >> testCodeImporter [
53-
54-
| string importer class runBlock |
55-
"Code importer meed a plain expression or use a custom format"
56-
snippet source isAllSeparators ifTrue: [ ^ self skip ].
57-
[
58-
string := snippet isScripting
59-
ifFalse: [
60-
class := ChunkImportTestCase new importAClass.
61-
'!{1} methodsFor: ''some protocol''!{2}' format: {
62-
class name asString.
63-
snippet source } ]
64-
ifTrue: [ snippet source ].
65-
66-
"Note: it might be possible that the snipped messes with the chuck format... to investigate"
67-
importer := CodeImporter fromString: string.
68-
importer parseChunks.
69-
70-
self skipIf: #exec.
71-
72-
"Importer should fail when faulty"
73-
snippet isFaulty ifTrue: [
74-
self should: [ importer evaluate ] raise: OCCodeError.
75-
snippet isScripting ifFalse: [ class removeFromSystem ].
76-
^ self ].
77-
78-
"When not faulty, it's more complicated..."
79-
runBlock := [
80-
| value |
81-
value := importer evaluate.
82-
83-
snippet isScripting ifFalse: [
84-
| method phonyArgs |
85-
self assert: value isSymbol.
86-
"Need to call the method, the importer added it to `class`, so retrieve it"
87-
method := class >> value.
88-
class removeFromSystem. "No more needed"
89-
phonyArgs := (1 to: method numArgs) asArray.
90-
value := nil withArgs: phonyArgs executeMethod: method ].
91-
92-
value ].
93-
94-
self testExecuteBlock: runBlock ] ensure: [ self packageOrganizer removePackage: ChunkImportTestCase new packageNameForTests ]
95-
]
96-
97-
{ #category : 'tests' }
98-
OCCodeSnippetTest >> testFormattedCode [
99-
100-
| ast |
101-
ast := snippet parse.
102-
self assert: ast formattedCode withSeparatorsCompacted equals: snippet formattedCode withSeparatorsCompacted
103-
]
104-
105-
{ #category : 'tests' }
106-
OCCodeSnippetTest >> testParse [
107-
108-
| ast |
109-
ast := snippet parse.
110-
111-
self
112-
assert: ast isFaulty
113-
equals: (snippet isParseFaulty ifNil: [ snippet isFaulty ]).
114-
115-
"Smoke test on the method node"
116-
self assert: ast methodNode reformatSource isString.
117-
118-
snippet nodePositions ifNotNil: [
119-
self assert: ast asPositionDebugString equals: snippet nodePositions ].
120-
121-
"Smoke test on each AST node (in alphabetic order of selectors)"
122-
ast nodesDo: [ :node |
123-
self assert: ((node allParents includes: ast) or: [node = ast]).
124-
node start to: node stop do: [ :i | self assert: ((node bestNodeFor: (i to: i)) isKindOf: OCProgramNode) ].
125-
node start+1 to: node stop do: [ :i | self assert: ((node bestNodeForPosition: i) isKindOf: OCProgramNode) ].
126-
self assert: node dump equals: node dump.
127-
node hasMultipleReturns.
128-
node hasNonLocalReturn.
129-
self assert: node sourceCode isString.
130-
node start to: node stop do: [ :i | self assert: ((node nodeForOffset: i) isKindOf: OCProgramNode) ].
131-
self assert: node printString isString.
132-
self assert: node selfMessages isCollection.
133-
self assert: node methodNode = ast equals: snippet isScripting not.
134-
self assert: (node methodOrBlockNode isKindOf: OCProgramNode).
135-
]
136-
]
137-
138-
{ #category : 'tests' }
139-
OCCodeSnippetTest >> testParseOnError [
140-
141-
| ast error |
142-
error := nil.
143-
144-
ast := snippet parseOnError: [ :e | error := e messageText ].
145-
146-
(snippet isParseFaulty ifNil: [ snippet isFaulty ])
147-
ifTrue: [ self assert: error isNotNil ]
148-
ifFalse: [
149-
self assert: error isNil.
150-
self deny: ast isFaulty ]
151-
]
152-
153-
{ #category : 'tests' }
154-
OCCodeSnippetTest >> testSimpleFormattedCode [
155-
156-
| ast fast east |
157-
ast := snippet parse.
158-
fast := (OCSimpleFormatter format: ast) reject: #isSeparator.
159-
east := snippet formattedCode reject: #isSeparator.
160-
self assert: fast equals: east
161-
]

src/OpalCompiler-Tests/OCCodeSnippetTest.extension.st renamed to src/AST-Core-Tests/OCCompileCodeSnippetTest.class.st

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
Extension { #name : 'OCCodeSnippetTest' }
1+
Class {
2+
#name : 'OCCompileCodeSnippetTest',
3+
#superclass : 'OCCodeSnippetTest',
4+
#category : 'AST-Core-Tests-Snippets',
5+
#package : 'AST-Core-Tests',
6+
#tag : 'Snippets'
7+
}
28

3-
{ #category : '*OpalCompiler-Tests' }
4-
OCCodeSnippetTest >> compileSnippet: anOCCodeSnippet [
9+
{ #category : 'helpers' }
10+
OCCompileCodeSnippetTest >> compileSnippet: anOCCodeSnippet [
511

612
^ [ OpalCompiler new
713
permitFaulty: true;
@@ -15,8 +21,8 @@ OCCodeSnippetTest >> compileSnippet: anOCCodeSnippet [
1521
e pass ]
1622
]
1723

18-
{ #category : '*OpalCompiler-Tests' }
19-
OCCodeSnippetTest >> compileSnippet: aSnippet onError: errorBlock [
24+
{ #category : 'helpers' }
25+
OCCompileCodeSnippetTest >> compileSnippet: aSnippet onError: errorBlock [
2026

2127
^ [
2228
OpalCompiler new
@@ -26,8 +32,8 @@ OCCodeSnippetTest >> compileSnippet: aSnippet onError: errorBlock [
2632
do: [ :e | errorBlock cull: e ]
2733
]
2834

29-
{ #category : '*OpalCompiler-Tests' }
30-
OCCodeSnippetTest >> testCompileFailBlock [
35+
{ #category : 'tests' }
36+
OCCompileCodeSnippetTest >> testCompileFailBlock [
3137

3238
| method error |
3339
error := nil.
@@ -50,8 +56,8 @@ OCCodeSnippetTest >> testCompileFailBlock [
5056
self testExecute: method ]
5157
]
5258

53-
{ #category : '*OpalCompiler-Tests' }
54-
OCCodeSnippetTest >> testCompileFaulty [
59+
{ #category : 'tests' }
60+
OCCompileCodeSnippetTest >> testCompileFaulty [
5561

5662
| method |
5763

@@ -74,8 +80,8 @@ OCCodeSnippetTest >> testCompileFaulty [
7480
self testExecute: method
7581
]
7682

77-
{ #category : '*OpalCompiler-Tests' }
78-
OCCodeSnippetTest >> testCompileOnError [
83+
{ #category : 'tests' }
84+
OCCompileCodeSnippetTest >> testCompileOnError [
7985

8086
| method error |
8187
error := nil.
@@ -92,8 +98,8 @@ OCCodeSnippetTest >> testCompileOnError [
9298
self testExecute: method ]
9399
]
94100

95-
{ #category : '*OpalCompiler-Tests' }
96-
OCCodeSnippetTest >> testCompileOnErrorResume [
101+
{ #category : 'tests' }
102+
OCCompileCodeSnippetTest >> testCompileOnErrorResume [
97103

98104
| method error |
99105
error := nil.
@@ -107,8 +113,8 @@ OCCodeSnippetTest >> testCompileOnErrorResume [
107113
self testExecute: method
108114
]
109115

110-
{ #category : '*OpalCompiler-Tests' }
111-
OCCodeSnippetTest >> testCompileUndeclaredFaultyFailBlock [
116+
{ #category : 'tests' }
117+
OCCompileCodeSnippetTest >> testCompileUndeclaredFaultyFailBlock [
112118

113119
| method error |
114120
error := nil.
@@ -132,8 +138,8 @@ OCCodeSnippetTest >> testCompileUndeclaredFaultyFailBlock [
132138
self testExecute: method ]
133139
]
134140

135-
{ #category : '*OpalCompiler-Tests' }
136-
OCCodeSnippetTest >> testCompileWithRequestor [
141+
{ #category : 'tests' }
142+
OCCompileCodeSnippetTest >> testCompileWithRequestor [
137143

138144
| requestor method |
139145
requestor := OCMockRequestor new.
@@ -162,8 +168,52 @@ OCCodeSnippetTest >> testCompileWithRequestor [
162168
self testExecute: method
163169
]
164170

165-
{ #category : '*OpalCompiler-Tests' }
166-
OCCodeSnippetTest >> testDoSemanticAnalysis [
171+
{ #category : 'tests' }
172+
OCCompileCodeSnippetTest >> testCritiques [
173+
174+
| ast critiques |
175+
ast := snippet parse.
176+
critiques := ast critiques.
177+
178+
snippet numberOfCritiques ifNotNil: [ :n |
179+
self assert: critiques size equals: n.
180+
^ self ].
181+
182+
"Alone blocks will have ReDeadBlockRule. Currently no other critiques are fired."
183+
"When we get some critiques, we will add a instance vaviable in the snippet to validate them"
184+
ast isBlock
185+
ifTrue: [
186+
self assert: critiques size equals: 1.
187+
self assert: critiques anyOne rule class equals: ReDeadBlockRule ]
188+
ifFalse: [ self assert: critiques isEmpty ]
189+
]
190+
191+
{ #category : 'tests' }
192+
OCCompileCodeSnippetTest >> testDecompile [
193+
194+
| method ast |
195+
method := self compileSnippet: snippet.
196+
method ifNil: [ ^ self skip ]. "Another test responsibility"
197+
ast := method decompile.
198+
self assert: ast isMethod.
199+
ast := method parseTree.
200+
self assert: ast isMethod.
201+
"Decompilation lose many information. Not sure how to test more"
202+
]
203+
204+
{ #category : 'tests' }
205+
OCCompileCodeSnippetTest >> testDecompileIR [
206+
207+
| method ir |
208+
method := self compileSnippet: snippet.
209+
method ifNil: [ ^ self skip ]. "Another test responsibility"
210+
ir := method decompileIR.
211+
self assert: ir class equals: OCIRMethod.
212+
"Decompilation lose information. Not sure how to test more"
213+
]
214+
215+
{ #category : 'tests' }
216+
OCCompileCodeSnippetTest >> testDoSemanticAnalysis [
167217
"We should test more than that"
168218

169219
| ast |
@@ -174,8 +224,8 @@ OCCodeSnippetTest >> testDoSemanticAnalysis [
174224
self assert: (snippet hasAllNotices: ast allNotices)
175225
]
176226

177-
{ #category : '*OpalCompiler-Tests' }
178-
OCCodeSnippetTest >> testDoSemanticAnalysisOnError [
227+
{ #category : 'tests' }
228+
OCCompileCodeSnippetTest >> testDoSemanticAnalysisOnError [
179229
"We should test more than that"
180230

181231
| ast error |
@@ -190,8 +240,8 @@ OCCodeSnippetTest >> testDoSemanticAnalysisOnError [
190240
self assert: error isNil ]
191241
]
192242

193-
{ #category : '*OpalCompiler-Tests' }
194-
OCCodeSnippetTest >> testDump [
243+
{ #category : 'tests' }
244+
OCCompileCodeSnippetTest >> testDump [
195245

196246
| ast dump ast2 dump2 |
197247
ast := snippet parse.
@@ -202,8 +252,8 @@ OCCodeSnippetTest >> testDump [
202252
self assert: dump2 equals: dump
203253
]
204254

205-
{ #category : '*OpalCompiler-Tests' }
206-
OCCodeSnippetTest >> testExecute: method [
255+
{ #category : 'helpers' }
256+
OCCompileCodeSnippetTest >> testExecute: method [
207257

208258
| runBlock phonyArgs |
209259
self skipIf: #exec.
@@ -215,8 +265,8 @@ OCCodeSnippetTest >> testExecute: method [
215265
self testExecuteBlock: runBlock
216266
]
217267

218-
{ #category : '*OpalCompiler-Tests' }
219-
OCCodeSnippetTest >> testExecuteBlock: aRunBlock [
268+
{ #category : 'helpers' }
269+
OCCompileCodeSnippetTest >> testExecuteBlock: aRunBlock [
220270

221271
| runBlock |
222272
"a block that apply value on aRunBlock until it's no more a block"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
Class {
2+
#name : 'OCParseCodeSnippetTest',
3+
#superclass : 'OCCodeSnippetTest',
4+
#category : 'AST-Core-Tests-Snippets',
5+
#package : 'AST-Core-Tests',
6+
#tag : 'Snippets'
7+
}
8+
9+
{ #category : 'tests' }
10+
OCParseCodeSnippetTest >> testFormattedCode [
11+
12+
| ast |
13+
ast := snippet parse.
14+
self assert: ast formattedCode withSeparatorsCompacted equals: snippet formattedCode withSeparatorsCompacted
15+
]
16+
17+
{ #category : 'tests' }
18+
OCParseCodeSnippetTest >> testParse [
19+
20+
| ast |
21+
ast := snippet parse.
22+
23+
self
24+
assert: ast isFaulty
25+
equals: (snippet isParseFaulty ifNil: [ snippet isFaulty ]).
26+
27+
"Smoke test on the method node"
28+
self assert: ast methodNode reformatSource isString.
29+
30+
snippet nodePositions ifNotNil: [
31+
self assert: ast asPositionDebugString equals: snippet nodePositions ].
32+
33+
"Smoke test on each AST node (in alphabetic order of selectors)"
34+
ast nodesDo: [ :node |
35+
self assert: ((node allParents includes: ast) or: [node = ast]).
36+
node start to: node stop do: [ :i | self assert: ((node bestNodeFor: (i to: i)) isKindOf: OCProgramNode) ].
37+
node start+1 to: node stop do: [ :i | self assert: ((node bestNodeForPosition: i) isKindOf: OCProgramNode) ].
38+
self assert: node dump equals: node dump.
39+
node hasMultipleReturns.
40+
node hasNonLocalReturn.
41+
self assert: node sourceCode isString.
42+
node start to: node stop do: [ :i | self assert: ((node nodeForOffset: i) isKindOf: OCProgramNode) ].
43+
self assert: node printString isString.
44+
self assert: node selfMessages isCollection.
45+
self assert: node methodNode = ast equals: snippet isScripting not.
46+
self assert: (node methodOrBlockNode isKindOf: OCProgramNode).
47+
]
48+
]
49+
50+
{ #category : 'tests' }
51+
OCParseCodeSnippetTest >> testParseOnError [
52+
53+
| ast error |
54+
error := nil.
55+
56+
ast := snippet parseOnError: [ :e | error := e messageText ].
57+
58+
(snippet isParseFaulty ifNil: [ snippet isFaulty ])
59+
ifTrue: [ self assert: error isNotNil ]
60+
ifFalse: [
61+
self assert: error isNil.
62+
self deny: ast isFaulty ]
63+
]
64+
65+
{ #category : 'tests' }
66+
OCParseCodeSnippetTest >> testSimpleFormattedCode [
67+
68+
| ast fast east |
69+
ast := snippet parse.
70+
fast := (OCSimpleFormatter format: ast) reject: #isSeparator.
71+
east := snippet formattedCode reject: #isSeparator.
72+
self assert: fast equals: east
73+
]

0 commit comments

Comments
 (0)