-
Notifications
You must be signed in to change notification settings - Fork 819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tests for call statements with and w/o preceding comment #2539
base: master
Are you sure you want to change the base?
add tests for call statements with and w/o preceding comment #2539
Conversation
test without comment currently succeeds while tests with preceding comment fail at the moment
Thanks for adding some tests 👍 I see that the failure looks like
Could you please adjust the test code in such a way that the failure message looks like a decent bug report? (see https://github.com/pgjdbc/pgjdbc/blob/master/CONTRIBUTING.md#test ) |
- put each test into a distinct test method with one assertion - add speaking failure message
I have updated the tests accordingly. Please check whether this is sufficient. |
* @param jdbcCallParseInfo not <code>null</code> | ||
*/ | ||
private void assertIsFunction(JdbcCallParseInfo jdbcCallParseInfo) { | ||
String message = "Call statement was not recognised as such : \"" + jdbcCallParseInfo.getSql() + "\", " + jdbcCallParseInfo.getClass().getSimpleName() + ".isFunction() -"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be clearer to me to say Parse error or Unable to parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the message
*/ | ||
@Test | ||
public void testModifyJdbcCallRecogniseFunctionCall() throws SQLException { | ||
assertIsFunction(Parser.modifyJdbcCall("{ ? = call test_function(?)}", true, ServerVersion.v14.getVersionNum(), 3, EscapeSyntaxCallMode.CALL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think you could push Parser.modifyJdbcCall
into assertIsFunction
as well, so its failure message would indicate the way it called parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the call to assertIsFunction
, which is a good idea since it reduces duplicate code. However, I don't see how this would improve the failure message.
Do you mind if I switch this test class ParserTest
to JUnit5 instead of JUnit4?
Then we could use a @ParemeterizedTest
annotated test method here instead of 4 test methods. This would also allow to add more parameters easily, e.g. the server version, though I doubt that this would impact this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is a good idea since it reduces duplicate code
Glad you liked it. Every time I ask I am afraid it would be considered splitting hairs.
However, I don't see how this would improve the failure message.
How about the following?
JdbcCallParseInfo jdbcCallParseInfo = Parser.modifyJdbcCall(sql, true, ServerVersion.v14.getVersionNum(), 3, EscapeSyntaxCallMode.CALL);
String message = "Parser.modifyJdbcCall(\"" + sql + "\", , true, ServerVersion.v14.getVersionNum(), 3, EscapeSyntaxCallMode.CALL).isFunction was supposed to return FUNCTION, however got " + jdbcCallParseInfo;
Switch to JUnit5 is just fine.
Frankly speaking, I would love to rewrite the existing BaseTest4
into something like JUnit5 extension, however, I had no chances to do that yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JdbcCallParseInfo
does not implement toString()
obviously:
Parser.modifyJdbcCall("/* some comment */ { ? = call test_function(?)}", , true, ServerVersion.v14.getVersionNum(), 3, EscapeSyntaxCallMode.CALL).isFunction was supposed to return FUNCTION, however got org.postgresql.core.JdbcCallParseInfo@5f1b1944 expected:<true> but was:<false>
Therefore I omitted the however ... part:
Parser.modifyJdbcCall("/* some comment */ { ? = call test_function(?)}", , true, ServerVersion.v14.getVersionNum(), 3, EscapeSyntaxCallMode.CALL).isFunction was supposed to return FUNCTION, expected:<true> but was:<false>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to JUnit5 is just fine. Frankly speaking, I would love to rewrite the existing
BaseTest4
into something like JUnit5 extension, however, I had no chances to do that yet.
I have converted the ParserTest
to JUnit5 (update imports, swap method params) and changed the four test methods to one ParameterizedTest.
merge the four testModifyJdbcCallRecognise*() test methods and assertIsFunction(String) to the new parameterized test method testParseCallStatementAsFunction(String) and add argument provider method argsTestParseCallStatementAsFunction()
test without comment currently succeeds while tests with preceding comment fail at the moment
All Submissions:
Test submission
CALL
statements prevent setting of OUT parameters for stored procedures / functions #2538