Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

heimburgerj2
Copy link

test without comment currently succeeds while tests with preceding comment fail at the moment

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Test submission

test without comment currently succeeds while tests with preceding comment fail at the moment
@vlsi
Copy link
Member

vlsi commented Jun 7, 2022

Thanks for adding some tests 👍

I see that the failure looks like

FAILURE   0.0sec, org.postgresql.core.ParserTest > testModifyJdbcCall
    java.lang.AssertionError: expected:<true> but was:<false>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:120)
at org.junit.Assert.assertEquals(Assert.java:146)
at org.postgresql.core.ParserTest.testModifyJdbcCall(ParserTest.java:160)

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
@heimburgerj2
Copy link
Author

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 )

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() -";
Copy link
Member

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.

Copy link
Author

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));
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

Copy link
Author

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>

Copy link
Author

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants