Skip to content

Doctest stdlib timerelated#11327

Open
spoo wants to merge 10 commits into
erlang:masterfrom
spoo:doctest_stdlib_timerelated
Open

Doctest stdlib timerelated#11327
spoo wants to merge 10 commits into
erlang:masterfrom
spoo:doctest_stdlib_timerelated

Conversation

@spoo

@spoo spoo commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This PR adds doctest examples to time related modules in Stdlib application for most of the functions

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

CT Test Results

    2 files    100 suites   1h 7m 31s ⏱️
2 306 tests 2 254 ✅ 51 💤 1 ❌
2 729 runs  2 672 ✅ 56 💤 1 ❌

For more details on these failures, see this check.

Results for commit 25c69b8.

♻️ 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

@jhogberg jhogberg added the team:VM Assigned to OTP team VM label Jul 6, 2026
Comment thread lib/stdlib/src/random.erl Outdated
Comment on lines +206 to +207
2> F = random:uniform(), is_float(F), F > 0.0, F < 1.0.
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This results in true for any F that is a number (including integers) that is less than 1.0, for example -5.

@spoo spoo Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing it . The idea was to demonstrate output as floating and between 0.0 and 1.0. Added 'and' operator now to correct the same than the 'comma' operator. Hope now is ok

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should be andalso.

Comment thread lib/stdlib/src/random.erl Outdated
Comment on lines +208 to +209
3> I = random:uniform(10), I >= 1, I =< 10.
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This results in true for any I that is a number (including floats) that is less than or equal to 10, for example -5.5.

Comment thread lib/stdlib/src/random.erl Outdated
Comment on lines +249 to +250
2> {Float, _NewState} = random:uniform_s(State), is_float(Float), Float > 0.0, Float < 1.0.
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This results in true for any Float that is a number (including integers) that is less than 1.0, for example -5.

Comment thread lib/stdlib/src/random.erl Outdated
Comment on lines +251 to +252
3> {Int, _NewState2} = random:uniform_s(10, State), Int >= 1, Int =< 10.
true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This results in true for any Int that is a number (including floats) that is less than or equal to 10, for example -5.5.

Comment thread lib/stdlib/src/timer.erl Outdated
Comment on lines +55 to +56
1> ok = element(1, timer:apply_after(5000, io, format, ["~nHello World!~n", []])).
ok

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This wrapping in element(1, ...) makes the examples pretty confusing. A newcomer will certainly wonder, "Is that needed? What for? 🤔"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree that it makes the example not too clear enough for beginers. I have reverted preexisting examples at start of document back to text script. For newer added examples, since the TRef that is given by apply_after is always dynamic its hard to pattern match output and fails by doctest function in performed by timer_suite module. As per my understanding, examples should pass doctest at anypoint and hence a way verifying they are correct , so here TRef being dynamically generated will not be able to pattern match and hence extracting first element 'ok which will also validate success. I am happy to discuss any other better method that could be adopted otherwise :)

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

Labels

team:VM Assigned to OTP team VM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants