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

Added a progress bar as a logger #117

Merged
merged 17 commits into from
May 6, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ MTCoveragePropagationPreparationTest >> testWorking [
analysis := MTAnalysis new
testClasses: { MTCIHelperTest };
classesToMutate: { MTCIHelper };
budget: MTFreeBudget new.
budget: MTFreeBudget new;
logger: MTNullLogger new.
analysis run.

moreInfo := MTCoveragePropagationPreparation new
Expand Down
59 changes: 41 additions & 18 deletions src/MuTalk-Model/MTAnalysis.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MTAnalysis >> defaultBudget [
{ #category : 'accessing - defaults' }
MTAnalysis >> defaultLogger [

^ MTTranscriptLogger new
^ MTProgressBarLogger new
]

{ #category : 'accessing - defaults' }
Expand Down Expand Up @@ -117,42 +117,49 @@ MTAnalysis >> generalResult [
{ #category : 'running' }
MTAnalysis >> generateCoverageAnalysis [

logger logStartCoverageAnalysis.
logger logStartCoverageAnalysis: testCases size.
coverageAnalysisResult := (MTCoverageAnalysis
for: methodsToMutate
running: testCases)
run;
result
result.
logger logEndCoverageAnalysis
]

{ #category : 'running' }
MTAnalysis >> generateMutations [

logger logStartMutationGeneration.
logger logStartMutationGeneration: self methodSize.
^ mutations ifNil: [
mutations := mutantGenerationStrategy
mutationsFor: self
loggingIn: logger.
logger logTotalNumberOfMutations: mutations.
logger
logTotalNumberOfMutations: mutations;
logEndMutationGeneration.
mutations ]
]

{ #category : 'running' }
MTAnalysis >> generateResults [

mutantResults := OrderedCollection new.
logger logStartMutationEvaluation.
logger logStartMutationEvaluation: mutations.

mutations do: [ :aMutation |
(budget exceedsBudgetOn: mutantResults fromTotalMutations: mutations)
ifTrue: [ ^ mutantResults ].
logger logStartEvaluating: aMutation.
logger logStartEvaluating: aMutation with: testCases size.

mutantResults add: ((MTMutantEvaluation
for: aMutation
using: testCases
following: testSelectionStrategy
andConsidering: self coverageAnalysisResult)
valueStoppingOnError: stopOnErrorOrFail) ].
valueStoppingOnError: stopOnErrorOrFail).
logger logEndEvaluating ].

logger logEndMutationEvaluation.
logger logEnd.
^ mutantResults
]
Expand All @@ -161,7 +168,10 @@ MTAnalysis >> generateResults [
MTAnalysis >> initialTestRun [
"Runs all tests once and filters them"

testCases do: [ :aTestCase | aTestCase run ].
| results |
logger logStartInitialTestRun: testCases size.
results := testCases collect: [ :aTestCase | aTestCase run ].
logger logEndInitialTestRun.

"The test filter is initialized lazily here because the default one needs the run time of tests, so the initial test run must be executed first"
testCases := self testFilter filterTests: testCases.
Expand Down Expand Up @@ -198,6 +208,12 @@ MTAnalysis >> logger: anObject [
logger := anObject
]

{ #category : 'as yet unclassified' }
MTAnalysis >> methodSize [

^ (self modelClasses flatCollect: #methods) size
]

{ #category : 'accessing' }
MTAnalysis >> methodsToMutate [

Expand Down Expand Up @@ -292,16 +308,23 @@ MTAnalysis >> run [
those classes) and execute all mutants in the set of testClases.
We obtain a result for each mutant generated"

self initialTestRun.

"The budget is started after the initial test run because the default one needs the run time of tests"
budget start.
logger logAnalysisStartFor: self.

elapsedTime := [
self generateCoverageAnalysis.
self generateMutations.
self generateResults ] timeToRun
logger logAnalysisStart.
self initialTestRun.
self startBudget.
[
self generateCoverageAnalysis.
self generateMutations.
self generateResults ] timeToRun ] ensure: [
logger release ]
]

{ #category : 'starting' }
MTAnalysis >> startBudget [
"The budget is initialized here because the default one needs the run time of tests, so the initial test run must be executed first"

budget ifNil: [ budget := self defaultBudget ].
budget start
]

{ #category : 'accessing' }
Expand Down
60 changes: 55 additions & 5 deletions src/MuTalk-Model/MTAnalysisLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
}

{ #category : 'logging' }
MTAnalysisLogger >> logAnalysisStartFor: aMutationTestingAnalysis [
MTAnalysisLogger >> logAnalysisStart [
self subclassResponsibility
]

Expand All @@ -17,6 +17,36 @@ MTAnalysisLogger >> logEnd [
^ self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logEndCoverageAnalysis [

^ self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logEndEvaluating [

self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logEndInitialTestRun [

self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logEndMutationEvaluation [

self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logEndMutationGeneration [

self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logNumberOfGeneratedMutations: aNumber [

Expand All @@ -35,24 +65,31 @@ MTAnalysisLogger >> logStartBuildingMutantionsFor: aCompiledMethod using: aMutan
]

{ #category : 'logging' }
MTAnalysisLogger >> logStartCoverageAnalysis [
MTAnalysisLogger >> logStartCoverageAnalysis: testSize [

^ self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logStartEvaluating: aMethodMutation [
MTAnalysisLogger >> logStartEvaluating: aMethodMutation with: testSize [

self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logStartInitialTestRun: testSize [

self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logStartMutationEvaluation [
MTAnalysisLogger >> logStartMutationEvaluation: mutants [

^ self subclassResponsibility
]

{ #category : 'logging' }
MTAnalysisLogger >> logStartMutationGeneration [
MTAnalysisLogger >> logStartMutationGeneration: methodSize [

^ self subclassResponsibility
]
Expand All @@ -62,3 +99,16 @@ MTAnalysisLogger >> logTotalNumberOfMutations: mutations [

^ self subclassResponsibility
]

{ #category : 'private' }
MTAnalysisLogger >> methodNameOf: aCompiledMethod [

^ aCompiledMethod methodClass name asString , '>>'
, aCompiledMethod selector printString
]

{ #category : 'dependencies' }
MTAnalysisLogger >> release [

"Hook for subclasses. Called after the analysis is done, either because of success of exception/unwind"
]
6 changes: 6 additions & 0 deletions src/MuTalk-Model/MTFileLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ MTFileLogger >> initializeToFileNamed: aString [
fileReference := aString asFileReference.
self initialize
]

{ #category : 'dependencies' }
MTFileLogger >> release [

stream close
]
1 change: 1 addition & 0 deletions src/MuTalk-Model/MTMethodMutation.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ MTMethodMutation >> printOn: aStream [
MTMethodMutation >> runMutantStoppingOnError: aBoolean in: anEvaluation [

| testResults brokenTests |
"1halt."
[
EpMonitor disableDuring: [
testResults := [
Expand Down
12 changes: 5 additions & 7 deletions src/MuTalk-Model/MTMutantGenerationStrategy.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ MTMutantGenerationStrategy >> mutationsFor: aMutationTestingAnalysis loggingIn:

| mutations |
mutations := OrderedCollection new.
(self methodsToMutateFrom: aMutationTestingAnalysis)
do: [ :aMethod |
mutations addAll: (self
mutationsFor: aMethod
usingAll: aMutationTestingAnalysis operators
logginIn: aLogger) ]
displayingProgress: 'Building Mutants'.
(self methodsToMutateFrom: aMutationTestingAnalysis) do: [ :aMethod |
mutations addAll: (self
mutationsFor: aMethod
usingAll: aMutationTestingAnalysis operators
logginIn: aLogger) ].
^ mutantSelectionStrategy shuffleMutants: mutations
]

Expand Down
54 changes: 51 additions & 3 deletions src/MuTalk-Model/MTNullLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,43 @@ MTNullLogger class >> new [
]

{ #category : 'logging' }
MTNullLogger >> logAnalysisStartFor: aMutationTestingAnalysis [
MTNullLogger >> logAnalysisStart [
]

{ #category : 'logging' }
MTNullLogger >> logEnd [


]

{ #category : 'logging' }
MTNullLogger >> logEndCoverageAnalysis [


]

{ #category : 'logging' }
MTNullLogger >> logEndEvaluating [


]

{ #category : 'logging' }
MTNullLogger >> logEndInitialTestRun [


]

{ #category : 'logging' }
MTNullLogger >> logEndMutationEvaluation [


]

{ #category : 'logging' }
MTNullLogger >> logEndMutationGeneration [


]

{ #category : 'logging' }
Expand All @@ -42,7 +72,7 @@ MTNullLogger >> logStartBuildingMutantionsFor: aCompiledMethod using: aMutantOpe
]

{ #category : 'logging' }
MTNullLogger >> logStartCoverageAnalysis [
MTNullLogger >> logStartCoverageAnalysis: testSize [


]
Expand All @@ -52,7 +82,19 @@ MTNullLogger >> logStartEvaluating: aMethodMutation [
]

{ #category : 'logging' }
MTNullLogger >> logStartMutationEvaluation [
MTNullLogger >> logStartEvaluating: aMethodMutation with: testSize [


]

{ #category : 'logging' }
MTNullLogger >> logStartInitialTestRun: testSize [


]

{ #category : 'logging' }
MTNullLogger >> logStartMutationEvaluation: mutants [


]
Expand All @@ -61,6 +103,12 @@ MTNullLogger >> logStartMutationEvaluation [
MTNullLogger >> logStartMutationGeneration [


]

{ #category : 'logging' }
MTNullLogger >> logStartMutationGeneration: methodSize [


]

{ #category : 'logging' }
Expand Down
Loading
Loading