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
Fix example code in ct_hooks_chapter.xml #6437
Conversation
CT Test Results 3 files 69 suites 1h 30m 51s ⏱️ Results for commit 0631c7f. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
Thanks for taking a deeper look into that area! I like the reduced [minimal example] (https://gist.github.com/fabjan/754840a6daf30058c00880b465448974). I think current example is more of a code skeleton than a minimal example. I would suggest having it(minimal_example) in ct_hooks_chapter with following adjustments:
Additionally (does not have to be included in this PR), I thought about following:
I brought points 1 and 5 because regularly when I'm explaining CT hooks to students I got a question/suggestion that feature does not work when actually the forget to adjust the code path or compile the hook module before hand.
|
Cheers for the feedback! I'll take a stab at pulling the minimal example in here (and look at the other files you mentioned, I always want to be nice to Emacs users).
Yes it works when installing the hook via e.g. the CT command line, but when the hook is installed by a |
|
It might be because I installed the hook multiple times, which I did on purpose to see how it works aside from reading the docs. The docs say that if you install multiple times as long as the ID is the same the second hook should not be started at all(?): "The Id identifies a CTH instance uniquely. If two CTHs return the same Id, the second CTH is ignored and subsequent calls to the CTH are only made to the first instance. For details, see section [Installing a CTH] in the User's Guide."
I would vote for this, given that this is supposed to be a minimal example I think as long as it works and makes sense it's good (however much my vote counts in this repo, just drive-by PR:ing some docs 🙂). As you say the state is in memory, so it's hard to tell if the file open is in Also, if we can decide to just do this (mode the file open form init to the end before write), we don't have to debug this minimal example hook code more (the opened file handle messing up when I used multiple hooks). If it is not in init on purpose, and the current example doesn't work as advertised it seems to me to be harmless to "fix" it even if we don't know the deepest root cause. Because the example code in the current documentation does not work as the docs advertise, even after syntax errors are fixed: installing the hook via the But perhaps I misunderstood something in the docs. (This is the reason I pulled the code out into that separate repository, to poke at it for real instead of inside an HTML document. Thanks for looking at that code in addition to just inside this PR, I think that makes things much easier.) I will make sure to not change the style (indentation in this case) when updating this PR 👍 |
Side note about the indentation. As the file is now, it seems to be using a four space indent level BUT all lines are prefixed with one extra space. I left the extra space at the beginning to try and make sure the diff for my changes is a as legible as possible, showing only the meaningful changes. Would you like me to in this PR also get rid of that first extra column of space characters? (Maybe the diff preservation is not as interesting now that we are discussing bigger changes anyway) |
I added the minimal example hook now, with the adjustments discussed above. I think I have addressed all the suggestions above, either in the code or in my comments here (except for the emacs skeleton, will look at that next). For the sake of the review, may I suggest that any further issues with the code changes here are discussed under the "Files changed" tab? I think that makes it easier to manage the discussions as separate threads when the issues are separate. The indentation question I think is not quite resolved, see my side note comment above. |
I put the suggested Emacs skeleton in this PR as well, we can remove it if you prefer. Tested by putting this in my ~/.emacs.d/init.el: ;; Set up Erlang mode
(setq load-path (cons "~/code/otp/lib/tools/emacs" load-path))
(require 'erlang-start) The skeleton showed up in the "Erlang" menu, and produces this: I copied that module and tested in my example_cth repository (linked in the thread above) and it logged this:
|
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.
Sorry for delay. This PR has lower priority and must wait longer.
- Please fix minor comments I've added in code.
- can you set target of PR to master branch, please?
- I've played around with adding hook modules via ct_run parameter and from suite/0 function in test suite. My observations are that,
Module:init/2
behaves as expected (i.e. if the hook module returns the same id - init will be called only once). There are more calls toModule:id/1
, but I presume this is needed for checking hook ID by the framework and making the decision.
So from my perspective, there is nothing suspicious at this stage. However if you still observe some anomaly worth checking, please create separate issue with reproduction steps and we will try to clarify that.
%%% To use this hook, on the command line: | ||
%%% ct_run -suite example_SUITE -pa . -ct_hooks example_cth | ||
%%% | ||
%%% N.B. `-pa .`, the hook BEAM file must be in the code path when installing. |
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.
Please avoid Latin acronyms in docs so it is more accessible. Not everyone was privileged to have Latin classes at school ;-)
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.
Ah, no problem! Will fix. How about I just write "Note: " instead?
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.
Good enough!
file:close(File), | ||
ok. | ||
|
||
results(State) -> |
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 left the extra space at the beginning to try and make sure the diff for my changes is a as legible as possible, showing only the meaningful changes. Would you like me to in this PR also get rid of that first extra column of space characters? (Maybe the diff preservation is not as interesting now that we are discussing bigger changes anyway)
Please remove the extra space in the example code. We will see how it behaves ... it looks artificial, maybe there is some reason I'm missing ... let us check and hope it will be fine:-)
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.
👍
No worries, that makes sense. 1 and 2: will fix and update PR. 3: yeah I agree it should be treated separately, I think that's something I experienced when I was trying the file handle issue out in different ways. If I can reproduce something meaningful I can open a separate issue. |
The suggestions should all be adressed now. |
The build failed after curling the GitHub API into Since it's inside a shell pipeline we can't see what the cause was, but it's possible |
I've pushed small commit removing some spaces and wrapping code line. I wanted to check if we can get rid of scrollbar under code example and improve readability. If it it works and you are fine with this suggestion - please squash the commits on the branch and we will merge it. |
I'm fine with that formatting 👍, but not sure how to check if it renders better. I'll squash the commits though. |
The example code has a syntax error (missing a period), and uses the deprecated erlang:now/0 function. * prefix unused variable names with _ * use a more minimal example * move file:open to terminate * 'suite_total' and 'total' were mixed up * put complete CT hook example in erlang-skels.el * fix indentation for the example CTH code * remove some spaces and align to 80 chars rule
Thanks
easiest way I'm aware of is to navigate to HTML doc generated for PR. once processed link should appear in area visualized on screenshot below (it usually works) - "No HTML docs found" should be replaced with a link. |
no horizontal scroll bar now :-). at least in my browsers. https://erlang.github.io/prs/6437/lib/common_test-1.23.2/doc/html/ct_hooks_chapter.html#example-cth |
Nice, yeah for me too 👍 |
Problem
When I copied the example hook from the Common Test User's Guide to use as a base for making a new hook
my editor complained about the code.
The example code has a syntax error (missing a period), and uses the deprecated erlang:now/0 function.
Fix
I followed the suggestions in "How to Work with the New API" to replace the
erlang:now/0
calls.