google / googletest

GoogleTest - Google Testing and Mocking Framework
https://google.github.io/googletest/
BSD 3-Clause "New" or "Revised" License
34.6k stars 10.11k forks source link

What to #include, namespaces not obvious from the documentation #4604

Open dabrahams opened 1 month ago

dabrahams commented 1 month ago

Describe the issue

For example, on this page I see uses of HasSubstring but nothing on that page tells me what namespace it comes from.

On this page I see

using ::testing::HasSubstr;

in examples, but #include <gtest/gtest.h> is insufficient to find that, and nothing on the page tells me what the right #include is.

Steps to reproduce the problem

Read the docs

What version of GoogleTest are you using?

ff233bdd4cac0a0bf6e5cd45bda3406814cb2796

What operating system and version are you using?

macOS 14.6.1

What compiler and version are you using?

gcc-14

What build system are you using?

CMake 29.3

Additional context

No response

XAMeLeOH commented 3 weeks ago

Dear Dave,

It seems it has already been fixed. If I check the reference link from your comment, I see the following in the last paragraph of the main section (just above the Wildcard header):

Built-in matchers ... are divided into several categories. All matchers are defined in the ::testing namespace unless otherwise noted.

Could you please confirm that?

dabrahams commented 3 weeks ago

That covers the namespace but not what to #include.

XAMeLeOH commented 3 weeks ago

That covers the namespace but not what to #include.

Yeah, that makes sense.

I created a PR. Let's see if it gets merged. Feel free to review it too.

XAMeLeOH commented 3 weeks ago

From your comment:

Marchers.md was just an example. You need to do this for all of the files in the documentation, and double check that the name spaces are also specified.

I figured that the guides are fine, because they are teaching how to use the tool, not sure that information belongs there. Also the code snippets do mention the namespace one way or another.

I believe the most critical part are the references, that is why I checked testing, mocking, assertions, matchers and actions. And to me it seems that the matchers and actions are the only ones which didn't reference the correct header and/or namespace.

dabrahams commented 3 weeks ago

The code snippets I saw do not mention the namespace nor do they have #include directives. Remember that users will often jump to documentation for a specific facility rather than reading a whole page where that documentation is given. Whether you want to address this is of course up to you; I have no further comments.