-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(analysis.stateaccess): integration with other analyzers
- Loading branch information
1 parent
665183a
commit e6f40b9
Showing
7 changed files
with
173 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
analysis/src/test/scala/org/polystat/odin/analysis/DetectAccessTests.scala
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
analysis/src/test/scala/org/polystat/odin/analysis/DetectStateAccessTests.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.polystat.odin.analysis | ||
|
||
import cats.effect._ | ||
import org.scalatest.wordspec.AnyWordSpec | ||
import org.polystat.odin.parser.EoParser.sourceCodeEoParser | ||
import cats.effect.unsafe.implicits.global | ||
import org.polystat.odin.analysis.EOOdinAnalyzer.directStateAccessAnalyzer | ||
import EOOdinAnalyzer.OdinAnalysisResult._ | ||
|
||
class DetectStateAccessTests extends AnyWordSpec { | ||
case class TestCase(label: String, code: String, expected: List[String]) | ||
|
||
def analyze(code: String): IO[List[String]] = EOOdinAnalyzer | ||
.analyzeSourceCode[String, IO](directStateAccessAnalyzer)(code)( | ||
cats.Monad[IO], | ||
sourceCodeEoParser() | ||
) | ||
.flatMap { | ||
case Ok(_) => IO.pure(List.empty) | ||
case DefectDetected(_, errors) => IO.pure(errors.toList) | ||
case AnalyzerFailure(_, e) => IO.raiseError(e) | ||
} | ||
|
||
val testsWithDefect: List[TestCase] = List( | ||
TestCase( | ||
label = "Improper access to state", | ||
code = """[] > a | ||
| memory > state | ||
| [self new_state] > update_state | ||
| self.state.write new_state > @ | ||
|[] > b | ||
| a > @ | ||
| [self new_state] > change_state_plus_two | ||
| self.state.write (new_state.add 2) > @ | ||
|""".stripMargin, | ||
expected = List( | ||
"Method 'change_state_plus_two' of object 'b' directly accesses state 'state' of base class 'a'" | ||
) | ||
) | ||
) | ||
|
||
val testsWithoutDefect: List[TestCase] = List( | ||
TestCase( | ||
label = "Proper access to state", | ||
code = """[] > a | ||
| memory > state | ||
| [self new_state] > update_state | ||
| self.state.write new_state > @ | ||
|[] > b | ||
| a > @ | ||
| [self new_state] > change_state_plus_two | ||
| new_state.add 2 > tmp | ||
| self.update_state self tmp > @ | ||
|""".stripMargin, | ||
expected = List() | ||
) | ||
) | ||
|
||
def runTests(tests: List[TestCase]): Unit = | ||
tests.foreach { case TestCase(label, code, expected) => | ||
registerTest(label) { | ||
val obtained = analyze(code).unsafeRunSync() | ||
assert(obtained == expected) | ||
} | ||
} | ||
|
||
"analyzer" should { | ||
"find errors" should { | ||
runTests(testsWithDefect) | ||
} | ||
|
||
"not find errors" should { | ||
runTests(testsWithoutDefect) | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.