Skip to content

Commit 02642c4

Browse files
committed
Add exception through method proxies
1 parent 02359b2 commit 02642c4

12 files changed

Lines changed: 159 additions & 132 deletions

src/ExecutableRequirements-Tests/ExReqMockTestObject.class.st

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ ExReqMockTestObject >> methodToTestMetaSafeRecursion [
1515
^ true
1616
]
1717

18+
{ #category : 'as yet unclassified' }
19+
ExReqMockTestObject >> methodToTestTheExceptionExit [
20+
21+
x := [ true ifTrue: [ Exception signal ] ] value.
22+
^ Color blue
23+
]
24+
1825
{ #category : 'as yet unclassified' }
1926
ExReqMockTestObject >> methodToTestTheNonLocalReturn [
2027

src/ExecutableRequirements-Tests/ExReqSafePassingControlTest.class.st

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ ExReqSafePassingControlTest >> req3 [
6565
yourself
6666
]
6767

68+
{ #category : 'as yet unclassified' }
69+
ExReqSafePassingControlTest >> req4 [
70+
71+
<ExReqSafePassingControl>
72+
^ ExReqRequirement new
73+
title: 'A requirement verifications shall handle exception';
74+
addVerification: [ :verify |
75+
verify
76+
addStepOnAST:
77+
((ExReqMockTestObject methodNamed:
78+
#methodToTestTheExceptionExit) ast allChildren select: [
79+
:each | each isMessage ]) first
80+
withPrecondition: [ true ]
81+
withPostcondition: [ true ] ];
82+
yourself
83+
]
84+
6885
{ #category : 'running' }
6986
ExReqSafePassingControlTest >> setUp [
7087

@@ -85,6 +102,18 @@ ExReqSafePassingControlTest >> tearDown [
85102
repository := nil
86103
]
87104

105+
{ #category : 'tests' }
106+
ExReqSafePassingControlTest >> testExceptionExit [
107+
108+
| requirement requirementReport |
109+
self report installTracingPoints.
110+
self should: [ExReqMockTestObject new methodToTestTheExceptionExit] raise: Exception.
111+
requirement := self req4.
112+
requirementReport := self report findRequirementReport: requirement.
113+
self assert: requirementReport isValid.
114+
self report removeTracingPoints
115+
]
116+
88117
{ #category : 'tests' }
89118
ExReqSafePassingControlTest >> testMetaSafeRecursion [
90119

src/ExecutableRequirements/NeoExReqInstrumentationBuilder.class.st

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ Class {
22
#name : 'NeoExReqInstrumentationBuilder',
33
#superclass : 'Object',
44
#instVars : [
5-
'preconditionMethodProxies',
6-
'postconditionMethodProxies',
75
'preconditionTracingPoints',
8-
'postconditionTracingPoints'
6+
'postconditionTracingPoints',
7+
'methodProxies'
98
],
109
#category : 'ExecutableRequirements-Technical',
1110
#package : 'ExecutableRequirements',
@@ -16,26 +15,23 @@ Class {
1615
NeoExReqInstrumentationBuilder >> initialize [
1716

1817
super initialize.
19-
preconditionMethodProxies := Dictionary new.
20-
postconditionMethodProxies := Dictionary new.
18+
methodProxies := Dictionary new.
2119
preconditionTracingPoints := Dictionary new.
2220
postconditionTracingPoints := Dictionary new
2321
]
2422

2523
{ #category : 'as yet unclassified' }
2624
NeoExReqInstrumentationBuilder >> installAllStepReports: aCollection [
2725

28-
| tracingPoints methodProxies |
26+
| tracingPoints |
2927
aCollection do: [ :each | self installStepReport: each ].
3028
tracingPoints := self preconditionTracingPoints values
3129
, self postconditionTracingPoints values.
32-
methodProxies := self preconditionMethodProxies values
33-
, self postconditionMethodProxies values.
3430

3531
tracingPoints do: [ :each |
3632
each link: each metaLink.
3733
each install ].
38-
methodProxies do: [ :each |
34+
self methodProxies valuesDo: [ :each |
3935
each
4036
install;
4137
enableInstrumentation ]
@@ -56,27 +52,27 @@ NeoExReqInstrumentationBuilder >> installMethodProxyForStepReport: aStepReport w
5652
{ #category : 'as yet unclassified' }
5753
NeoExReqInstrumentationBuilder >> installPostconditionMethodProxyForStepReport: aStepReport withNode: aNode [
5854

59-
self postconditionMethodProxies
55+
self methodProxies
6056
at: aNode
61-
ifPresent: [ :p | p handler addStepReport: aStepReport ]
57+
ifPresent: [ :p | p handler addPostconditionStepReport: aStepReport ]
6258
ifAbsentPut: [
6359
| handler |
64-
handler := NeoExReqPostconditionMethodProxyHandler new
65-
addStepReport: aStepReport;
60+
handler := NeoExReqMethodProxyHandler new
61+
addPostconditionStepReport: aStepReport;
6662
yourself.
6763
MpMethodProxy onMethod: aNode compiledMethod handler: handler ]
6864
]
6965

7066
{ #category : 'as yet unclassified' }
7167
NeoExReqInstrumentationBuilder >> installPreconditionMethodProxyForStepReport: aStepReport withNode: aNode [
7268

73-
self preconditionMethodProxies
69+
self methodProxies
7470
at: aNode
75-
ifPresent: [ :p | p handler addStepReport: aStepReport ]
71+
ifPresent: [ :p | p handler addPreconditionStepReport: aStepReport ]
7672
ifAbsentPut: [
7773
| handler |
78-
handler := NeoExReqPreconditionMethodProxyHandler new
79-
addStepReport: aStepReport;
74+
handler := NeoExReqMethodProxyHandler new
75+
addPreconditionStepReport: aStepReport;
8076
yourself.
8177
MpMethodProxy onMethod: aNode compiledMethod handler: handler ]
8278
]
@@ -87,12 +83,12 @@ NeoExReqInstrumentationBuilder >> installStepReport: aStepReport [
8783
| astNode |
8884
astNode := aStepReport step node.
8985
astNode isMethod
90-
ifTrue: [
91-
self installMethodProxyForStepReport: aStepReport withNode: astNode ]
86+
ifTrue: [ self installMethodProxyForStepReport: aStepReport withNode: astNode
87+
]
9288
ifFalse: [
93-
"self
89+
self
9490
installTracingPointForStepReport: aStepReport
95-
withNode: astNode" ]
91+
withNode: astNode ]
9692
]
9793

9894
{ #category : 'as yet unclassified' }
@@ -123,7 +119,9 @@ NeoExReqInstrumentationBuilder >> installTracingPointForStepReport: aStepReport
123119
{ #category : 'testing' }
124120
NeoExReqInstrumentationBuilder >> isEmpty [
125121

126-
^ self preconditionMethodProxies isEmpty and: [self postconditionMethodProxies isEmpty and: [self preconditionTracingPoints isEmpty and: [ self postconditionTracingPoints isEmpty ]]].
122+
^ self methodProxies isEmpty and: [
123+
self preconditionTracingPoints isEmpty and: [
124+
self postconditionTracingPoints isEmpty ] ]
127125
]
128126

129127
{ #category : 'testing' }
@@ -132,9 +130,9 @@ NeoExReqInstrumentationBuilder >> isNotEmpty [
132130
]
133131

134132
{ #category : 'accessing' }
135-
NeoExReqInstrumentationBuilder >> postconditionMethodProxies [
133+
NeoExReqInstrumentationBuilder >> methodProxies [
136134

137-
^ postconditionMethodProxies
135+
^ methodProxies
138136
]
139137

140138
{ #category : 'accessing' }
@@ -143,12 +141,6 @@ NeoExReqInstrumentationBuilder >> postconditionTracingPoints [
143141
^ postconditionTracingPoints
144142
]
145143

146-
{ #category : 'accessing' }
147-
NeoExReqInstrumentationBuilder >> preconditionMethodProxies [
148-
149-
^ preconditionMethodProxies
150-
]
151-
152144
{ #category : 'accessing' }
153145
NeoExReqInstrumentationBuilder >> preconditionTracingPoints [
154146

@@ -158,16 +150,13 @@ NeoExReqInstrumentationBuilder >> preconditionTracingPoints [
158150
{ #category : 'as yet unclassified' }
159151
NeoExReqInstrumentationBuilder >> uninstallAllStepReports [
160152

161-
| tracingPoints methodProxies |
153+
| tracingPoints |
162154
tracingPoints := self preconditionTracingPoints values
163155
, self postconditionTracingPoints values.
164-
methodProxies := self preconditionMethodProxies values
165-
, self postconditionMethodProxies values.
166156

167157
tracingPoints do: [ :each | each uninstall ].
168-
methodProxies do: [ :each | each uninstall ].
158+
self methodProxies valuesDo: [ :each | each uninstall ].
169159
self preconditionTracingPoints removeAll.
170160
self postconditionTracingPoints removeAll.
171-
self preconditionMethodProxies removeAll.
172-
self postconditionMethodProxies removeAll.
161+
self methodProxies removeAll
173162
]
Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,65 @@
11
Class {
22
#name : 'NeoExReqMethodProxyHandler',
33
#superclass : 'MpHandler',
4-
#traits : 'TExReqTracingHandler',
5-
#classTraits : 'TExReqTracingHandler classTrait',
4+
#instVars : [
5+
'postconditionStepReports',
6+
'preconditionStepReports'
7+
],
68
#category : 'ExecutableRequirements-Technical',
79
#package : 'ExecutableRequirements',
810
#tag : 'Technical'
911
}
12+
13+
{ #category : 'evaluating' }
14+
NeoExReqMethodProxyHandler >> aboutToReturnWithReceiver: anObject arguments: anArrayOfObjects [
15+
16+
self postconditionStepReports do: [ :stepReport |
17+
stepReport
18+
verifyPostconditionWithReceiver: anObject
19+
withArguments: anArrayOfObjects ]
20+
]
21+
22+
{ #category : 'adding' }
23+
NeoExReqMethodProxyHandler >> addPostconditionStepReport: aStepReport [
24+
25+
self postconditionStepReports add: aStepReport
26+
]
27+
28+
{ #category : 'adding' }
29+
NeoExReqMethodProxyHandler >> addPreconditionStepReport: aStepReport [
30+
31+
self preconditionStepReports add: aStepReport
32+
]
33+
34+
{ #category : 'evaluating' }
35+
NeoExReqMethodProxyHandler >> afterExecutionWithReceiver: anObject arguments: anArrayOfObjects returnValue: aReturnValue [
36+
37+
self postconditionStepReports do: [ :stepReport |
38+
stepReport
39+
verifyPostconditionWithReceiver: anObject
40+
withArguments: anArrayOfObjects ].
41+
^ aReturnValue
42+
]
43+
44+
{ #category : 'evaluating' }
45+
NeoExReqMethodProxyHandler >> beforeExecutionWithReceiver: anObject arguments: anArrayOfObjects [
46+
47+
self preconditionStepReports , self postconditionStepReports do: [ :stepReport |
48+
stepReport
49+
verifyPreconditionWithReceiver: anObject
50+
withArguments: anArrayOfObjects ]
51+
]
52+
53+
{ #category : 'accessing' }
54+
NeoExReqMethodProxyHandler >> postconditionStepReports [
55+
56+
^ postconditionStepReports ifNil: [ postconditionStepReports := OrderedCollection new ].
57+
58+
]
59+
60+
{ #category : 'accessing' }
61+
NeoExReqMethodProxyHandler >> preconditionStepReports [
62+
63+
^ preconditionStepReports ifNil: [ preconditionStepReports := OrderedCollection new ].
64+
65+
]

src/ExecutableRequirements/NeoExReqPostconditionMethodProxyHandler.class.st

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/ExecutableRequirements/NeoExReqPostconditionTracingPoint.class.st

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Class {
22
#name : 'NeoExReqPostconditionTracingPoint',
33
#superclass : 'NeoExReqTracingPoint',
4-
#traits : 'TExReqPostconditionsHandler',
5-
#classTraits : 'TExReqPostconditionsHandler classTrait',
64
#category : 'ExecutableRequirements-Technical',
75
#package : 'ExecutableRequirements',
86
#tag : 'Technical'
@@ -21,3 +19,12 @@ NeoExReqPostconditionTracingPoint >> verifyConditionsWithReceiver: anObject with
2119
verifyPostconditionsWithReceiver: anObject
2220
withArguments: aCollection
2321
]
22+
23+
{ #category : 'as yet unclassified' }
24+
NeoExReqPostconditionTracingPoint >> verifyPostconditionsWithReceiver: anObject withArguments: aCollection [
25+
26+
self stepReports do: [ :stepReport |
27+
stepReport
28+
verifyPostconditionWithReceiver: anObject
29+
withArguments: aCollection ]
30+
]

src/ExecutableRequirements/NeoExReqPreconditionMethodProxyHandler.class.st

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/ExecutableRequirements/NeoExReqPreconditionTracingPoint.class.st

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Class {
22
#name : 'NeoExReqPreconditionTracingPoint',
33
#superclass : 'NeoExReqTracingPoint',
4-
#traits : 'TExReqPreconditionsHandler',
5-
#classTraits : 'TExReqPreconditionsHandler classTrait',
64
#category : 'ExecutableRequirements-Technical',
75
#package : 'ExecutableRequirements',
86
#tag : 'Technical'
@@ -13,3 +11,12 @@ NeoExReqPreconditionTracingPoint >> verifyConditionsWithReceiver: anObject withA
1311

1412
^ self verifyPreconditionsWithReceiver: anObject withArguments: aCollection
1513
]
14+
15+
{ #category : 'as yet unclassified' }
16+
NeoExReqPreconditionTracingPoint >> verifyPreconditionsWithReceiver: anObject withArguments: aCollection [
17+
18+
self stepReports do: [ :stepReport |
19+
stepReport
20+
verifyPreconditionWithReceiver: anObject
21+
withArguments: aCollection ]
22+
]

0 commit comments

Comments
 (0)