Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report writer #879

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Class {
#name : 'MicAnalysisReportWriterTest',
#superclass : 'TestCase',
#category : 'Microdown-BookTester-Tests',
#package : 'Microdown-BookTester-Tests'
}

{ #category : 'tests' }
MicAnalysisReportWriterTest >> testWithEmptyResults [

self assert: MicAnalysisReportWriter new report isEmpty
]

{ #category : 'tests' }
MicAnalysisReportWriterTest >> testWithResults [

| reporter |
reporter := MicAnalysisReportWriter new
addResults: { MicBrokenSyncDefinition new };
addResults: { MicBrokenSyncOriginDefinition new }.
self assert: reporter results size equals: 2.
self deny: reporter report isEmpty
]
36 changes: 36 additions & 0 deletions src/Microdown-BookTester-Tests/MicResultTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,42 @@ MicResultTest >> testExplanationUndefinedAnchor [

]

{ #category : 'tests - basic result creation' }
MicResultTest >> testMicBookTestResultExplanationWorksWithEmptyInstance [

self flag: #improve.
"I do not like these tests that test string."
self
assert: MicBookTestResult new explanation
equals: 'test status: Passed
isExpectedFailure? false
Description of the test result : Test failed without raising an exception
the concerned code Block : here we should get an expression
from the source file: nil'
]

{ #category : 'tests - basic result creation' }
MicResultTest >> testMicBrokenSyncDefinitionResultExplanationWorksWithEmptyInstance [

self flag: #improve.
"I do not like these tests that test string."
self
assert: MicBrokenSyncDefinition new explanation
equals: 'The sync definition has the following broken value: empty .'
]

{ #category : 'tests - basic result creation' }
MicResultTest >> testResultCreation [

{ MicBookTestResult . MicBrokenSyncDefinition . MicBrokenSyncOriginDefinition . MicDesynchronizedCodeResult . MicDuplicatedAnchorResult . MicUndefinedAnchorResult . MicUndefinedFigureFileResult . MicUndefinedInputFileResult} do: [ :each | each new printString ]
]

{ #category : 'tests - basic result creation' }
MicResultTest >> testResultCreationSmokeTest [

{ MicBookTestResult . MicBrokenSyncDefinition . MicBrokenSyncOriginDefinition . MicDesynchronizedCodeResult . MicDuplicatedAnchorResult . MicUndefinedAnchorResult . MicUndefinedFigureFileResult . MicUndefinedInputFileResult} do: [ :each | each new printString ]
]

{ #category : 'tests' }
MicResultTest >> testSTONFormatExplanationDuplicatedAnchor [

Expand Down
98 changes: 98 additions & 0 deletions src/Microdown-BookTester/MicAnalysisReportWriter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"
I'm a little util classes that encapsulates writing reports about analyses.
"
Class {
#name : 'MicAnalysisReportWriter',
#superclass : 'Object',
#instVars : [
'results'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
}

{ #category : 'adding' }
MicAnalysisReportWriter >> addResults: aCollection [

results addAll: aCollection
]

{ #category : 'reporting' }
MicAnalysisReportWriter >> buildReportOn: str [

| dict |
dict := results groupedBy: [ :each | each class ].
dict keysAndValuesDo: [ :k :v |
str cr; nextPutAll: '## ' ;nextPutAll: k headerString; cr; cr.
self reportElementsOn: str.
str cr; cr.
]
]

{ #category : 'reporting' }
MicAnalysisReportWriter >> buildReportSTONFormatOn: str [

| dict list |
dict := results groupedBy: [ :each | each class ].
dict keysAndValuesDo: [ :k :v | |array|
array := Array new: 2.
list := OrderedCollection new.
self reportElementsSTONFormatOn: list.
list := list asArray.
array
at: 1 put: (Association new key: 'type' value: k errorType);
at: 2 put: list.
(String streamContents: [ :out | STON put: array onStream: str ])
]
]

{ #category : 'initialization' }
MicAnalysisReportWriter >> initialize [

super initialize.
results := OrderedCollection new
]

{ #category : 'reporting' }
MicAnalysisReportWriter >> report [

^ String streamContents: [ :str |
self buildReportOn: str
]
]

{ #category : 'reporting' }
MicAnalysisReportWriter >> reportElementsOn: aStream [

results
do: [ :each | aStream tab; nextPutAll: each explanation ]
separatedBy: [ aStream cr ]

]

{ #category : 'reporting' }
MicAnalysisReportWriter >> reportElementsSTONFormatOn: aList [

results do: [ :each | aList add: each stonFormatExplanation ].

]

{ #category : 'reporting' }
MicAnalysisReportWriter >> reportSTONFormat [

^ String streamContents: [ :str |
self buildReportSTONFormatOn: str
]
]

{ #category : 'accessing' }
MicAnalysisReportWriter >> results [

^ results
]

{ #category : 'accessing' }
MicAnalysisReportWriter >> results: anObject [

results := anObject
]
5 changes: 3 additions & 2 deletions src/Microdown-BookTester/MicBookTestResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ MicBookTestResult >> initialize [

super initialize.
status := true.
isExpectedFailure := false .
message := 'Test failed without raising an exception'
isExpectedFailure := false.
message := 'Test failed without raising an exception'.
text := 'here we should get an expression'
]

{ #category : 'accessing' }
Expand Down
21 changes: 20 additions & 1 deletion src/Microdown-BookTester/MicBookTesterVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Class {
#superclass : 'MicrodownVisitor',
#instVars : [
'strategies',
'results'
'results',
'reportWriter'
],
#category : 'Microdown-BookTester',
#package : 'Microdown-BookTester'
Expand Down Expand Up @@ -51,12 +52,30 @@ MicBookTesterVisitor >> isOk [
^ checkingVariable
]

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

^ reportWriter
]

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

reportWriter := anObject
]

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

^ results
]

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

results := anObject
]

{ #category : 'accessing' }
MicBookTesterVisitor >> start: anObject [
anObject accept: self
Expand Down
13 changes: 13 additions & 0 deletions src/Microdown-BookTester/MicBrokenSyncDefinition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicBrokenSyncDefinition class >> headerString [

^ 'Broken sync definition [should be sync=''true|false'''
]

{ #category : 'building' }
MicBrokenSyncDefinition >> codeBlock: aMicCodeBlock [
codeBlock := aMicCodeBlock
Expand All @@ -29,6 +35,13 @@ MicBrokenSyncDefinition >> explanation [
^ 'The sync definition has the following broken value: ', syncValue, ' .'
]

{ #category : 'initialization' }
MicBrokenSyncDefinition >> initialize [

super initialize.
syncValue := 'empty'
]

{ #category : 'accessing' }
MicBrokenSyncDefinition >> syncValue [
^ syncValue
Expand Down
18 changes: 18 additions & 0 deletions src/Microdown-BookTester/MicBrokenSyncOriginDefinition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicBrokenSyncOriginDefinition class >> headerString [

^ 'Broken sync origin specification [ should be C [class]>>#selector ]'
]

{ #category : 'accessing' }
MicBrokenSyncOriginDefinition >> explanation [

^ 'The sync origin in the definition is bogus it should be C [class]>> #selector and we get: ', origin
]

{ #category : 'accessing' }
MicBrokenSyncOriginDefinition >> initialize [
super initialize.
origin := 'C [class]>>#selector'
]

{ #category : 'accessing' }
MicBrokenSyncOriginDefinition >> originString: aString [
origin := aString
Expand Down
18 changes: 15 additions & 3 deletions src/Microdown-BookTester/MicDesynchronizedCodeResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'accessing' }
MicDesynchronizedCodeResult >> bookContent [
^ bookContents
{ #category : 'kinds' }
MicDesynchronizedCodeResult class >> headerString [

^ 'Desynchronized method body'
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -45,6 +46,17 @@ MicDesynchronizedCodeResult >> imageContents [
^ imageContents
]

{ #category : 'initialization' }
MicDesynchronizedCodeResult >> initialize [

super initialize.
bookContents := 'book contents'.
imageContents := 'image contents'.
originString := 'C [class]>>#selector'.
pharoVersion := '>12'

]

{ #category : 'accessing' }
MicDesynchronizedCodeResult >> originString [
^ originString
Expand Down
Loading
Loading