diff --git a/src/Microdown-BookTester-Tests/MicAnalysisReportWriterTest.class.st b/src/Microdown-BookTester-Tests/MicAnalysisReportWriterTest.class.st new file mode 100644 index 00000000..c6c48734 --- /dev/null +++ b/src/Microdown-BookTester-Tests/MicAnalysisReportWriterTest.class.st @@ -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 +] diff --git a/src/Microdown-BookTester-Tests/MicResultTest.class.st b/src/Microdown-BookTester-Tests/MicResultTest.class.st index 73065e4c..d1778b57 100644 --- a/src/Microdown-BookTester-Tests/MicResultTest.class.st +++ b/src/Microdown-BookTester-Tests/MicResultTest.class.st @@ -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 [ diff --git a/src/Microdown-BookTester/MicAnalysisReportWriter.class.st b/src/Microdown-BookTester/MicAnalysisReportWriter.class.st new file mode 100644 index 00000000..729123d1 --- /dev/null +++ b/src/Microdown-BookTester/MicAnalysisReportWriter.class.st @@ -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 +] diff --git a/src/Microdown-BookTester/MicBookTestResult.class.st b/src/Microdown-BookTester/MicBookTestResult.class.st index 2156351a..bfc13599 100644 --- a/src/Microdown-BookTester/MicBookTestResult.class.st +++ b/src/Microdown-BookTester/MicBookTestResult.class.st @@ -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' } diff --git a/src/Microdown-BookTester/MicBookTesterVisitor.class.st b/src/Microdown-BookTester/MicBookTesterVisitor.class.st index 5a947510..2171f555 100644 --- a/src/Microdown-BookTester/MicBookTesterVisitor.class.st +++ b/src/Microdown-BookTester/MicBookTesterVisitor.class.st @@ -6,7 +6,8 @@ Class { #superclass : 'MicrodownVisitor', #instVars : [ 'strategies', - 'results' + 'results', + 'reportWriter' ], #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' @@ -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 diff --git a/src/Microdown-BookTester/MicBrokenSyncDefinition.class.st b/src/Microdown-BookTester/MicBrokenSyncDefinition.class.st index 6ef526d5..4c79c62d 100644 --- a/src/Microdown-BookTester/MicBrokenSyncDefinition.class.st +++ b/src/Microdown-BookTester/MicBrokenSyncDefinition.class.st @@ -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 @@ -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 diff --git a/src/Microdown-BookTester/MicBrokenSyncOriginDefinition.class.st b/src/Microdown-BookTester/MicBrokenSyncOriginDefinition.class.st index 6bce4789..98d14c26 100644 --- a/src/Microdown-BookTester/MicBrokenSyncOriginDefinition.class.st +++ b/src/Microdown-BookTester/MicBrokenSyncOriginDefinition.class.st @@ -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 diff --git a/src/Microdown-BookTester/MicDesynchronizedCodeResult.class.st b/src/Microdown-BookTester/MicDesynchronizedCodeResult.class.st index dbbea4b8..bb067bc2 100644 --- a/src/Microdown-BookTester/MicDesynchronizedCodeResult.class.st +++ b/src/Microdown-BookTester/MicDesynchronizedCodeResult.class.st @@ -14,9 +14,10 @@ Class { #package : 'Microdown-BookTester' } -{ #category : 'accessing' } -MicDesynchronizedCodeResult >> bookContent [ - ^ bookContents +{ #category : 'kinds' } +MicDesynchronizedCodeResult class >> headerString [ + + ^ 'Desynchronized method body' ] { #category : 'accessing' } @@ -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 diff --git a/src/Microdown-BookTester/MicReferenceChecker.class.st b/src/Microdown-BookTester/MicReferenceChecker.class.st index 346f1c6e..4cd0b3ee 100644 --- a/src/Microdown-BookTester/MicReferenceChecker.class.st +++ b/src/Microdown-BookTester/MicReferenceChecker.class.st @@ -12,6 +12,9 @@ I use the FileCollector to support all the file input relations. This lets the user have for example unused, broken or underway files on the side. As soon as they are not used I do not analyse them. +I support the following API to be able to chained over a report writer: +- result/results: +- reportWriter: # todo @@ -21,6 +24,7 @@ Class { #name : 'MicReferenceChecker', #superclass : 'MicrodownVisitor', #instVars : [ + 'reportWriter', 'references', 'anchors', 'duplicatedAnchors', @@ -53,35 +57,6 @@ MicReferenceChecker >> addDuplicatedAnchor: anAnchor [ results add: micResultInstance ] -{ #category : 'reporting' } -MicReferenceChecker >> 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' } -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 . " @@ -181,7 +156,10 @@ MicReferenceChecker >> initialize [ results := OrderedCollection new. references := OrderedCollection new. anchors := OrderedCollection new. - duplicatedAnchors := OrderedCollection new + duplicatedAnchors := OrderedCollection new. + "by default if the reporter is not set from outside + then it shares the results of this current checker." + reportWriter := MicAnalysisReportWriter new results: results. ] { #category : 'testing' } @@ -202,31 +180,24 @@ MicReferenceChecker >> isOkay [ { #category : 'reporting' } MicReferenceChecker >> report [ - ^ String streamContents: [ :str | - self buildReportOn: str - ] + ^ reportWriter report ] { #category : 'reporting' } -MicReferenceChecker >> reportElementsOn: aStream [ - - results do: [ :each | aStream tab; nextPutAll: each explanation ] separatedBy: [ aStream cr ] - +MicReferenceChecker >> reportSTONFormat [ + ^ reportWriter reportSTONFormat ] -{ #category : 'reporting' } -MicReferenceChecker >> reportElementsSTONFormatOn: aList [ +{ #category : 'accessing' } +MicReferenceChecker >> reportWriter [ - results do: [ :each | aList add: each stonFormatExplanation ]. - + ^ reportWriter ] -{ #category : 'reporting' } -MicReferenceChecker >> reportSTONFormat [ +{ #category : 'accessing' } +MicReferenceChecker >> reportWriter: anObject [ - ^ String streamContents: [ :str | - self buildReportSTONFormatOn: str - ] + reportWriter := anObject ] { #category : 'accessing' } @@ -235,6 +206,12 @@ MicReferenceChecker >> results [ ^ results ] +{ #category : 'accessing' } +MicReferenceChecker >> results: anObject [ + + results := anObject +] + { #category : 'accessing' } MicReferenceChecker >> rootDirectory: aFileReferemce [ diff --git a/src/Microdown-Tests/MicrodownParserTest.class.st b/src/Microdown-Tests/MicrodownParserTest.class.st index dd91c8e3..bdeb040b 100644 --- a/src/Microdown-Tests/MicrodownParserTest.class.st +++ b/src/Microdown-Tests/MicrodownParserTest.class.st @@ -132,12 +132,12 @@ MicrodownParserTest >> testAnnotatedBlockBackwardCompatibleOnLongLine [ MicrodownParserTest >> testAnnotatedBlockBackwardCompatibleWithDifferentLabel [ | source root annotated | - source := '!!remark This is an important paragraph on one line.'. + source := '!!important This is an important paragraph on one line.'. root := parser parse: source. self assert: root children size equals: 1. annotated := root children first. self assert: annotated class equals: MicAnnotatedParagraphBlock. - self assert: annotated label equals: 'remark'. + self assert: annotated label equals: 'important'. self assert: annotated text equals: 'This is an important paragraph on one line.' diff --git a/src/Microdown/MicAbstractAnnotatedBlock.class.st b/src/Microdown/MicAbstractAnnotatedBlock.class.st index 44aa24c6..dc773c55 100644 --- a/src/Microdown/MicAbstractAnnotatedBlock.class.st +++ b/src/Microdown/MicAbstractAnnotatedBlock.class.st @@ -21,7 +21,7 @@ MicAbstractAnnotatedBlock >> addLineAndReturnNextNode: line [ ifNil: [ "this part is to be backward compatible and we will remove it in future releases" (line beginsWith: AnnotatedParagraphBackwardCompatibleMarkup) - ifTrue: [ self handleDoubleBangStartingLine: line ] + ifTrue: [ ^ self handleDoubleBangStartingLine: line ] ifFalse: [ | indexOfFirstClosingBracket | indexOfFirstClosingBracket := line indexOf: $].