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

test(developer): kmcmplib compiler unit tests 2 #11663

Merged
merged 19 commits into from
Jul 26, 2024

Conversation

markcsinclair
Copy link
Contributor

Google Test based unit tests for Compiler.cpp

Continues PR #11378

@keymanapp-test-bot skip

@keymanapp-test-bot
Copy link

keymanapp-test-bot bot commented Jun 3, 2024

User Test Results

Test specification and instructions

User tests are not required

@keymanapp-test-bot keymanapp-test-bot bot added this to the A18S3 milestone Jun 3, 2024
@markcsinclair markcsinclair self-assigned this Jun 3, 2024
@markcsinclair markcsinclair marked this pull request as draft June 3, 2024 11:01
@markcsinclair markcsinclair changed the title test(developer) kmcmplib compiler unit tests 2 test(developer): kmcmplib compiler unit tests 2 Jun 7, 2024
@mcdurdin mcdurdin modified the milestones: A18S3, A18S4 Jun 7, 2024
@markcsinclair
Copy link
Contributor Author

Hmm ... one of the commits (54d82b5) says initFileKeyboard when it should say deleteFileKeyboard ... too late to change.

…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@darcywong00 darcywong00 modified the milestones: A18S5, A18S6 Jul 8, 2024
…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@markcsinclair
Copy link
Contributor Author

markcsinclair commented Jul 8, 2024

Putting this in for review as it stands, and will continue in a new PR. There are several test cases written but commented out due to issues #11814 (u16tok() bug)and #11937 (GetDelimitedString() bug), as well as a test that passes and shouldn't due to issue #11833 (a space works as well as a comma between arguments in index()). The fixes for the outstanding issues should uncomment (or reverse the outcome) of the relevant test cases here.

…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@darcywong00 darcywong00 modified the milestones: A18S6, A18S7 Jul 19, 2024
…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, all the tests look good.

The compiler code is pretty yeuch but this is at least pushing stability in the right direction. If we have a comprehensive set of tests, we can rewrite bits one day!

Copy link
Contributor

@jahorton jahorton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM outside of lines 876 - 879.

I'm not currently able to adequately parse the setup for that block to know why the test works and makes sense. It's not that I found an issue; it's more that I'm having difficulty parsing what it represents and so cannot give good feedback there. Feel free to move forward if you're not too worried about that particular test - it's one of many, and the reset seem fine and clear enough.

…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@markcsinclair
Copy link
Contributor Author

LGTM outside of lines 876 - 879.

I'm not currently able to adequately parse the setup for that block to know why the test works and makes sense. It's not that I found an issue; it's more that I'm having difficulty parsing what it represents and so cannot give good feedback there. Feel free to move forward if you're not too worried about that particular test - it's one of many, and the reset seem fine and clear enough.

I have added some local variables and comments to try to clarify the CERR_OutsTooLong test case

Comment on lines +1120 to +1125
// outs, CERR_OutsTooLong
PKMX_WCHAR dpString = (PKMX_WCHAR)u"abc";
file_store[1].dpString = dpString; // length 4 => max should be > 4, otherwise a CERR_OutsTooLong is emitted
int max = u16len(dpString) + 1; // 4, including terminating '\0'
u16cpy(str, u"outs(b)");
EXPECT_EQ(CERR_OutsTooLong, GetXStringImpl(tstr, &fileKeyboard, str, u"", output, max, 0, &newp, FALSE)); // max reduced to force error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I realize that the code being tested isn't yours... but man, that is not an intuitive pattern for max. In the worst case, I'd expect max=4 to be perfectly fine with 3 chars + 1 null terminator. 4 is within a max of 4, after all. (I can understand not making the null terminator implicit due to how C / C++ strings work.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Looks like an off-by-one in calculation, but it's off-by-one in a conservative way so not really any harm done. If you are looking for intuitive code, I suggest you don't look at the compiler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, it is one of the very few places in the kmcmplib compiler where any of the code tests to see if there is room in the buffer before writing (see here). Buffer overruns are detected post facto by Marc's high-level fix here.

Copy link
Member

@mcdurdin mcdurdin Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so many problems with buffer management. Yay C. My high-level fix is an attempt to mitigate rather than resolve, as we slowly inch towards a rewrite one day.

@markcsinclair
Copy link
Contributor Author

markcsinclair commented Jul 24, 2024

Re-review requested as nine test cases uncommented and passing due to having merged #11938 and #11910 into master.

Copy link
Contributor

@jahorton jahorton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm admittedly not terribly clear on the cases from among the newly-uncommented nine (see ea0a2f7) that involve the special Keyman-language keyword beep in the midst of other statements, but otherwise this LGTM.

@markcsinclair
Copy link
Contributor Author

I'm admittedly not terribly clear on the cases from among the newly-uncommented nine (see ea0a2f7) that involve the special Keyman-language keyword beep in the midst of other statements, but otherwise this LGTM.

The reason the beeps are there is because the compiler renenters on that part of the statement (e.g. if you call GetXStringImpl() on u"baselayout(beep)", the call chain includes process_baselayout() on the argument beep, which ultimately calls GetXStringImpl() on beep. I selected beep as a simple command that I had already tested. In an ideal world, all of these case statements in GetXStringImpl() and the functions they call would be stubbable virtual class methods, so the unit test didn't extend beyond a single method, but what can you do!

…compiler-unit-tests-2

# Keyman Conventional Commit suggestions:
#
# - Link to a Sentry issue with git trailer:
#     Fixes: _MODULE_-_ID_
# - Give credit to co-authors:
#     Co-authored-by: _Name_ <_email_>
# - Use imperative, present tense ('attach' not 'attaches', 'attached' etc)
# - Don't include a period at the end of the title
# - Always include a blank line before trailers
# - More: https://github.com/keymanapp/keyman/wiki/Pull-Request-and-Commit-workflow-notes
@markcsinclair markcsinclair merged commit 0f7d0c5 into master Jul 26, 2024
4 checks passed
@markcsinclair markcsinclair deleted the test/developer/kmcmplib-compiler-unit-tests-2 branch July 26, 2024 12:50
@keyman-server
Copy link
Collaborator

Changes in this pull request will be available for download in Keyman version 18.0.76-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

5 participants