Skip to content

Commit e596326

Browse files
committed
Add safe postconditions
1 parent d8de816 commit e596326

9 files changed

Lines changed: 188 additions & 120 deletions

src/ExecutableRequirements-Tests/ExReqMockRequirements.class.st

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ Class {
66
#tag : 'Meta-Requirements-Tests'
77
}
88

9+
{ #category : 'initialization' }
10+
ExReqMockRequirements >> resetMethod [
11+
12+
<script: 'ExReqMockRequirements new resetMethod'>
13+
| class methods |
14+
ExReqTracingPoint all do: #remove.
15+
class := ExReqMockRequirements.
16+
methods := class methods collect: [ :each | each sourceCode ].
17+
class methods do: [ :each | class removeSelector: each ].
18+
methods do: [ :each | class compile: each ]
19+
]
20+
921
{ #category : 'tests' }
1022
ExReqMockRequirements >> testReq1 [
1123

@@ -113,26 +125,26 @@ ExReqMockRequirements >> testReq7 [
113125
description: 'The description';
114126
addVerification: [ :verify |
115127
verify addStepOnAST:
116-
((ExReqMockRequirements methodNamed: #testReq7) ast allChildren
117-
select: [ :each | each isSequence ]) second ];
128+
((ExReqMockRequirements methodNamed: #testReq1) ast allChildren
129+
select: [ :each | each isSequence ]) first ];
118130
addVerification: [ :verify |
119131
verify
120132
addStepOnAST:
121-
((ExReqMockRequirements methodNamed: #testReq7) ast allChildren
122-
select: [ :each | each isSequence ]) second
133+
((ExReqMockRequirements methodNamed: #testReq1) ast allChildren
134+
select: [ :each | each isSequence ]) first
123135
withPrecondition: [ :obj :arguments :requirement | true ] ];
124136
addVerification: [ :verify |
125137
verify
126138
addStepOnAST:
127-
((ExReqMockRequirements methodNamed: #testReq7) ast allChildren
128-
select: [ :each | each isSequence ]) second
139+
((ExReqMockRequirements methodNamed: #testReq1) ast allChildren
140+
select: [ :each | each isSequence ]) first
129141
withPrecondition: [ :obj :arguments :requirement | true ]
130142
withPostcondition: [ :obj :arguments :requirement | true ] ];
131143
addVerification: [ :verify |
132144
verify
133145
addStepOnAST:
134-
((ExReqMockRequirements methodNamed: #testReq7) ast allChildren
135-
select: [ :each | each isSequence ]) second
146+
((ExReqMockRequirements methodNamed: #testReq1) ast allChildren
147+
select: [ :each | each isSequence ]) first
136148
withPostcondition: [ :obj :arguments :requirement | true ] ];
137149
yourself
138150
]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Class {
2+
#name : 'ExReqMockTestObject',
3+
#superclass : 'Object',
4+
#instVars : [
5+
'x'
6+
],
7+
#category : 'ExecutableRequirements-Tests-Safe-Passing-Control',
8+
#package : 'ExecutableRequirements-Tests',
9+
#tag : 'Safe-Passing-Control'
10+
}
11+
12+
{ #category : 'as yet unclassified' }
13+
ExReqMockTestObject >> methodToTestTheNonLocalReturn [
14+
15+
x := [ true ifTrue: [ ^ Color red ] ] value.
16+
^ Color blue
17+
]

src/ExecutableRequirements-Tests/ExReqRepositoryReportTest.class.st

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ ExReqRepositoryReportTest >> testExecuteTracingPoints [
5757

5858
| requirement requirementReport |
5959
self report installTracingPoints.
60+
ExReqMockRequirements new testReq1.
6061
requirement := ExReqMockRequirements new testReq7.
6162
requirementReport := self report findRequirementReport: requirement.
6263
self assert: requirementReport isValid.
@@ -111,7 +112,7 @@ ExReqRepositoryReportTest >> testStepReportIsValidEvent [
111112
do: [ :evt | success := true ]
112113
for: self.
113114
self report installTracingPoints.
114-
ExReqMockRequirements new testReq7.
115+
ExReqMockRequirements new testReq1.
115116
self assert: success
116117
]
117118

src/ExecutableRequirements-Tests/ExReqRepositoryTest.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ ExReqRepositoryTest >> testRequirementsAreTraceable [
3131
each isPharoImageDocument ].
3232
mockDocuments := documents select: [ :each | each isMockDocument ].
3333

34-
self assert: pharoImageDocument size equals: ExReqMockRequirements methods size - 1.
34+
self assert: pharoImageDocument size equals: ExReqMockRequirements methods size - 2.
3535
self
3636
assertCollection: (pharoImageDocument collect: #method)
3737
includesAll: (ExReqMockRequirements methods reject: [ :each |
38-
each selector = #testReq3 ]).
38+
each selector = #testReq3 or: [ each selector = #resetMethod ] ]).
3939

4040
self assert: mockDocuments size equals: 1.
4141
self assert: mockDocuments first requirementId equals: #testReq3
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Class {
2+
#name : 'ExReqSafePassingControlTest',
3+
#superclass : 'TestCase',
4+
#instVars : [
5+
'repository',
6+
'report'
7+
],
8+
#category : 'ExecutableRequirements-Tests-Safe-Passing-Control',
9+
#package : 'ExecutableRequirements-Tests',
10+
#tag : 'Safe-Passing-Control'
11+
}
12+
13+
{ #category : 'accessing' }
14+
ExReqSafePassingControlTest >> report [
15+
16+
^ report
17+
]
18+
19+
{ #category : 'as yet unclassified' }
20+
ExReqSafePassingControlTest >> req3 [
21+
22+
<ExReqSafePassingControl>
23+
^ ExReqRequirement new
24+
title: 'A requirement verifications shall handle non local return';
25+
addVerification: [ :verify |
26+
verify
27+
addStepOnAST:
28+
((ExReqMockTestObject methodNamed:
29+
#methodToTestTheNonLocalReturn) ast allChildren select: [
30+
:each | each isMessage ]) first
31+
withPrecondition: [ true ]
32+
withPostcondition: [ true ] ];
33+
yourself
34+
]
35+
36+
{ #category : 'running' }
37+
ExReqSafePassingControlTest >> setUp [
38+
39+
super setUp.
40+
41+
repository := ExReqRepository new
42+
pragmaSelector: #ExReqSafePassingControl;
43+
yourself.
44+
report := repository asReport
45+
]
46+
47+
{ #category : 'running' }
48+
ExReqSafePassingControlTest >> tearDown [
49+
50+
super tearDown.
51+
self report removeTracingPoints.
52+
self report closeReport.
53+
repository := nil
54+
]
55+
56+
{ #category : 'tests' }
57+
ExReqSafePassingControlTest >> testNonLocalReturn [
58+
59+
| requirement requirementReport |
60+
self report installTracingPoints.
61+
ExReqMockTestObject new methodToTestTheNonLocalReturn.
62+
requirement := self req3.
63+
requirementReport := self report findRequirementReport: requirement.
64+
self assert: requirementReport isValid.
65+
self report removeTracingPoints
66+
]

src/ExecutableRequirements-Toplo-Example/ExReqToploLoginRequirements.class.st

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Class {
55
#package : 'ExecutableRequirements-Toplo-Example'
66
}
77

8-
{ #category : 'as yet unclassified' }
8+
{ #category : 'capella file' }
99
ExReqToploLoginRequirements >> capellaFile [
1010

1111
^ '<?xml version="1.0" encoding="UTF-8"?>
@@ -948,7 +948,7 @@ ExReqToploLoginRequirements >> capella_requirement_1 [
948948
<ExReqToploExample>
949949
^ ExReqRequirement new
950950
title:
951-
'Person send "preliminary informations" to Authentication app';
951+
'Person shall send "preliminary informations" to Authentication app';
952952
description:
953953
'The component named "Person"[a74ca346-8ba1-430e-8ca9-06c48d702ac5] in the function "Proof of identity"[6e26d3cf-5684-4117-ac88-17f5fb63eb0e] transmit "preliminary informations"[ae5df6ac-07ff-4177-8a1d-7f73b386dea8] to the component named "Input Identity UI"[300a7f2b-c0d2-48cd-854b-d9a8fcbadc24] in the function "Authentication app"[d68548ae-78af-44d6-85de-b5e5229541b5]';
954954
sourceDocument: (ExReqCapellaDocument new
@@ -1016,7 +1016,7 @@ ExReqToploLoginRequirements >> capella_requirement_3 [
10161016
yourself
10171017
]
10181018

1019-
{ #category : 'as yet unclassified' }
1019+
{ #category : 'step 4' }
10201020
ExReqToploLoginRequirements >> compiledSourceCodeIntoRequirementMethods [
10211021

10221022
| pragma methodPrefix sourceCodes index methodString |
@@ -1038,7 +1038,7 @@ ExReqToploLoginRequirements >> compiledSourceCodeIntoRequirementMethods [
10381038
self class compile: fullMethod classified: 'requirement - generated' ]
10391039
]
10401040

1041-
{ #category : 'as yet unclassified' }
1041+
{ #category : 'script' }
10421042
ExReqToploLoginRequirements >> openOnExample [
10431043

10441044
<script: 'ExReqToploLoginRequirements new openOnExample'>
@@ -1051,7 +1051,7 @@ ExReqToploLoginRequirements >> openOnExample [
10511051
open.
10521052
]
10531053

1054-
{ #category : 'as yet unclassified' }
1054+
{ #category : 'step 1' }
10551055
ExReqToploLoginRequirements >> transformCapellaFileIntoSimpleModel [
10561056

10571057
| project simple |
@@ -1068,13 +1068,13 @@ ExReqToploLoginRequirements >> transformCapellaFileIntoSimpleModel [
10681068
^ simple
10691069
]
10701070

1071-
{ #category : 'as yet unclassified' }
1071+
{ #category : 'step 3' }
10721072
ExReqToploLoginRequirements >> transformRequirementsIntoSourceCode [
10731073

10741074
^ self transformSimpleModelIntoRequirements collect: [ :each | Stash new serialize: each ]
10751075
]
10761076

1077-
{ #category : 'as yet unclassified' }
1077+
{ #category : 'step 2' }
10781078
ExReqToploLoginRequirements >> transformSimpleModelIntoRequirements [
10791079

10801080
^ self transformCapellaFileIntoSimpleModel asExReqRequirements

src/ExecutableRequirements/ExReqRepositoryReport.class.st

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,25 +84,35 @@ ExReqRepositoryReport >> closeReport [
8484
{ #category : 'as yet unclassified' }
8585
ExReqRepositoryReport >> createTracingPoints [
8686

87-
| stepReports nodeDictionary |
87+
| stepReports preconditionNodeDictionary postconditionNodeDictionary|
8888
"
8989
- Step1: Get all step reports.
90-
- Step2: Form a dictionary with all ast -> step reports .
91-
- Step3: Create all TracingPoint.
90+
- Step2: Create a dictionary with all ast -> step reports.
91+
- Step3: Create all PreconditionTracingPoint.
92+
- Step4: Create a dictionary with all ast & ast methodNode -> step reports.
93+
- Step5: Create all PostconditionTracingPoint.
9294
"
9395
stepReports := self requirementReports flatCollect: [ :req |
9496
req verificationReports flatCollect: #stepReports ].
95-
nodeDictionary := Dictionary new.
97+
preconditionNodeDictionary := Dictionary new.
98+
postconditionNodeDictionary := Dictionary new.
9699
stepReports do: [ :stepReport |
97-
nodeDictionary
100+
preconditionNodeDictionary
98101
at: stepReport step node
99102
ifPresent: [ :col | col add: stepReport ]
100-
ifAbsentPut: [ OrderedCollection with: stepReport ] ].
101-
self tracingPoints: (nodeDictionary values collect: [ :col |
102-
ExReqTracingPointContainer new
103-
stepReports: col;
104-
createTracingPoint;
105-
yourself ])
103+
ifAbsentPut: [ OrderedCollection with: stepReport ].
104+
postconditionNodeDictionary
105+
at: stepReport step node
106+
ifPresent: [ :col | col add: stepReport ]
107+
ifAbsentPut: [ Set with: stepReport ].
108+
postconditionNodeDictionary
109+
at: stepReport step node methodNode
110+
ifPresent: [ :col | col add: stepReport ]
111+
ifAbsentPut: [ Set with: stepReport ].
112+
].
113+
self tracingPoints: OrderedCollection new.
114+
self tracingPoints addAll: (preconditionNodeDictionary associations collect: [ :asso | ExReqTracingPoint installPreconditionOn: asso key withStepReports: asso value ]).
115+
self tracingPoints addAll: (postconditionNodeDictionary associations collect: [ :asso | ExReqTracingPoint installPostconditionOn: asso key withStepReports: asso value ]).
106116
]
107117

108118
{ #category : 'as yet unclassified' }
@@ -126,9 +136,7 @@ ExReqRepositoryReport >> initialize [
126136
ExReqRepositoryReport >> installTracingPoints [
127137

128138
self createTracingPoints.
129-
self tracingPoints do: [ :each |
130-
each preconditionTracingPoint install.
131-
each postconditionTracingPoint install ].
139+
self tracingPoints do: [ :each | each install ].
132140
self isInstalled: true.
133141
self isRunning: true.
134142
self annouceTracingPointInstalled
@@ -149,12 +157,10 @@ ExReqRepositoryReport >> isValid [
149157
{ #category : 'as yet unclassified' }
150158
ExReqRepositoryReport >> removeTracingPoints [
151159

152-
self tracingPoints do: [ :each |
153-
each preconditionTracingPoint remove.
154-
each postconditionTracingPoint remove ].
155-
self tracingPoints: {}.
160+
self tracingPoints do: [ :each | each remove ].
161+
self tracingPoints: { }.
156162
self isRunning: false.
157-
self annouceTracingPointRemoved.
163+
self annouceTracingPointRemoved
158164
]
159165

160166
{ #category : 'accessing' }

src/ExecutableRequirements/ExReqTracingPoint.class.st

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,62 @@ ExReqTracingPoint class >> all [
1919
^ TracingPoints ifNil: [ TracingPoints := Set new ]
2020
]
2121

22+
{ #category : 'as yet unclassified' }
23+
ExReqTracingPoint class >> installPostconditionOn: aNode withStepReports: aCollection [
24+
25+
| tracingPoint |
26+
tracingPoint := self
27+
tracingPointOn: aNode
28+
withStepReports: aCollection.
29+
tracingPoint bePostcondition.
30+
self installTracingPoint: tracingPoint withBehaviors: { }.
31+
^ tracingPoint
32+
]
33+
34+
{ #category : 'as yet unclassified' }
35+
ExReqTracingPoint class >> installPreconditionOn: aNode withStepReports: aCollection [
36+
37+
| tracingPoint |
38+
tracingPoint := self
39+
tracingPointOn: aNode
40+
withStepReports: aCollection.
41+
tracingPoint bePrecondition.
42+
self installTracingPoint: tracingPoint withBehaviors: { }.
43+
^ tracingPoint
44+
]
45+
46+
{ #category : 'as yet unclassified' }
47+
ExReqTracingPoint class >> installTracingPoint: dp withBehaviors: aListOfBehaviorClasses [
48+
49+
| ml |
50+
ml := dp metaLink.
51+
52+
dp link: ml.
53+
dp install.
54+
self add: dp.
55+
56+
"adding behaviors"
57+
aListOfBehaviorClasses do: [ :bhc | dp addBehavior: bhc new ].
58+
59+
^ dp
60+
]
61+
2262
{ #category : 'removing' }
2363
ExReqTracingPoint class >> remove: aDebugPoint [
2464

2565
self all remove: aDebugPoint ifAbsent: [ ].
2666
DebugPoint all remove: aDebugPoint ifAbsent: [ ].
2767
]
2868

69+
{ #category : 'as yet unclassified' }
70+
ExReqTracingPoint class >> tracingPointOn: aNode withStepReports: aCollection [
71+
72+
^ self new
73+
node: aNode;
74+
stepReports: aCollection;
75+
yourself
76+
]
77+
2978
{ #category : 'accessing' }
3079
ExReqTracingPoint >> bePostcondition [
3180

@@ -54,16 +103,6 @@ ExReqTracingPoint >> hitWithContext: aContext [
54103
^ true
55104
]
56105

57-
{ #category : 'API' }
58-
ExReqTracingPoint >> hitWithContext: aContext value: aValue [
59-
60-
(self hitWithContext: aContext) ifFalse: [ ^ self ].
61-
self enabled ifFalse: [ ^ self ].
62-
self enabled: false.
63-
self verifyStepsConditionWithContext: aContext.
64-
self enabled: true
65-
]
66-
67106
{ #category : 'accessing' }
68107
ExReqTracingPoint >> initialize [
69108

0 commit comments

Comments
 (0)