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

mock: complete API documentation including expect module #2494

Merged
merged 27 commits into from
Nov 2, 2024

Conversation

hds
Copy link
Contributor

@hds hds commented Mar 3, 2023

Motivation

There has been interest around publishing tracing-mock to crates.io
for some time. In order to make this possible, documentation and some
code clean up is needed.

The expect module, which contains constructor functions for many of
the other tracing-mock modules needs documentation and examples.

This change adds documentation to the expect module and all the public
APIs within it. This includes doctests on all the methods which serve as
examples.

Solution

The lint for missing_docs has been enabled for the entire
tracing-mock crate! This has been done together with all the
other lints that are enabled on the other crates in this project.

The event::msg("message") constructor was removed, in favor of
requiring an explicit construction via
expect::event().with_fields(expect::msg("message")). This is
appropriate to reduce the API surface that would need to be supported in
the future and also because the event::msg constructor could be
overridden by a subsequent usage of with_fields. The shorthand
expect::message() was renamed to expect::msg to make this
change less burdensome.

The span::named("name") constructor was removed, in favor of requiring
an explicit construction via expect::span.with_name("name"). The
latter isn't much longer and since #3097, a string with the name can
be passed directly everywhere that an ExpectedSpan is required.

This change also sets the missing_docs lint to warn for the entire
tracing-mock crate, making it ready to publish (once backported).

Refs: #539

hds and others added 24 commits November 16, 2022 15:43
There has been interest around publishing `tracing-mock` to crates.io
for some time. In order to make this possible, documentation and some
code clean up is needed.

This change adds documentation to the collector module itself and to all the
public APIs in the module. This includes doctests on all the methods
that serve as examples.

Additionally the implementation for the `Expect` struct has been moved
into the module with the definition, this was missed in #2369.

Refs: #539
It creates too many issues (need to add `allow_deprecated` annotations
all over the place) and they will actually make fixing those tests to
use the new (but as yet unimplemented) `MockCollector::close_span` more
difficult.
They are! I removed the referce to `MockCollector::close_span` as it
doesn't yet exist.
Also cleaned up the text and tried to apply the code review comments
from #2426 to what I'd written already.
All based on the lovely code review feedback I've been receiving.
This change adds documentation to the span module and all the public
APIs within it. This includes doctests on all the methods which serve as
examples.

Additionally, the validation on `ExpectedSpan` was improved so that it
validates the level and target during `enter` and `exit` as well as on
`new_span`.

The method `ExpectedSpan::with_field` was renamed to `with_fields`
(plural) to match the same method on `ExpectedEvent` (and because
multiple fields can be passed to it).

A copy-paste typo was also fixed in the documentation for
`ExpectedEvent::with_contextual_parent`.

Refs: #539
This change adds documentation to the `field` module and all the public
APIs within it. This includes doctests on all the methods which serve as
examples.

Additionally, the `field::msg` function (which constructs a field with
name "message" and the provided value) was moved to `expect::message`.
This is part of a unification of all expectation constructors inside the
`expect` module.

Refs: #539
The PR documenting the subscriber module.
There has been interest around publishing tracing-mock to crates.io
for some time. In order to make this possible, documentation and some
code clean up is needed.

The `expect` module, which contains constructor functions for many of
the other `tracing-mock` modules needs documentation and examples.

This change adds documentation to the `expect` module and all the public
APIs within it. This includes doctests on all the methods which serve as
examples.

The lint for `missing_docs` has been enabled for the entire
`tracing-mock` crate! Further lints which are common in other crates in
this project haven't been enabled. This will be done in a later PR.

The `event::msg("message")` constructor was removed, in favor of
requiring an explicit construction via
`expect::event().with_fields(expect::msg("message"))`. This is
appropriate to reduce the API surface that would need to be supported in
the future and also because the `event::msg` constructor could be
overridden by a subsequent usage of `with_fields`.

The `span::named("name")` constructor was removed, in favor of requiring
an explicit construction via `expect::span.with_name("name")`. The
latter isn't much longer.
@hds hds requested review from hawkw, davidbarsky and a team as code owners March 3, 2023 15:24
@hds hds marked this pull request as draft March 3, 2023 15:25
@hds hds force-pushed the hds/mock-docs-expect branch from 23cc2cb to da9f9fc Compare October 30, 2024 17:00
@hds hds force-pushed the hds/mock-docs-expect branch from da9f9fc to c467577 Compare October 30, 2024 17:07
@hds hds marked this pull request as ready for review October 30, 2024 21:53
Copy link
Contributor

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks! 👍

tracing-mock/src/expect.rs Outdated Show resolved Hide resolved
@hds hds merged commit 91fedc1 into master Nov 2, 2024
56 checks passed
@hds hds deleted the hds/mock-docs-expect branch November 2, 2024 11:25
hds added a commit that referenced this pull request Nov 11, 2024
There has been interest around publishing tracing-mock to crates.io
for some time. In order to make this possible, documentation and some
code clean up is needed.

The `expect` module, which contains constructor functions for many of
the other `tracing-mock` modules needs documentation and examples.

This change adds documentation to the `expect` module and all the public
APIs within it. This includes doctests on all the methods which serve as
examples.

The lint for `missing_docs` has been enabled for the entire
`tracing-mock` crate! This has been done together with all the
other lints that are enabled on the other crates in this project.

The `event::msg("message")` constructor was removed, in favor of
requiring an explicit construction via
`expect::event().with_fields(expect::msg("message"))`. This is
appropriate to reduce the API surface that would need to be supported in
the future and also because the `event::msg` constructor could be
overridden by a subsequent usage of `with_fields`. The shorthand
`expect::message()` was renamed to `expect::msg` to make this
change less burdensome.

The `span::named("name")` constructor was removed, in favor of requiring
an explicit construction via `expect::span.with_name("name")`. The
latter isn't much longer and since #3097, a string with the name can
be passed directly everywhere that an `ExpectedSpan` is required.

This change also sets the `missing_docs` lint to warn for the entire
`tracing-mock` crate, making it ready to publish (once backported).

Refs: #539
hds added a commit that referenced this pull request Nov 20, 2024
There has been interest around publishing tracing-mock to crates.io
for some time. In order to make this possible, documentation and some
code clean up is needed.

The `expect` module, which contains constructor functions for many of
the other `tracing-mock` modules needs documentation and examples.

This change adds documentation to the `expect` module and all the public
APIs within it. This includes doctests on all the methods which serve as
examples.

The lint for `missing_docs` has been enabled for the entire
`tracing-mock` crate! This has been done together with all the
other lints that are enabled on the other crates in this project.

The `event::msg("message")` constructor was removed, in favor of
requiring an explicit construction via
`expect::event().with_fields(expect::msg("message"))`. This is
appropriate to reduce the API surface that would need to be supported in
the future and also because the `event::msg` constructor could be
overridden by a subsequent usage of `with_fields`. The shorthand
`expect::message()` was renamed to `expect::msg` to make this
change less burdensome.

The `span::named("name")` constructor was removed, in favor of requiring
an explicit construction via `expect::span.with_name("name")`. The
latter isn't much longer and since #3097, a string with the name can
be passed directly everywhere that an `ExpectedSpan` is required.

This change also sets the `missing_docs` lint to warn for the entire
`tracing-mock` crate, making it ready to publish (once backported).

Refs: #539
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.

3 participants