Skip to content

Commit

Permalink
Merge pull request #867 from moufort/861-Emit-checker-results-in-ston…
Browse files Browse the repository at this point in the history
…-format-too-

Issue 861 emit checker results in ston format too
  • Loading branch information
Ducasse authored Aug 28, 2024
2 parents 0587e24 + a8f6552 commit 3d38378
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,44 @@ MicReferenceCheckerTest >> testRefersToUnkAncS1 [
self assert: visitor results first source equals: '/fileRefAncS1.md'
]

{ #category : 'tests - duplicated' }
MicReferenceCheckerTest >> testReportingSTONFormatDuplicatedAnchors [

| defAncS0TripleAncS1RefAncS1AncS0 checker |
defAncS0TripleAncS1RefAncS1AncS0 := self defAncS0TripleAncS1RefAncS1AncS0.
checker := MicReferenceChecker new.
checker checkList: { defAncS0TripleAncS1RefAncS1AncS0 }.

self assert: checker reportSTONFormat equals: '[''type'':''DuplicatedAnchor'',[''ancS1'':''/myDirectory/defAncS0TripleAncS1RefAncS1AncS0.md'',''ancS1'':''/myDirectory/defAncS0TripleAncS1RefAncS1AncS0.md'']]'


]

{ #category : 'tests - duplicated' }
MicReferenceCheckerTest >> testReportingSTONFormatDuplicatedFigure [

| checker |
self fileRefAncS1.
checker := MicReferenceChecker new.
checker rootDirectory: dir.
checker checkProject: refAncS1.

self assert: checker reportSTONFormat equals: '[''type'':''UndefinedAnchor'',[''ancS1'':''/fileRefAncS1.md'']]'
]

{ #category : 'tests - duplicated' }
MicReferenceCheckerTest >> testReportingSTONFormatUnknownAnchorDir [

| checker |
self fileRefAncS1.
checker := MicReferenceChecker new.
checker rootDirectory: dir.
checker checkProject: refAncS1.

self assert: checker reportSTONFormat equals: '[''type'':''UndefinedAnchor'',[''ancS1'':''/fileRefAncS1.md'']]'

]

{ #category : 'skipped for now' }
MicReferenceCheckerTest >> testReportingUnknownAnchorDir [

Expand Down
38 changes: 38 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,44 @@ MicResultTest >> testExplanationUndefinedAnchor [

]

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

| res association |
res := MicDuplicatedAnchorResult new.
res anchorLabel: 'ancS0'.
"pay attention since in this package fromFile is pass a fullName and not a file we will have to change
this later"
res source: '/myDir/chapter1.md'.

association := res stonFormatExplanation.

self
assert: (association isKindOf: Association );
assert: association key equals: 'ancS0';
assert: association value equals: '/myDir/chapter1.md'

]

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

| res association |
res := MicUndefinedAnchorResult new.
res anchorLabel: 'ancS0'.
"pay attention since in this package fromFile is pass a fullName and not a file we will have to change
this later"
res source: '/myDir/chapter1.md'.

association := res stonFormatExplanation.

self
assert: (association isKindOf: Association );
assert: association key equals: 'ancS0';
assert: association value equals: '/myDir/chapter1.md'

]

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

Expand Down
13 changes: 13 additions & 0 deletions src/Microdown-BookTester/MicAnchorResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicAnchorResult class >> errorType [

^ 'UndefinedAnchor'
]

{ #category : 'accessing' }
MicAnchorResult >> anchorLabel [

Expand All @@ -31,3 +37,10 @@ MicAnchorResult >> explanation [
MicAnchorResult >> isWhat [
^ 'undefined'
]

{ #category : 'accessing' }
MicAnchorResult >> stonFormatExplanation [

^ Association new key: anchorLabel value: source

]
23 changes: 23 additions & 0 deletions src/Microdown-BookTester/MicBookTestResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ MicBookTestResult >> isValid [
^ status
]

{ #category : 'accessing' }
MicBookTestResult >> stonFormatExplanation [

^ '{', String cr , '"status" : "',
(self class allMessages at: self status asString) asString ,'",',
String cr ,
'"isExpectedFailure" : "',
self isExpectedFailure asString ,'",',
String cr ,
'"Description" : "' ,
self message asString ,'",',
String cr ,
'"codeBlock" : "',
self text , '",',
String cr ,
'"sourceFile" : "' ,
self source asString , '"',
String cr , '}'



]

{ #category : 'accessing' }
MicBookTestResult >> text [

Expand Down
6 changes: 6 additions & 0 deletions src/Microdown-BookTester/MicDuplicatedAnchorResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicDuplicatedAnchorResult class >> errorType [

^ 'DuplicatedAnchor'
]

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

Expand Down
7 changes: 7 additions & 0 deletions src/Microdown-BookTester/MicFileResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ MicFileResult >> explanation [

]

{ #category : 'accessing' }
MicFileResult >> stonFormatExplanation [

^ '"', self what,'" : "', source , '"'

]

{ #category : 'accessing' }
MicFileResult >> what [

Expand Down
32 changes: 32 additions & 0 deletions src/Microdown-BookTester/MicReferenceChecker.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ MicReferenceChecker >> addDuplicatedAnchor: anAnchor [
MicReferenceChecker >> buildReportOn: str [

| dict |

dict := results groupedBy: [ :each | each class ].
dict keysAndValuesDo: [ :k :v |
str cr; nextPutAll: '## ' ;nextPutAll: k headerString; cr; cr.
Expand All @@ -65,6 +66,22 @@ MicReferenceChecker >> buildReportOn: str [
]
]

{ #category : 'reporting' }
MicReferenceChecker >> 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 : 'main API' }
MicReferenceChecker >> checkDirectory: aDir [
"Take the directory, parse all its children with microdown file parser and let the visitor visit each time then return visitor is ok which should be true if every thing is okay, the visitor turned out to treat the many documents that it visits as one, so if anchor is duplicated in another file it will detect that . "
Expand Down Expand Up @@ -197,6 +214,21 @@ MicReferenceChecker >> reportElementsOn: aStream [

]

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

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

]

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

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

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

Expand Down
12 changes: 12 additions & 0 deletions src/Microdown-BookTester/MicResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicResult class >> errorType [

^ self subclassResponsibility
]

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

Expand Down Expand Up @@ -70,3 +76,9 @@ MicResult >> status: anObject [

status := anObject
]

{ #category : 'accessing' }
MicResult >> stonFormatExplanation [

^ self subclassResponsibility
]
6 changes: 6 additions & 0 deletions src/Microdown-BookTester/MicUndefinedAnchorResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicUndefinedAnchorResult class >> errorType [

^ 'UndefinedAnchor'
]

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicUndefinedFigureFileResult class >> errorType [

^ 'UndefinedFigureFiles:'
]

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

Expand Down
6 changes: 6 additions & 0 deletions src/Microdown-BookTester/MicUndefinedInputFileResult.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Class {
#package : 'Microdown-BookTester'
}

{ #category : 'kinds' }
MicUndefinedInputFileResult class >> errorType [

^ 'UndefinedInputFiles'
]

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

Expand Down

0 comments on commit 3d38378

Please sign in to comment.