forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StHaltCacheTest.class.st
180 lines (153 loc) · 5.87 KB
/
StHaltCacheTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Class {
#name : #StHaltCacheTest,
#superclass : #StHaltAndBreakpointControlTest,
#category : #'NewTools-Debugger-Breakpoints-Tools-Tests'
}
{ #category : #'testing - halts cache' }
StHaltCacheTest >> testAddingHaltToMethod [
| nodeCacheForSimpleHalt originalNodeCacheSize |
nodeCacheForSimpleHalt := cache
nodeCacheForSelector: 'StDummyTestClassWithHalts>>#mHalt'.
originalNodeCacheSize := nodeCacheForSimpleHalt size.
self testClass compile: 'mHalt self halt. self halt'.
nodeCacheForSimpleHalt := cache
nodeCacheForSelector: 'StDummyTestClassWithHalts>>#mHalt'.
self
assert: nodeCacheForSimpleHalt size
equals: originalNodeCacheSize + 1.
(self testClass >> #mHalt) ast statements
do: [ :node | self assert: (nodeCacheForSimpleHalt includes: node) ].
self
assert:
(cache methodsWithHalts keys
select:
[ :methodSelector | methodSelector = 'StDummyTestClassWithHalts>>#mHalt' ])
size
equals: 1
]
{ #category : #'testing - cache initialization' }
StHaltCacheTest >> testCacheActivation [
cache removeSubscriptions.
cache := StHaltCache new.
cache isActive: true.
self assert: cache isActive.
self assert: (SystemAnnouncer uniqueInstance hasSubscriber: cache)
]
{ #category : #'testing - cache initialization' }
StHaltCacheTest >> testCacheDectivation [
cache removeSubscriptions.
cache := StHaltCache new.
cache isActive: true.
self assert: (SystemAnnouncer uniqueInstance hasSubscriber: cache).
cache isActive: false.
self deny: (SystemAnnouncer uniqueInstance hasSubscriber: cache)
]
{ #category : #'testing - cache initialization' }
StHaltCacheTest >> testInitialActivation [
cache := StHaltCache new.
self deny: cache isActive.
self deny: (SystemAnnouncer uniqueInstance hasSubscriber: cache)
]
{ #category : #'testing - cache building' }
StHaltCacheTest >> testInitialCacheBuild [
self assert: cache methodsWithHalts size equals: 6.
(self testClass methods
reject: [ :m |
#('StDummyTestClassWithHalts>>#mNoHalt' 'StDummyTestClassWithHalts>>#mRejectHalt')
includes: m printString ])
do: [ :method |
| haltNode nodeCache |
haltNode := method ast statements first.
self
assert: (cache methodsWithHalts keys includes: method printString).
nodeCache := cache nodeCacheForSelector: method printString.
self assert: nodeCache size equals: 1.
self
assert: nodeCache asOrderedCollection first
identicalTo: haltNode ]
]
{ #category : #'testing - halts cache' }
StHaltCacheTest >> testMethodWithHaltRemoval [
|methodCacheForSimpleHalt |
methodCacheForSimpleHalt := cache methodsWithHalts size.
self testClass removeSelector: #mHalt.
self assert: cache methodsWithHalts size equals: methodCacheForSimpleHalt - 1.
self assert:
(cache methodsWithHalts keys select:[:methodSelector| methodSelector = 'StDummyTestClassWithHalts>>#mHalt']) isEmpty
]
{ #category : #'testing - halts cache' }
StHaltCacheTest >> testNewMethodWithHalt [
|methodCacheForSimpleHalt haltNode|
methodCacheForSimpleHalt := cache methodsWithHalts size.
self testClass compile: 'mHalt2 self halt.'.
haltNode := (self testClass>>#mHalt2) ast statements first.
self assert: cache methodsWithHalts size equals: methodCacheForSimpleHalt + 1.
self assert: (cache nodeCacheForSelector: 'StDummyTestClassWithHalts>>#mHalt2') size equals: 1.
self assert: (cache nodeCacheForSelector: 'StDummyTestClassWithHalts>>#mHalt2') asOrderedCollection first == haltNode.
]
{ #category : #'testing - cache building' }
StHaltCacheTest >> testRefreshCacheWithScanAllSystem [
|newCache|
newCache := StHaltCache new.
newCache scanAllSystem: true.
newCache refreshCache.
self assert: cache methodsWithHalts size >= 6
]
{ #category : #'testing - cache building' }
StHaltCacheTest >> testRefreshCacheWithoutScanAllSystem [
|newCache|
newCache := StHaltCache new.
newCache refreshCache.
self assert: newCache methodsWithHalts isEmpty
]
{ #category : #'testing - halts cache' }
StHaltCacheTest >> testRemoveAllHaltsFromMethod [
| methodCacheForSimpleHalt |
methodCacheForSimpleHalt := cache methodsWithHalts size.
self testClass compile: 'mHalt ^self'.
self
assert: cache methodsWithHalts size
equals: methodCacheForSimpleHalt - 1.
self
assert:
(cache methodsWithHalts keys
select:
[ :methodSelector | methodSelector = 'StDummyTestClassWithHalts>>#mHalt' ])
isEmpty
]
{ #category : #'testing - cache building' }
StHaltCacheTest >> testScanAllSystemDisabled [
|newCache|
newCache := StHaltCache new.
self assert: newCache methodsWithHalts isEmpty
]
{ #category : #'testing - cache building' }
StHaltCacheTest >> testScanAllSystemEnabled [
|newCache|
newCache := StHaltCache basicNew.
newCache scanAllSystem: true.
newCache initialize.
self assert: cache methodsWithHalts size >= 6
]
{ #category : #'testing - halts cache' }
StHaltCacheTest >> testShouldConsiderHaltNode [
| node |
node := RBMessageNode receiver: RBSelfNode new selector: #haltOnAccessTo.
self deny: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #haltOnRead.
self deny: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #haltOnWrite.
self deny: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #haltOnAccess.
self deny: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #mhalt.
self deny: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #halt.
self assert: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #haltOnce.
self assert: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #haltIf.
self assert: (cache shouldConsiderHaltNode: node).
node := RBMessageNode receiver: RBSelfNode new selector: #haltOnCallTo.
self assert: (cache shouldConsiderHaltNode: node).
]