Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ package org.polystat.odin.analysis

import org.polystat.odin.analysis.mutualrec.advanced.CallGraph._
import org.polystat.odin.analysis.mutualrec.advanced.Program._
import org.scalatest.wordspec.AnyWordSpec

class CallGraphTests extends AnyWordSpec {
class CallChainTests extends munit.FunSuite {

val cc1: CallChain = List("a" % "s", "a" % "b", "a" % "d")
val cc2: CallChain = List("a" % "b", "a" % "d", "a" % "s")

test("be shift-equivalent") {
assert(cc1 isShiftOf cc2)
assert(cc2 isShiftOf cc1)
}

}

class CallGraphTests extends munit.FunSuite {

val exampleCgBefore: CallGraph = Map(
"a" % "s" -> Set("a" % "b"),
"a" % "b" -> Set("a" % "d"),
Expand All @@ -32,63 +40,65 @@ class CallGraphTests extends AnyWordSpec {
val exampleNoCycles: CallGraph =
exampleCgBefore.updated("a" % "d", Set("a" % "f"))

"call graph" should {
"correctly detect cycles" in {
assert(!exampleNoCycles.containsCycles)
assert(exampleCgBefore.containsCycles)
assert(!exampleCgExtends.containsCycles)
assert(exampleCgAfter.containsCycles)
}

"correctly extend another call graph" in {

assert(exampleCgBefore.extendWith(exampleCgExtends).size == 5)
assert(exampleCgBefore.extendWith(exampleCgExtends) == exampleCgAfter)
assert(
exampleCgBefore.extendWith(exampleCgExtends) !=
exampleCgExtends.extendWith(exampleCgBefore)
)
test("correctly detect cycles") {
assert(!exampleNoCycles.containsCycles)
assert(exampleCgBefore.containsCycles)
assert(!exampleCgExtends.containsCycles)
assert(exampleCgAfter.containsCycles)
}

}
"correctly find cycles" in {
val cycles: Set[CallChain] = Set(
List(
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s")
),
List(
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b")
),
List(
MethodName(ObjectName("a"), "c"),
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b")
),
List(
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d")
)
test("correctly extend another call graph") {

assert(exampleCgBefore.extendWith(exampleCgExtends).size == 5)
assert(exampleCgBefore.extendWith(exampleCgExtends) == exampleCgAfter)
assert(
exampleCgBefore.extendWith(exampleCgExtends) !=
exampleCgExtends.extendWith(exampleCgBefore)
)

}

test("correctly find cycles") {
val cycles: Set[CallChain] = Set(
List(
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s")
),
List(
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b")
),
List(
MethodName(ObjectName("a"), "c"),
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b")
),
List(
MethodName(ObjectName("a"), "d"),
MethodName(ObjectName("a"), "s"),
MethodName(ObjectName("a"), "b"),
MethodName(ObjectName("a"), "d")
)
)

assert(exampleCgBefore.findCycles.toSet == cycles)
}
assert(exampleCgBefore.findCycles.toSet == cycles)
}

"call chain" should {
"be shift-equivalent" in {
assert(cc1 isShiftOf cc2)
assert(cc2 isShiftOf cc1)
}
test("correctly extend another call graph") {

assert(exampleCgBefore.extendWith(exampleCgExtends).size == 5)
assert(exampleCgBefore.extendWith(exampleCgExtends) == exampleCgAfter)
assert(
exampleCgBefore.extendWith(exampleCgExtends) !=
exampleCgExtends.extendWith(exampleCgBefore)
)

}

//
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.polystat.odin.analysis

import cats.effect._
import cats.effect.unsafe.implicits.global
import org.polystat.odin.analysis.EOOdinAnalyzer.directStateAccessAnalyzer
import org.polystat.odin.parser.EoParser.sourceCodeEoParser
import org.scalatest.wordspec.AnyWordSpec

import EOOdinAnalyzer.OdinAnalysisResult._

class DetectStateAccessTests extends AnyWordSpec {
class DetectStateAccessTests extends munit.CatsEffectSuite {
case class TestCase(label: String, code: String, expected: List[String])

def analyze(code: String): IO[List[String]] = EOOdinAnalyzer
Expand Down Expand Up @@ -382,23 +380,16 @@ class DetectStateAccessTests extends AnyWordSpec {
)
)

def runTests(tests: List[TestCase]): Unit =
def runTests(prefix: String)(tests: List[TestCase]): Unit =
tests.foreach { case TestCase(label, code, expected) =>
registerTest(label) {
val obtained = analyze(code).unsafeRunSync()
assert(obtained == expected)
test(prefix + label) {
val obtained = analyze(code)
assertIO(obtained, expected)
}
}

"analyzer" should {
"find errors" should {
runTests(testsWithDefect)
}

"not find errors" should {
runTests(testsWithoutDefect)
}
runTests("find errors")(testsWithDefect)

}
runTests("not find errors")(testsWithoutDefect)

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.polystat.odin.analysis

import cats.effect._
import cats.effect.unsafe.implicits.global
import org.polystat.odin.analysis.EOOdinAnalyzer.OdinAnalysisResult._
import org.polystat.odin.parser.EoParser.sourceCodeEoParser
import org.scalatest.wordspec.AnyWordSpec

import EOOdinAnalyzer.liskovPrincipleViolationAnalyzer

class LiskovPrincipleTests extends AnyWordSpec {
class LiskovPrincipleTests extends munit.CatsEffectSuite {

case class TestCase(label: String, code: String, expected: List[String])

Expand Down Expand Up @@ -249,23 +247,17 @@ class LiskovPrincipleTests extends AnyWordSpec {
)
)

def runTests(tests: List[TestCase]): Unit =
def runTests(prefix: String)(tests: List[TestCase]): Unit =
tests.foreach { case TestCase(label, code, expected) =>
registerTest(label) {
val obtained = analyze(code).unsafeRunSync()
assert(obtained == expected)
test(prefix + label) {
val obtained = analyze(code)
assertIO(obtained, expected)
}

}

"analyzer" should {
"find errors" should {
runTests(testCasesWithErrors)
}
runTests("find errors - ")(testCasesWithErrors)

"not find errors" should {
runTests(testCasesWithoutErrors)
}
}
runTests("not find errors - ")(testCasesWithoutErrors)

}
Loading