From 948ac50beb25397d5c2211f743a32843e727de4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Thu, 12 Sep 2024 15:38:23 +0200 Subject: [PATCH] - make the file collector returns the list of files. - rename the api visitedDocumentFiles --- .../MicFileCollectorTest.class.st | 16 +++++------ .../MicAnalysisReportWriter.class.st | 6 ++++ .../MicFileCollector.class.st | 28 ++++++++++++------- .../MicReferenceChecker.class.st | 7 +++-- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st b/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st index 0c0c490f..3e09f911 100644 --- a/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st +++ b/src/Microdown-BookTester-Tests/MicFileCollectorTest.class.st @@ -29,7 +29,7 @@ MicFileCollectorTest >> testDoubleLoopsAndThatUnexistingInputIsCorrectlyResolved self startVisitingFromTheRoot: section2. self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: Set <- { '/myDirectory/section1.md' . @@ -61,7 +61,7 @@ MicFileCollectorTest >> testFileCollectorHandlesLoopFromSection3ToMain [ section4" self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: { '/myDirectory/section1.md' . @@ -82,7 +82,7 @@ MicFileCollectorTest >> testLoopOfFilesReferencingEachOther [ self startVisitingFromTheRoot: section1. self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: Set <- { '/myDirectory/section1.md'. @@ -97,7 +97,7 @@ MicFileCollectorTest >> testMultipleReferencesOfFileThatDoesNotExist [ self startVisitingFromTheRoot: section1. self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: Set <- { '/myDirectory/section1.md' . @@ -119,7 +119,7 @@ MicFileCollectorTest >> testMultipleReferencesToTheSameFile [ self startVisitingFromTheRoot: section1. self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: { '/myDirectory/section1.md'. '/myDirectory/sections/section2.md' . '/myDirectory/sections/section4.md' } asSet @@ -132,7 +132,7 @@ MicFileCollectorTest >> testOnlyGoDownInFolders [ self startVisitingFromTheRoot: section1. self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: Set <- { '/myDirectory/section1.md' . @@ -149,7 +149,7 @@ MicFileCollectorTest >> testOnlyGoUpInFoldersStartingFromAnotherRoot [ self startVisitingFromTheRoot: section4. self - assert: visitor visitedDocumentFiles + assert: visitor visitedFileStrings equals: Set <- { '/myDirectory/section1.md'. @@ -166,7 +166,7 @@ MicFileCollectorTest >> testUnreferencedFileAreNotHandled [ self createProjectWithUnreferencedFiles3And5. self startVisitingFromTheRoot: section1. - self assert: visitor visitedDocumentFiles equals: Set + self assert: visitor visitedFileStrings equals: Set <- { '/myDirectory/section1.md'. '/myDirectory/sections/section2.md'. '/myDirectory/sections/section4.md' } diff --git a/src/Microdown-BookTester/MicAnalysisReportWriter.class.st b/src/Microdown-BookTester/MicAnalysisReportWriter.class.st index 729123d1..526908c1 100644 --- a/src/Microdown-BookTester/MicAnalysisReportWriter.class.st +++ b/src/Microdown-BookTester/MicAnalysisReportWriter.class.st @@ -53,6 +53,12 @@ MicAnalysisReportWriter >> initialize [ results := OrderedCollection new ] +{ #category : 'testing' } +MicAnalysisReportWriter >> isOkay [ + + ^ results isEmpty +] + { #category : 'reporting' } MicAnalysisReportWriter >> report [ diff --git a/src/Microdown-BookTester/MicFileCollector.class.st b/src/Microdown-BookTester/MicFileCollector.class.st index 197c3a8b..a5ebfa20 100644 --- a/src/Microdown-BookTester/MicFileCollector.class.st +++ b/src/Microdown-BookTester/MicFileCollector.class.st @@ -14,21 +14,23 @@ Class { #superclass : 'MicrodownVisitor', #instVars : [ 'rootDirectory', - 'visited', 'unexistingFiles', - 'inputFiles' + 'inputFiles', + 'visitedFileStrings', + 'visitedFiles' ], #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' } -{ #category : 'visiting' } +{ #category : 'initialization' } MicFileCollector >> initialize [ super initialize. rootDirectory := FileSystem workingDirectory. - visited := Set new. + visitedFileStrings := Set new. unexistingFiles := Set new. + visitedFiles := OrderedCollection new. ] { #category : 'accessing' } @@ -65,9 +67,10 @@ MicFileCollector >> visitRoot: micDocument [ [ worklist isEmpty ] whileFalse: [ | currentDocument | currentDocument := worklist removeFirst. - visited add: currentDocument fromFile. + visitedFileStrings add: currentDocument fromFile. currentDocument resolveYourself. - + visitedFiles add: currentDocument. + inputFiles := OrderedCollection new. "treat all the inputFile from the current document" self visitChildrenOf: currentDocument. @@ -81,8 +84,7 @@ MicFileCollector >> visitRoot: micDocument [ "Since we are just checking that a file exist it does not matter when we check. We do not have to wait until we walk through all the files." - - (visited includes: fr path pathString) ifFalse: [ + (visitedFileStrings includes: fr path pathString) ifFalse: [ [ doc := Microdown parseFile: fr. worklist addFirst: doc ] @@ -91,7 +93,13 @@ MicFileCollector >> visitRoot: micDocument [ ] { #category : 'accessing' } -MicFileCollector >> visitedDocumentFiles [ +MicFileCollector >> visitedFileStrings [ + + ^ visitedFileStrings +] + +{ #category : 'accessing' } +MicFileCollector >> visitedFiles [ - ^ visited + ^ visitedFiles ] diff --git a/src/Microdown-BookTester/MicReferenceChecker.class.st b/src/Microdown-BookTester/MicReferenceChecker.class.st index 4cd0b3ee..6afd3736 100644 --- a/src/Microdown-BookTester/MicReferenceChecker.class.st +++ b/src/Microdown-BookTester/MicReferenceChecker.class.st @@ -29,7 +29,8 @@ Class { 'anchors', 'duplicatedAnchors', 'results', - 'rootDirectory' + 'rootDirectory', + 'listOfFiles' ], #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' @@ -78,14 +79,14 @@ MicReferenceChecker >> checkList: aCollection [ { #category : 'main API' } MicReferenceChecker >> checkProject: aFileReference [ - | mainMic collector listOfFiles | + | mainMic collector | mainMic := Microdown parseFile: aFileReference. collector := MicFileCollector new. collector rootDirectory: rootDirectory; visit: mainMic. self handleUndefinedFilesFrom: collector. - listOfFiles := collector visitedDocumentFiles collect: [ :file | + listOfFiles := collector visitedFileStrings collect: [ :file | rootDirectory resolve: file ]. self checkList: listOfFiles ]