MopeSWTP-SS21 / MopeSWTP

MIT License
1 stars 0 forks source link

Implement sendExpression via executeCommand #97

Open CSchoel opened 3 years ago

CSchoel commented 3 years ago
manuEbg commented 3 years ago
  • If the omc-java-api throws any exception, report the error message back to the user.

omc-java-apis sendExpression does not throw any Exceptions.

I created a few testcases for this functionality.

im quite sure that at least the sendExpression4 Error is because of ModelicaVersion 3.2.3 which gets loaded in a test prior and was not used to produce expected output.

PS.: The sendExpression Links somehow don't jump to the correct line when clicked... RightClick -> copy link works fine

manuEbg commented 3 years ago

The Problem with sendExpression4 is not because of different ModelicaStandardLibrary but because of loading any ModelicaStandardLibrary... I will adjust the expected output. I replaced the expected Output for sendExpression5 with a bad Regex... its ugly but i think it works

manuEbg commented 3 years ago

Two Questions remain:

CSchoel commented 3 years ago

omc-java-apis sendExpression does not throw any Exceptions.

It does not declare any Exceptions in the header, but that does not mean that it wont throw runtime exceptions, those are two different things. If you look at the implementation of sendExpression(), you can clearly see that the author did anticipate runtime exceptions (otherwise the try is meaningless) and even throws an IllegalStateException explicitly.

CSchoel commented 3 years ago

It was a good idea to implement the test cases. This allows us to discuss test design:

CSchoel commented 3 years ago

Two Questions remain:

expected: <[<interactive>:1:1-1:18:writable] Error: Class unknownAPIMethod not found in scope <global scope> (looking for a function or record).
    > 
but was: <[<interactive>:1:1-1:0:writable] Error: Class unknownAPIMethod not found in scope <global scope> (looking for a function or record).>

As you can see, the difference lies in the column number where the error is reported. You expect to see the error from line 1 column 1 to line one column 18, which is the end of the string unknownAPIMethod(). Instead, you get a strange invalid range from line 1, column 1 to line one, column 0. You could investigate where this comes from, but I would argue that it is inconsequential for the test. This is not a real file we are talking about, but a code snippet that is sent directly to the OMC. What good does a correct line and column do for debugging in this case? I would therefore suggest that you simply make the test more flexible, only checking for the relevant part such as Class unknownAPIMethod not found.

The downside to this is that with assertTrue(x.contains("...")) you do not see the actual string content in case the test fails. This can be remedied in two ways:

  • Where does the Notification during sendExpression9 come from? Notification: Downloaded package index from URL https://libraries.openmodelica.org/index/v1/index.json.

The OMC tries to install unknown libraries from a central package index if possible. The "correct" way to do this seems to be to use installLibrary(), but I think loadModel() also has a fallback mechanism where it tries to install a library, when it cannot find it on the Modelica path. The error that the package index could not be parsed is a known issue in the OpenModelica project that we will have to work around for now.