Skip to content

Commit

Permalink
Add plugin for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-seifert committed Jun 2, 2018
1 parent 333965b commit d8316bb
Show file tree
Hide file tree
Showing 24 changed files with 191 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A disharmony is a design problem in a software, as for instance a class that holds much data but no logic (considered as a data class).

I offer some disharmony detecting tests.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test-data
basicClasses
"Classes that should not cause Tradition Breaker"

^ {
Object. ProtoObject. Class. Behavior. Model. Morph
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-data
classNamesNotUnderTest
^ {self name asString}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defaults
defaultCategory

^ 'Disharmonies II'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests
offeredTestsData

^ {
{#myPrecedence. 'Precedence Test'. 'A+B*C should maybe be A+(B*C).'}.
{ #myTest . nil .nil . SwaLint hiddenCategory}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests
brainClass: aSLClassTestObject

aSLClassTestObject shouldBeClass.

^ self successResult:
(((aSLClassTestObject resultOf: #weightedMethodCount) >= #veryHigh) and:
[(aSLClassTestObject resultOf: #tightClassCohesion) < 0.5] and:
[self looksLikeBrainClass: aSLClassTestObject])
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests
brainMethod: aSLMethodTestObject

aSLMethodTestObject ifClassTestChildrenWith: #brainMethod.
aSLMethodTestObject shouldBeMethod.
^ self successResult:
((self isExcessivelyLarge: aSLMethodTestObject) and:
[self looksLikeBrainMethod: aSLMethodTestObject])
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests
dataClass: aSLClassTestObject

aSLClassTestObject shouldBeClass.

^ self successResult:
(((aSLClassTestObject resultOf: #weightOfClass) < (1/3)) and:
[self looksLikeDataClass: aSLClassTestObject])
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests
dispersedCoupling: aSLMethodTestObject

aSLMethodTestObject ifClassTestChildrenWith: #dispersedCoupling.
aSLMethodTestObject shouldBeMethod.
^ self successResult:
((self looksLikeDispersedCoupling: aSLMethodTestObject) and:
[ (aSLMethodTestObject resultOf: #maxNesting) > #one ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests
featureEnvy: aSLMethodTestObject

aSLMethodTestObject ifClassTestChildrenWith: #featureEnvy.
aSLMethodTestObject shouldBeMethod.

^ self successResult:
(((aSLMethodTestObject resultOf: #methodATFD) > #few) and:
[ (aSLMethodTestObject resultOf: #methodLAA) < (1/3) ] and:
[ (aSLMethodTestObject resultOf: #methodFDP) <= #few ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests
godClass: aSLClassTestObject

aSLClassTestObject shouldBeClass.
^ self successResult:
(((aSLClassTestObject resultOf: #accessToForeignData) > #few) and:
[((aSLClassTestObject resultOf: #weightedMethodCount) >= #veryHigh) and:
[(aSLClassTestObject resultOf: #tightClassCohesion) <= (1/3)]])
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests
intensiveCoupling: aSLMethodTestObject

aSLMethodTestObject ifClassTestChildrenWith: #intensiveCoupling.
aSLMethodTestObject shouldBeMethod.
^ self successResult:
((self looksLikeIntensiveCoupling: aSLMethodTestObject) and:
[ (aSLMethodTestObject resultOf: #maxNesting) > #one ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialize-release
loadPreferences

" self loadPreferences: #(AverageLOCperMethodAVRG
ClassLOCAVRG ClassLOCSTDEV WMCAVRG WMCSTDEV).
self loadPreferenceCategory: #Disharmony."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests
myPrecedence: aSLClassTestObject
aSLClassTestObject shouldBeClass.
^ self
summarizeNumberOf: aSLClassTestObject methods
withResultOf: #myTest
satisfying: [:result | result isPositive]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
tests
myTest: aMethodTestObject
|methodNode b|
aMethodTestObject shouldBeMethod.

methodNode := RBParser parseMethod: (aMethodTestObject sourceCode)." ('method0
1+2.
^12')."
b := false.
methodNode body statements do: [:statement|
Transcript show: statement selector.
Transcript show: ((#(#select:) includes: (statement selector))).
b := b or: ((#(#select:) includes: (statement selector))).].
^self booleanResult: b

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests
shotgunSurgery: aSLMethodTestObject

aSLMethodTestObject ifClassTestChildrenWith: #shotgunSurgery.
aSLMethodTestObject shouldBeMethod.

^ self successResult:
((aSLMethodTestObject resultOf: #methodCM) > self class ShortMemoryCap and:
[(aSLMethodTestObject resultOf: #methodCC) > #many])
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
significantDuplication: aSLMethodTestObject

| significantDuplications |

aSLMethodTestObject ifClassTestChildrenWith: #significantDuplication.
aSLMethodTestObject shouldBeMethod.

significantDuplications := aSLMethodTestObject testSystem significantDuplicationUnseenMethods select: [ :each |
((self significantDuplicationChain: aSLMethodTestObject with: each) or:
[ self significantStandaloneExactClone: aSLMethodTestObject with: each ])].
aSLMethodTestObject testSystem significantDuplicationUnseenMethods
remove: aSLMethodTestObject.
^ self methodListResult: significantDuplications
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests
traditionBreaker: aSLClassTestObject

aSLClassTestObject shouldBeClass.

^ self successResult:
((self excessiveInterfaceIncrease: aSLClassTestObject) and:
[ self substantialSizeAndComplexity: aSLClassTestObject ] and:
[ self parentNeitherSmallNorDumb: aSLClassTestObject ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"class" : {
"basicClasses" : "topa 1/9/2015 16:17",
"classNamesNotUnderTest" : "BD 5/25/2018 12:35",
"defaultCategory" : "Lars Seifert 6/1/2018 15:38",
"offeredTestsData" : "Lars Seifert 6/1/2018 16:44" },
"instance" : {
"brainClass:" : "MB 6/17/2014 12:59",
"brainMethod:" : "AT 5/27/2008 00:48",
"dataClass:" : "AT 5/27/2008 19:19",
"dispersedCoupling:" : "MT 7/23/2014 22:59",
"featureEnvy:" : "MT 7/23/2014 23:00",
"godClass:" : "topa 12/7/2012 14:18",
"intensiveCoupling:" : "MT 7/23/2014 23:02",
"loadPreferences" : "HD 7/9/2014 19:36",
"myPrecedence:" : "Lars Seifert 6/1/2018 16:43",
"myTest:" : "Lars Seifert 6/1/2018 17:34",
"shotgunSurgery:" : "topa 1/9/2015 19:59",
"significantDuplication:" : "topa 1/18/2015 22:06",
"traditionBreaker:" : "MT 7/23/2014 23:13" } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"category" : "SwaLint-PlugIns",
"classinstvars" : [
],
"classvars" : [
"LargeClassLOC",
"LargeMethodLOC",
"LargeWeightedMethodCount",
"MinimumDuplicationChainLength",
"MinimumExactCloneSize",
"ShortMemoryCap",
"SignificantStandaloneExactCloneSize",
"SmallLineBias" ],
"commentStamp" : "<historical>",
"instvars" : [
],
"name" : "SLOtherPlugIn",
"pools" : [
],
"super" : "SLPlugIn",
"type" : "normal" }
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ magicNumbers: aSLThing
^ SLSmallLintPlugIn new
test: aSLThing
with: (SLTestData newNamed: #smallLintLiteralValuesSpelling)"


Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"instanceVariableAccessIsConsistent:" : "BD 5/15/2018 15:23",
"interestingMethods:" : "tfel 1/10/2011 13:38",
"isUnclassifiedMethod:" : "tfel 1/10/2011 14:04",
"magicNumbers:" : "BD 5/15/2018 15:28",
"magicNumbers:" : "Lars Seifert 6/2/2018 17:40",
"metaProgramming:" : "BD 5/15/2018 14:59",
"methodHandlesNil:" : "tfel 3/3/2011 14:34",
"methodHasComment:" : "topa 11/26/2012 18:08",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
as yet unclassified
method1: a
^a+5
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
"class" : {
},
"instance" : {
"method0" : "BD 5/18/2018 14:48" } }
"method0" : "BD 5/18/2018 14:48",
"method1:" : "Lars Seifert 6/1/2018 17:35" } }

0 comments on commit d8316bb

Please sign in to comment.