Skip to content

Commit

Permalink
Extracts Tonel support for coverage from SCIPharoCodeCoverage to SCIS…
Browse files Browse the repository at this point in the history
…queakTonelCodeCoverage and use it by default.
  • Loading branch information
marceltaeumel committed Jun 12, 2024
1 parent 25221dd commit 073df0d
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 3 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
as yet unclassified
isInTonelFormatCodeLocatedAt: aDirectoryName

| dir prop |
"1) First, look for a .properties file, assume STON format, and look for #format: #tonel."
(prop := (dir := FileDirectory on: aDirectoryName) / '.properties') exists ifTrue: [
prop readStreamDo: [ :stream | (STON fromStream: stream) at: #format ifPresent: [ :value | ^ value = #tonel ] ] ].

"2) Scan for a package directory with at least one having package.st."
dir entries do: [:projectEntry |
projectEntry isDirectory "= package" ifTrue: [
(projectEntry asFileDirectory / 'package.st') exists ifTrue: [^ true] ]].

^ false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
as yet unclassified
tonelFilePathFor: class in: aDirectoryName
| packageName packagePath |
packageName := self packageNameForClass: class.
packagePath := aDirectoryName , SmalltalkCI pathNameDelimiter , packageName.
^ (SmalltalkCI fileExists: packagePath)
ifTrue: [ packagePath , SmalltalkCI pathNameDelimiter , (self theNonMetaClassOf: class) name , '.class.st' ]
ifFalse: [ "This can be an extension. Currently not supported" SCIError signal: 'Extensions are unsupported in coverage' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
allClassesToCover

^ allClassesToCover ifNil: [ allClassesToCover := super allClassesToCover asArray ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coveralls
coverallsSourceFilesIn: projectDirectory

^ (self isInTonelFormat: projectDirectory)
ifTrue: [ self tonelCoverallsSourceFilesIn: projectDirectory ]
ifFalse: [ super coverallsSourceFilesIn: projectDirectory ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setup
finishUp

super finishUp.
coveredMethodsByClassName := coveredMethods groupBy: [ :method | method actualClass name ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
private
isInTonelFormat: projectDirectory

^ spec loading anySatisfy: [ :loadspec |
self class isInTonelFormatCodeLocatedAt: projectDirectory, SmalltalkCI pathNameDelimiter, loadspec directory ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setup
startUp

super startUp.
includedMethodsByClassName := includedMethods groupBy: [ :method | method actualClass name ].
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private
tonelCoverageFor: classToCover in: filePath
"The rationale of this method is to process the file line by line.
When a method start is found, get the coverage status of this method and apply it to the following lines until the method end.
When a method end is found reset the coverage status as excluded"

| coverageByLine coverageStatus inComment |
coverageByLine := OrderedCollection new.
coverageStatus := nil. "For coveralls nil represents an excluded line"
inComment := false.
(FileStream readOnlyFileNamed: filePath do: [ :stream | stream contents ])
linesDo: [ :line |
(line beginsWith: $" asString ) ifTrue: [ inComment := inComment not ].
(inComment not and: [line beginsWith: classToCover name])
ifTrue: [ "Start of method" coverageStatus := self tonelMethodCoverageStatusFor: line ].
coverageByLine add: coverageStatus.
(inComment not and: [line beginsWith: ']'])
ifTrue: [ "End Of Method" coverageStatus := nil ] ].
^ coverageByLine asArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
private
tonelCoverallsSourceFileFor: classToCover in: projectDirectory

| sourceDirectory filePath |
sourceDirectory := self tonelSourceDirectoryFor: projectDirectory.
filePath := self class tonelFilePathFor: classToCover in: sourceDirectory.
^ Dictionary
newFrom:
{('name' -> (self class relativeUnixPathOf: filePath to: projectDirectory)).
('source_digest' -> (self class md5Of: filePath)).
('coverage' -> (self tonelCoverageFor: classToCover in: filePath))}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
coveralls
tonelCoverallsSourceFilesIn: projectDirectory

| sourceFilesCoverage |
sourceFilesCoverage := OrderedCollection new.
self allClassesToCover
select: [ :class | class isMeta not ]
thenDo: [ :classToCover |
[ sourceFilesCoverage add: (self tonelCoverallsSourceFileFor: classToCover in: projectDirectory) ]
on: SCIError
do: [ :signal | signal return ] ].
^ sourceFilesCoverage asArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
private
tonelMethodCoverageStatusFor: methodDeclarationLine

"See http://docs.coveralls.io/api-reference for value mapping."

| selector methodDeclarationParts actualClassName |

methodDeclarationParts := methodDeclarationLine findTokens: '>>'.
actualClassName := methodDeclarationParts first withBlanksTrimmed.
selector := (Smalltalk globals at: #TonelParser) new extractSelector: (methodDeclarationParts last copyWithout: $]).

"Coveralls:
If the method is excluded -> nil
If the method is included and covered -> 1
If the method is inlcuded and uncovered -> 0"
^ (includedMethodsByClassName at: actualClassName ifAbsent: [ #() ])
detect: [ :methodReference | methodReference selector = selector ]
ifFound: [ :methodReference | (coveredMethodsByClassName at: actualClassName ifAbsent: [ #() ]) detect: [ :coveredMethod | coveredMethod = methodReference ] ifFound: [ 1 ] ifNone: [ 0 ] ]
ifNone: [ nil ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
private
tonelSourceDirectoryFor: projectDirectory
^ spec loading
detect:
[ :loadspec | SmalltalkCI fileExists: projectDirectory , SmalltalkCI pathNameDelimiter , loadspec directory ]
ifFound: [ :loadspec | projectDirectory , SmalltalkCI pathNameDelimiter , loadspec directory ]
ifNone: [ NotFound signal ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"class" : {
"isInTonelFormatCodeLocatedAt:" : "mt 6/12/2024 18:12",
"tonelFilePathFor:in:" : "mt 6/12/2024 17:34" },
"instance" : {
"allClassesToCover" : "mt 6/12/2024 17:38",
"coverallsSourceFilesIn:" : "mt 6/12/2024 17:37",
"finishUp" : "mt 6/12/2024 17:42",
"isInTonelFormat:" : "mt 6/12/2024 17:35",
"startUp" : "mt 6/12/2024 17:41",
"tonelCoverageFor:in:" : "mt 6/12/2024 18:19",
"tonelCoverallsSourceFileFor:in:" : "mt 6/12/2024 17:43",
"tonelCoverallsSourceFilesIn:" : "mt 6/12/2024 17:39",
"tonelMethodCoverageStatusFor:" : "mt 6/12/2024 18:17",
"tonelSourceDirectoryFor:" : "mt 6/12/2024 17:43" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"category" : "SmalltalkCI-Squeak-Core",
"classinstvars" : [
],
"classvars" : [
],
"commentStamp" : "",
"instvars" : [
"allClassesToCover",
"includedMethodsByClassName",
"coveredMethodsByClassName" ],
"name" : "SCISqueakTonelCodeCoverage",
"pools" : [
],
"super" : "SCISqueakCodeCoverage",
"type" : "normal" }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
compatibility
codeCoverageClass
^ SCISqueakCodeCoverage
^ SCISqueakTonelCodeCoverage
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"assureDirectoryExistence:" : "smalltalkCI 9/2/2020 15:57",
"chooseOptionFrom:title:" : "ct 5/25/2022 14:04",
"classesInPackage:" : "fn 11/23/2016 15:37",
"codeCoverageClass" : "fn 10/8/2016 14:57",
"codeCoverageClass" : "mt 6/12/2024 17:19",
"deleteFile:" : "fn 10/16/2016 16:14",
"deprecationWarning" : "fn 3/26/2018 14:56",
"extensionMethodsInPackage:" : "ct 9/29/2022 16:49",
Expand Down

Large diffs are not rendered by default.

0 comments on commit 073df0d

Please sign in to comment.