Skip to content

Commit

Permalink
- Rename the class CodeBlockValidator
Browse files Browse the repository at this point in the history
- Retagging
- Fixing explanation
- ready for cli
  • Loading branch information
Ducasse committed Sep 12, 2024
1 parent 948ac50 commit c3060ad
Show file tree
Hide file tree
Showing 21 changed files with 91 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {
MicBookTesterVisitorTest >> parseAndTest: docText [
| doc bTester |
doc := Microdown parse: docText.
bTester := MicBookTesterVisitor new.
bTester := MicCodeBlockValidator new.
bTester start: doc.
^ bTester
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ MicMethodBodySyncTest >> parseAndTest: docText [

| doc bTester |
doc := Microdown parse: docText.
bTester := MicBookTesterVisitor new.
bTester := MicCodeBlockValidator new.
bTester start: doc.
^ bTester
]
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicAnalysisReportWriter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Class {
#instVars : [
'results'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'adding' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicAnchorResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Class {
#instVars : [
'anchorLabel'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicBookTestResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ Class {
#classInstVars : [
'allMessages'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'initialization' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicBookTesterNullStrategy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ When there is no tag other than none or language, does not verify the code block
Class {
#name : 'MicBookTesterNullStrategy',
#superclass : 'MicBookTesterStrategy',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'hook' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicBookTesterStrategy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Class {
#instVars : [
'results'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'hook' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicBrokenSyncDefinition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ Class {
'syncValue',
'codeBlock'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Class {
'origin',
'codeBlock'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
i visit code blocks and make sure that evaluation is correct
"
Class {
#name : 'MicBookTesterVisitor',
#name : 'MicCodeBlockValidator',
#superclass : 'MicrodownVisitor',
#instVars : [
'strategies',
'results',
'reportWriter'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'testing' }
MicBookTesterVisitor class >> isAbstract [
MicCodeBlockValidator class >> isAbstract [
<ignoreForCoverage "This method is ignored for test coverage because it is overriden in all subclasses and these subclasses don't need to do a super-send.">
^ false
]

{ #category : 'initialization' }
MicBookTesterVisitor >> collectStrategies [
MicCodeBlockValidator >> collectStrategies [

MicBookTesterStrategy allSubclasses do: [ :each |
| strat |
Expand All @@ -30,13 +31,13 @@ MicBookTesterVisitor >> collectStrategies [
]

{ #category : 'visiting' }
MicBookTesterVisitor >> failedTests [
MicCodeBlockValidator >> failedTests [

^ results select: [ :each | each isFailed ]
]

{ #category : 'initialization' }
MicBookTesterVisitor >> initialize [
MicCodeBlockValidator >> initialize [

super initialize.
results := OrderedCollection new.
Expand All @@ -45,51 +46,51 @@ MicBookTesterVisitor >> initialize [
]

{ #category : 'visiting' }
MicBookTesterVisitor >> isOk [
MicCodeBlockValidator >> isOk [
| checkingVariable |
checkingVariable := true.
results do: [ :each | checkingVariable := checkingVariable and: [ each isMicPaired ] ].
^ checkingVariable
]

{ #category : 'accessing' }
MicBookTesterVisitor >> reportWriter [
MicCodeBlockValidator >> reportWriter [

^ reportWriter
]

{ #category : 'accessing' }
MicBookTesterVisitor >> reportWriter: anObject [
MicCodeBlockValidator >> reportWriter: anObject [

reportWriter := anObject
]

{ #category : 'visiting' }
MicBookTesterVisitor >> results [
MicCodeBlockValidator >> results [

^ results
]

{ #category : 'accessing' }
MicBookTesterVisitor >> results: anObject [
MicCodeBlockValidator >> results: anObject [

results := anObject
]

{ #category : 'accessing' }
MicBookTesterVisitor >> start: anObject [
MicCodeBlockValidator >> start: anObject [
anObject accept: self

]

{ #category : 'testing' }
MicBookTesterVisitor >> validTests [
MicCodeBlockValidator >> validTests [

^ results select: [ :each | each isValid ]
]

{ #category : 'visiting' }
MicBookTesterVisitor >> visitCode: aCodeBlock [
MicCodeBlockValidator >> visitCode: aCodeBlock [
"Creates an instance of PRBookTestResult with parameters depending of the type of the codeblock."

(strategies keys includes: aCodeBlock mainExtensionTag)
Expand Down
7 changes: 4 additions & 3 deletions src/Microdown-BookTester/MicDesynchronizedCodeResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ Class {
'imageContents',
'pharoVersion'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand All @@ -33,7 +34,7 @@ MicDesynchronizedCodeResult >> bookContents: aString [
{ #category : 'accessing' }
MicDesynchronizedCodeResult >> explanation [

^ 'The code block body of ', originString , ' is not in sync with the version in Pharo ', pharoVersion, 'in file: ', source fromFile fullName
^ 'The code block body of ', originString , ' is not in sync with the version in Pharo ', pharoVersion, 'in file: ', source fromFile
]

{ #category : 'accessing' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Class {
#name : 'MicDuplicatedAnchorResult',
#superclass : 'MicAnchorResult',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicExampleTesterStrategy.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Class {
#name : 'MicExampleTesterStrategy',
#superclass : 'MicBookTesterStrategy',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'hook' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicFileCollector.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Class {
'visitedFileStrings',
'visitedFiles'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'initialization' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicFileResult.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Class {
#name : 'MicFileResult',
#superclass : 'MicResult',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'accessing' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicReferenceChecker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ Class {
'rootDirectory',
'listOfFiles'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'accessing' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ Class {
'source',
'explanation'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
37 changes: 21 additions & 16 deletions src/Microdown-BookTester/MicSyncTesterStrategy.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Class {
#name : 'MicSyncTesterStrategy',
#superclass : 'MicBookTesterStrategy',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Analysis',
#package : 'Microdown-BookTester',
#tag : 'Analysis'
}

{ #category : 'hook' }
Expand Down Expand Up @@ -49,27 +50,31 @@ MicSyncTesterStrategy >> verify: aCodeBlock [
ifFalse: [ self handleBrokenSyncValue: syncValue of: aCodeBlock ]
ifTrue: [

originString := aCodeBlock arguments at: #origin.
originString := aCodeBlock arguments at: #origin.

splits := originString splitOn: '>>'.
( splits size = 2 )
ifFalse: [ self handleBrokenOrigin: originString of: aCodeBlock ]
ifTrue: [
| class |
splits := originString splitOn: '>>'.
( splits size = 2 )
ifFalse: [ self halt.self handleBrokenOrigin: originString of: aCodeBlock ]
ifTrue: [
| class |

className := splits first splitOn: Character space.
isMeta := false.
className size = 2
ifTrue: [ isMeta := className second trimBoth.
isMeta := isMeta = 'class' ].
class := Smalltalk globals at: className first asSymbol ifAbsent: [ ^ self handleBrokenOrigin: originString of: aCodeBlock ].
className := splits first splitOn: Character space.
isMeta := false.
className size = 2
ifTrue: [ isMeta := className second trimBoth.
isMeta := isMeta = 'class' ].
class := Smalltalk globals
at: className first asSymbol
ifAbsent: [ self halt. ^ self handleBrokenOrigin: originString of: aCodeBlock ].
isMeta
ifTrue: [ class := class class ].

class
compiledMethodAt: splits second allButFirst asSymbol
compiledMethodAt: splits second trimBoth allButFirst asSymbol
ifPresent: [ :m | method := m ]
ifAbsent: [ ^ self handleBrokenOrigin: originString of: aCodeBlock ].
ifAbsent: [ self halt. ^ self
handleBrokenOrigin: originString
of: aCodeBlock ].

aCodeBlock body = method sourceCode ifFalse: [
results add: (MicDesynchronizedCodeResult new
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicUndefinedAnchorResult.class.st
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Class {
#name : 'MicUndefinedAnchorResult',
#superclass : 'MicAnchorResult',
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Class {
#instVars : [
'figureFileString'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicUndefinedInputFileResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Class {
#instVars : [
'inputFileBlock'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
#category : 'Microdown-BookTester-Results',
#package : 'Microdown-BookTester',
#tag : 'Results'
}

{ #category : 'kinds' }
Expand Down

0 comments on commit c3060ad

Please sign in to comment.