Skip to content

Commit

Permalink
Write test cases for all suppression levels - #6
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbosch committed May 4, 2017
1 parent 1e01f62 commit 44cf09f
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ enum class Case(val file: String) {
NestedClasses("/cases/NestedClasses.kt"),
NestedLongMethods("/cases/NestedLongMethods.kt"),
FeatureEnvy("/cases/FeatureEnvy.kt"),
SuppressedElements("/SuppressedElements.kt");
SuppressedElements("/SuppressedByElementAnnotation.kt"),
SuppressedElementsByFile("/SuppressedElementsByFileAnnotation.kt"),
SuppressedElementsByClass("/SuppressedElementsByClassAnnotation.kt");

fun path(): Path {
val resource = Case::class.java.getResource(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.jetbrains.spek.api.dsl.it
*/
class SuppressingSpec : Spek({

it("all findings are suppressed on different levels") {
it("all findings are suppressed on element levels") {
val ktFile = compileForTest(Case.SuppressedElements.path())
val ruleSet = RuleSet("Test", listOf(LongMethod(), LongParameterList(), ComplexCondition()))
val findings = ruleSet.accept(ktFile)
Expand All @@ -24,4 +24,24 @@ class SuppressingSpec : Spek({
assertThat(findings).hasSize(0)
}

it("all findings are suppressed on file levels") {
val ktFile = compileForTest(Case.SuppressedElementsByFile.path())
val ruleSet = RuleSet("Test", listOf(LongMethod(), LongParameterList(), ComplexCondition()))
val findings = ruleSet.accept(ktFile)
findings.forEach {
println(it.compact())
}
assertThat(findings).hasSize(0)
}

it("all findings are suppressed on class levels") {
val ktFile = compileForTest(Case.SuppressedElementsByClass.path())
val ruleSet = RuleSet("Test", listOf(LongMethod(), LongParameterList(), ComplexCondition()))
val findings = ruleSet.accept(ktFile)
findings.forEach {
println(it.compact())
}
assertThat(findings).hasSize(0)
}

})
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("unused")

/**
* @author Artur Bosch
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @author Artur Bosch
*/
@Suppress("unused", "LongMethod", "LongParameterList", "ComplexCondition")
class SuppressedElements3 {

fun lpl(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) = (a + b + c + d + e + f).apply {
assert(false) { "FAILED TEST" }
}

fun cc() {
if (this is SuppressedElements3 && this !is Any && this is Nothing && this is SuppressedElements3) {
assert(false) { "FAIL" }
}
}

fun lm() {
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
assert(false) { "FAILED TEST" }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@file:Suppress("unused", "LongMethod", "LongParameterList", "ComplexCondition")

/**
* @author Artur Bosch
*/

fun lpl2(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) = (a + b + c + d + e + f).apply {
assert(false) { "FAILED TEST" }
}

class SuppressedElements2 {

fun lpl(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) = (a + b + c + d + e + f).apply {
assert(false) { "FAILED TEST" }
}

fun cc() {
if (this is SuppressedElements2 && this !is Any && this is Nothing && this is SuppressedElements2) {
assert(false) { "FAIL" }
}
}

fun lm() {
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
lpl(1, 2, 3, 4, 5, 6)
assert(false) { "FAILED TEST" }
}

}

0 comments on commit 44cf09f

Please sign in to comment.