From d36293994d81081f5edf20c9d0c4917c7a613ae2 Mon Sep 17 00:00:00 2001 From: SeeBasTStick <sebastian.stock@hhu.de> Date: Thu, 3 Sep 2020 13:44:32 +0200 Subject: [PATCH] added tests --- src/main/kotlin/b/language/server/Util.kt | 2 - .../server/proBMangement/prob/Util.kt | 15 +- src/test/kotlin/b/language/server/Client.kt | 52 ----- .../b/language/server/ProBCommandLineTest.kt | 182 ------------------ src/test/kotlin/b/language/server/TestApp.kt | 30 --- .../communication/DummyCommunication.kt | 57 ------ .../proBMangement/ProBKernelManagerTest.kt | 35 ---- .../server/prob2/proBMangement/UtilTest.kt | 68 +++++++ 8 files changed, 74 insertions(+), 367 deletions(-) delete mode 100644 src/test/kotlin/b/language/server/Client.kt delete mode 100644 src/test/kotlin/b/language/server/ProBCommandLineTest.kt delete mode 100644 src/test/kotlin/b/language/server/TestApp.kt delete mode 100644 src/test/kotlin/b/language/server/communication/DummyCommunication.kt delete mode 100644 src/test/kotlin/b/language/server/prob2/proBMangement/ProBKernelManagerTest.kt create mode 100644 src/test/kotlin/b/language/server/prob2/proBMangement/UtilTest.kt diff --git a/src/main/kotlin/b/language/server/Util.kt b/src/main/kotlin/b/language/server/Util.kt index ce08112..eb734fe 100644 --- a/src/main/kotlin/b/language/server/Util.kt +++ b/src/main/kotlin/b/language/server/Util.kt @@ -5,7 +5,6 @@ import com.google.gson.Gson import com.google.gson.JsonObject - /** * Takes a json and tries to cast it into a settings objects * @param json the json object @@ -18,7 +17,6 @@ fun castJsonToSetting(json : JsonObject) : Settings { Gson().fromJson(json.get("performanceHints"), Boolean::class.java), Gson().fromJson(json.get("probHome"), String::class.java), Gson().fromJson(json.get("debugMode"), Boolean::class.java)) - } diff --git a/src/main/kotlin/b/language/server/proBMangement/prob/Util.kt b/src/main/kotlin/b/language/server/proBMangement/prob/Util.kt index fa1a55b..dd42b43 100644 --- a/src/main/kotlin/b/language/server/proBMangement/prob/Util.kt +++ b/src/main/kotlin/b/language/server/proBMangement/prob/Util.kt @@ -5,25 +5,22 @@ import org.eclipse.lsp4j.Diagnostic import org.eclipse.lsp4j.DiagnosticSeverity import org.eclipse.lsp4j.Position 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>{ return errorItems.toList().map { errorItem -> 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, - getErrorItemType(errorItem), + getErrorItemType(errorItem.type), location.filename) } }.flatten() } -fun getErrorItemType(errorItem: ErrorItem) : DiagnosticSeverity{ - return when(errorItem.type){ +fun getErrorItemType(errorItem: ErrorItem.Type) : DiagnosticSeverity{ + return when(errorItem){ ErrorItem.Type.ERROR -> { DiagnosticSeverity.Error } diff --git a/src/test/kotlin/b/language/server/Client.kt b/src/test/kotlin/b/language/server/Client.kt deleted file mode 100644 index 4c12b9d..0000000 --- a/src/test/kotlin/b/language/server/Client.kt +++ /dev/null @@ -1,52 +0,0 @@ -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 diff --git a/src/test/kotlin/b/language/server/ProBCommandLineTest.kt b/src/test/kotlin/b/language/server/ProBCommandLineTest.kt deleted file mode 100644 index 6784d03..0000000 --- a/src/test/kotlin/b/language/server/ProBCommandLineTest.kt +++ /dev/null @@ -1,182 +0,0 @@ -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 diff --git a/src/test/kotlin/b/language/server/TestApp.kt b/src/test/kotlin/b/language/server/TestApp.kt deleted file mode 100644 index a923853..0000000 --- a/src/test/kotlin/b/language/server/TestApp.kt +++ /dev/null @@ -1,30 +0,0 @@ -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() - } - - diff --git a/src/test/kotlin/b/language/server/communication/DummyCommunication.kt b/src/test/kotlin/b/language/server/communication/DummyCommunication.kt deleted file mode 100644 index 0eb59e2..0000000 --- a/src/test/kotlin/b/language/server/communication/DummyCommunication.kt +++ /dev/null @@ -1,57 +0,0 @@ -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 diff --git a/src/test/kotlin/b/language/server/prob2/proBMangement/ProBKernelManagerTest.kt b/src/test/kotlin/b/language/server/prob2/proBMangement/ProBKernelManagerTest.kt deleted file mode 100644 index 7d41407..0000000 --- a/src/test/kotlin/b/language/server/prob2/proBMangement/ProBKernelManagerTest.kt +++ /dev/null @@ -1,35 +0,0 @@ -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 diff --git a/src/test/kotlin/b/language/server/prob2/proBMangement/UtilTest.kt b/src/test/kotlin/b/language/server/prob2/proBMangement/UtilTest.kt new file mode 100644 index 0000000..0eea8cf --- /dev/null +++ b/src/test/kotlin/b/language/server/prob2/proBMangement/UtilTest.kt @@ -0,0 +1,68 @@ +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 -- GitLab