Skip to content
Snippets Groups Projects
Commit d3629399 authored by SeeBasTStick's avatar SeeBasTStick
Browse files

added tests

parent 6c4ec778
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,6 @@ import com.google.gson.Gson ...@@ -5,7 +5,6 @@ import com.google.gson.Gson
import com.google.gson.JsonObject import com.google.gson.JsonObject
/** /**
* Takes a json and tries to cast it into a settings objects * Takes a json and tries to cast it into a settings objects
* @param json the json object * @param json the json object
...@@ -18,7 +17,6 @@ fun castJsonToSetting(json : JsonObject) : Settings { ...@@ -18,7 +17,6 @@ fun castJsonToSetting(json : JsonObject) : Settings {
Gson().fromJson(json.get("performanceHints"), Boolean::class.java), Gson().fromJson(json.get("performanceHints"), Boolean::class.java),
Gson().fromJson(json.get("probHome"), String::class.java), Gson().fromJson(json.get("probHome"), String::class.java),
Gson().fromJson(json.get("debugMode"), Boolean::class.java)) Gson().fromJson(json.get("debugMode"), Boolean::class.java))
} }
...@@ -5,25 +5,22 @@ import org.eclipse.lsp4j.Diagnostic ...@@ -5,25 +5,22 @@ import org.eclipse.lsp4j.Diagnostic
import org.eclipse.lsp4j.DiagnosticSeverity import org.eclipse.lsp4j.DiagnosticSeverity
import org.eclipse.lsp4j.Position import org.eclipse.lsp4j.Position
import org.eclipse.lsp4j.Range import org.eclipse.lsp4j.Range
import java.io.BufferedWriter
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStreamWriter
fun convertErrorItems(errorItems: List<ErrorItem>) : List<Diagnostic>{ fun convertErrorItems(errorItems: List<ErrorItem>) : List<Diagnostic>{
return errorItems.toList().map { errorItem -> return errorItems.toList().map { errorItem ->
errorItem.locations.map { location -> errorItem.locations.map { location ->
Diagnostic(Range(Position(location.startLine - 1, location.startColumn), Position(location.endLine - 1, location.endColumn)), Diagnostic(Range(
Position(location.startLine - 1, location.startColumn),
Position(location.endLine - 1, location.endColumn)),
errorItem.message, errorItem.message,
getErrorItemType(errorItem), getErrorItemType(errorItem.type),
location.filename) location.filename)
} }
}.flatten() }.flatten()
} }
fun getErrorItemType(errorItem: ErrorItem) : DiagnosticSeverity{ fun getErrorItemType(errorItem: ErrorItem.Type) : DiagnosticSeverity{
return when(errorItem.type){ return when(errorItem){
ErrorItem.Type.ERROR -> { ErrorItem.Type.ERROR -> {
DiagnosticSeverity.Error DiagnosticSeverity.Error
} }
......
package b.language.server
import org.eclipse.lsp4j.MessageActionItem
import org.eclipse.lsp4j.MessageParams
import org.eclipse.lsp4j.PublishDiagnosticsParams
import org.eclipse.lsp4j.ShowMessageRequestParams
import org.eclipse.lsp4j.services.LanguageClient
import java.util.concurrent.CompletableFuture
class Client : LanguageClient {
/**
* The telemetry notification is sent from the server to the client to ask
* the client to log a telemetry event.
*/
override fun telemetryEvent(`object`: Any?) {
TODO("Not yet implemented")
}
/**
* Diagnostics notifications are sent from the server to the client to
* signal results of validation runs.
*/
override fun publishDiagnostics(diagnostics: PublishDiagnosticsParams?) {
TODO("Not yet implemented")
}
/**
* The show message notification is sent from a server to a client to ask
* the client to display a particular message in the user interface.
*/
override fun showMessage(messageParams: MessageParams?) {
println("hi")
}
/**
* The show message request is sent from a server to a client to ask the
* client to display a particular message in the user interface. In addition
* to the show message notification the request allows to pass actions and
* to wait for an answer from the client.
*/
override fun showMessageRequest(requestParams: ShowMessageRequestParams?): CompletableFuture<MessageActionItem> {
TODO("Not yet implemented")
}
/**
* The log message notification is send from the server to the client to ask
* the client to log a particular message.
*/
override fun logMessage(message: MessageParams?) {
TODO("Not yet implemented")
}
}
\ No newline at end of file
package b.language.server
class ProBCommandLineTest{
/*
@Test
fun test_readProblems(@TempDir tempPath : File = File("tmp"))
{
val file = File(tempPath.path+"/tmp.txt")
val problemToWrite = Problem(message = "Test", file = "test.mch", reason = "test reason", version = "test",
start = Position(1,1), end = Position(1,1), type = "test")
file.writeText(Gson().toJson(problemToWrite))
val problems = ProBCommandLineAccess().readProblems(file.path)
val problem = problems.first()
assertEquals(problemToWrite.version, problem.version)
assertEquals(problemToWrite.end.col, problem.end.col)
assertEquals(problemToWrite.end.line, problemToWrite.end.line)
assertEquals(problemToWrite.start.col, problem.start.col)
assertEquals(problemToWrite.start.line, problemToWrite.start.line)
assertEquals(problemToWrite.file, problem.file)
assertEquals(problemToWrite.message, problem.message)
assertEquals(problemToWrite.reason, problem.reason)
}
@Test
fun test_buildCommand_everything_activated(@TempDir tempPath : File = File("tmp")){
val testSettings = Settings()
val tempFile = File(tempPath.path+"/m.mch")
val command = ProBCommandLineAccess().buildCommand(testSettings, tempFile, tempPath)
assertEquals("~/prob_prolog/probcli.sh -p MAX_INITIALISATIONS 0 " +
"-version " +
"-p PERFORMANCE_INFO TRUE " +
"-p STRICT_CLASH_CHECKING TRUE " +
"-p TYPE_CHECK_DEFINITIONS TRUE -lint " +
"-wd-check -release_java_parser ${tempFile.path} " +
"-p NDJSON_ERROR_LOG_FILE $tempPath", command)
}
@Test
fun test_buildCommand_everything_not_strict(@TempDir tempPath : File = File("tmp")){
val testSettings = Settings(strictChecks = false)
val tempFile = File(tempPath.path+"/m.mch")
val command = ProBCommandLineAccess().buildCommand(testSettings, tempFile, tempPath)
assertEquals("~/prob_prolog/probcli.sh -p MAX_INITIALISATIONS 0 " +
"-version " +
"-p PERFORMANCE_INFO TRUE " +
"-wd-check -release_java_parser ${tempFile.path} " +
"-p NDJSON_ERROR_LOG_FILE $tempPath", command)
}
@Test
fun test_buildCommand_everything_not_wd(@TempDir tempPath : File = File("tmp")){
val testSettings = Settings(wdChecks = false)
val tempFile = File(tempPath.path+"/m.mch")
val command = ProBCommandLineAccess().buildCommand(testSettings, tempFile, tempPath)
assertEquals("~/prob_prolog/probcli.sh -p MAX_INITIALISATIONS 0 " +
"-version " +
"-p PERFORMANCE_INFO TRUE " +
"-p STRICT_CLASH_CHECKING TRUE " +
"-p TYPE_CHECK_DEFINITIONS TRUE -lint " +
"${tempFile.path} " +
"-p NDJSON_ERROR_LOG_FILE $tempPath", command)
}
@Test
fun test_buildCommand_everything_not_performanceHints(@TempDir tempPath : File = File("tmp")){
val testSettings = Settings(performanceHints = false)
val tempFile = File(tempPath.path+"/m.mch")
val command = ProBCommandLineAccess().buildCommand(testSettings, tempFile, tempPath)
assertEquals("~/prob_prolog/probcli.sh -p MAX_INITIALISATIONS 0 " +
"-version " +
"-p STRICT_CLASH_CHECKING TRUE " +
"-p TYPE_CHECK_DEFINITIONS TRUE -lint " +
"-wd-check -release_java_parser ${tempFile.path} " +
"-p NDJSON_ERROR_LOG_FILE $tempPath", command)
}
@Test
fun test_transformProblems_negative_range(){
val problemFile = "test.mch"
val message = "Test"
val version = "test"
val testProblem = Problem(message = message, file = problemFile, reason = "test reason", version = version,
start = Position(-1,-1), end = Position(-1,-1), type = "error")
val transformedProblem = ProBCommandLineAccess().transformProblems(listOf(testProblem)).first()
val diagnostic = Diagnostic(Range(
org.eclipse.lsp4j.Position(1,0),
org.eclipse.lsp4j.Position(1, Integer.MAX_VALUE)), message, DiagnosticSeverity.Error, problemFile, " probcli v.$version" )
assertEquals(diagnostic, transformedProblem)
}
@Test
fun test_transformProblems_error(){
val problemFile = "test.mch"
val message = "Test"
val version = "test"
val testProblem = Problem(message = message, file = problemFile, reason = "test reason", version = version,
start = Position(32,54), end = Position(54,65), type = "error")
val transformedProblem = ProBCommandLineAccess().transformProblems(listOf(testProblem)).first()
val diagnostic = Diagnostic(Range(
org.eclipse.lsp4j.Position(31,54),
org.eclipse.lsp4j.Position(53, 65)), message, DiagnosticSeverity.Error, problemFile, " probcli v.$version" )
assertEquals(diagnostic, transformedProblem)
}
@Test
fun test_transformProblems_warning(){
val problemFile = "test.mch"
val message = "Test"
val version = "test"
val testProblem = Problem(message = message, file = problemFile, reason = "test reason", version = version,
start = Position(32,54), end = Position(54,65), type = "warning")
val transformedProblem = ProBCommandLineAccess().transformProblems(listOf(testProblem)).first()
val diagnostic = Diagnostic(Range(
org.eclipse.lsp4j.Position(31,54),
org.eclipse.lsp4j.Position(53, 65)), message, DiagnosticSeverity.Warning, problemFile, " probcli v.$version" )
assertEquals(diagnostic, transformedProblem)
}
@Test
fun test_transformProblems_information(){
val problemFile = "test.mch"
val message = "Test"
val version = "test"
val testProblem = Problem(message = message, file = problemFile, reason = "test reason", version = version,
start = Position(32,54), end = Position(54,65), type = "information")
val transformedProblem = ProBCommandLineAccess().transformProblems(listOf(testProblem)).first()
val diagnostic = Diagnostic(Range(
org.eclipse.lsp4j.Position(31,54),
org.eclipse.lsp4j.Position(53, 65)), message, DiagnosticSeverity.Information, problemFile, " probcli v.$version" )
assertEquals(diagnostic, transformedProblem)
}
@Test
fun test_transformProblems_hint(){
val problemFile = "test.mch"
val message = "Test"
val version = "test"
val testProblem = Problem(message = message, file = problemFile, reason = "test reason", version = version,
start = Position(32,54), end = Position(54,65), type = "something else")
val transformedProblem = ProBCommandLineAccess().transformProblems(listOf(testProblem)).first()
val diagnostic = Diagnostic(Range(
org.eclipse.lsp4j.Position(31,54),
org.eclipse.lsp4j.Position(5, 65)), message, DiagnosticSeverity.Hint, problemFile, " probcli v.$version" )
assertEquals(diagnostic, transformedProblem)
}
@Test
fun test_createFolders_success(@TempDir tempPath : File = File("tmp")){
val errorDict = File(tempPath.path+"/tmp")
val errorPath = File(tempPath.path+"/tmp/hallo.njson")
val result = ProBCommandLineAccess().createFolder(errorDict, errorPath)
assertTrue(result)
}
*/
}
\ No newline at end of file
package b.language.server
import b.language.server.proBMangement.prob.ProBKernelManager
import org.eclipse.lsp4j.jsonrpc.Launcher
import org.eclipse.lsp4j.launch.LSPLauncher
import org.eclipse.lsp4j.services.LanguageClient
import org.eclipse.lsp4j.services.LanguageServer
import java.io.InputStream
import java.io.OutputStream
import java.util.concurrent.Future
fun main() {
startServer(System.`in`, System.out)
}
fun startServer(inputStream: InputStream, outputStream: OutputStream){
val client = Client()
val launcher : Launcher<LanguageServer> = LSPLauncher.createClientLauncher(client, inputStream, outputStream)
val startListing : Future<*> = launcher.startListening()
startListing.get()
}
package b.language.server.communication
import b.language.server.communication.CommunicatorInterface
import org.eclipse.lsp4j.MessageType
import org.eclipse.lsp4j.PublishDiagnosticsParams
/**
* The Communicator is a side effect class, we don´t want side effects in out tests; especially such that are for
* debug purpose only
*/
class DummyCommunication() : CommunicatorInterface {
val outputCollector = mutableListOf<String>()
/**
* Sends the diagnostics
*
* @param diagnostics object containing the Diagnostics
*/
override fun publishDiagnostics(diagnostics: PublishDiagnosticsParams) {}
/**
* Sends a debug message resulting in a output channel message
*
* @param message the message to send
* @param severity the Severity of the message (Error/Info/Warning)
*/
override fun sendDebugMessage(message: String, severity: MessageType) {
outputCollector.add(message)
}
/**
* Sends a popup message resulting in a popup message
*
* @param message the message to send
* @param severity the Severity of the message (Error/Info/Warning)
*/
override fun showMessage(message: String, severity: MessageType) {}
/**
* To enable/disable debug mode
*
* @param mode the new state of the debug mode
*/
override fun setDebugMode(mode: Boolean) {
TODO("Not yet implemented")
}
/**
* To enable/disable debug mode
*
* @param mode the new state of the debug mode
*/
}
\ No newline at end of file
package b.language.server.prob2.proBMangement
class ProBKernelManagerTest {
/*
@Test
fun testCorrectBaseSetup(){
val dummyCommunication = DummyCommunication()
val proBKernelManager = ProBKernelManager(dummyCommunication)
proBKernelManager.setup("DEFAULT")
assertEquals(listOf("default prob selected", "generating kernel...", "..done"), dummyCommunication.outputCollector)
}
@Test
fun testCorrectBaseSetupWrongPath(){
val dummyCommunication = DummyCommunication()
val proBKernelManager = ProBKernelManager(dummyCommunication)
Assertions.assertThrows(WrongPathException::class.java) { proBKernelManager.setup("NOTDEFAULT") }
}
@Test
fun testCheckDocument(){
val dummyCommunication = DummyCommunication()
val proBKernelManager = ProBKernelManager(dummyCommunication)
val diagnostics = proBKernelManager.checkDocument("src/test/resources/Lift.mch", Settings(100, true, true, true, File("DEFAULT")))
println(dummyCommunication.outputCollector)
println(diagnostics)
}
*/
}
\ No newline at end of file
package b.language.server.prob2.proBMangement
import b.language.server.proBMangement.prob.convertErrorItems
import b.language.server.proBMangement.prob.getErrorItemType
import de.prob.animator.domainobjects.ErrorItem
import org.eclipse.lsp4j.Diagnostic
import org.eclipse.lsp4j.DiagnosticSeverity
import org.eclipse.lsp4j.Position
import org.eclipse.lsp4j.Range
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
class UtilTest {
/**
* as we using functional programming we don´t test the logic but the functionality
*/
@Test
fun generateErrorItem()
{
val startLine = 100
val statCol = 100
val endLine = 101
val endCol = 101
val message = "hello"
val file = "/test"
val errorItem = ErrorItem(message, ErrorItem.Type.INTERNAL_ERROR,
listOf(ErrorItem.Location(file, startLine,statCol,endLine,endCol)))
val diagnostic = Diagnostic(
Range(
Position(startLine-1, statCol),
Position(endLine-1, endCol)),
message, DiagnosticSeverity.Error, file)
val errorItemAfter = convertErrorItems(listOf(errorItem)).first()
assertEquals(diagnostic, errorItemAfter)
}
@Test
fun errorCodeTranslation_Error1()
{
val result = getErrorItemType(ErrorItem.Type.INTERNAL_ERROR)
assertEquals(DiagnosticSeverity.Error, result)
}
@Test
fun errorCodeTranslation_Error2()
{
val result = getErrorItemType(ErrorItem.Type.ERROR)
assertEquals(DiagnosticSeverity.Error, result)
}
@Test
fun errorCodeTranslation_Warning()
{
val result = getErrorItemType(ErrorItem.Type.WARNING)
assertEquals(DiagnosticSeverity.Warning, result)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment