Skip to content

Commit

Permalink
Docs for automatically handle CONAN_RUN_TESTS environment variable (#…
Browse files Browse the repository at this point in the history
…2056)

* wip

* wip

* update bh docs
  • Loading branch information
czoido committed Mar 30, 2021
1 parent c31da0b commit ed74600
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
11 changes: 3 additions & 8 deletions howtos/header_only.rst
Expand Up @@ -81,14 +81,9 @@ If you want to run the library unit test while packaging, you would need this re

If you are :ref:`cross-building <cross_building>` your **library** or **app** you'll probably need
to skip the **unit tests** because your target binary cannot be executed in current building host.
To do it you can use :ref:`tools_get_env` in combination with
:ref:`env_vars_conan_run_tests` environment variable, defined as **False**
in profile for cross-building and replace ``cmake.test()`` with:

.. code-block:: python
if tools.get_env("CONAN_RUN_TESTS", True):
cmake.test()
To do it you can use :ref:`env_vars_conan_run_tests` environment variable, defined as **False**
in profile for cross-building in the call to ``cmake.test()`` this variable will be evaluated and
the tests will not run.

Which will use a ``CMakeLists.txt`` file in the root folder:

Expand Down
4 changes: 3 additions & 1 deletion reference/build_helpers/cmake.rst
Expand Up @@ -335,7 +335,9 @@ test()
def test(args=None, build_dir=None, target=None, output_on_failure=False)
Build `CMake` test target (could be RUN_TESTS in multi-config projects or ``test`` in single-config projects), which usually means building and running unit tests
Build `CMake` test target (could be RUN_TESTS in multi-config projects or ``test`` in single-config
projects), which usually means building and running unit tests. When this function is called
:ref:`env_vars_conan_run_tests` will be evaluated to check if tests should run.

Parameters:
- **args** (Optional, Defaulted to ``None``): A list of additional arguments to be passed to the ``cmake`` command. Each argument will be escaped according to the current shell. No extra arguments will be added if ``args=None``.
Expand Down
3 changes: 2 additions & 1 deletion reference/build_helpers/meson.rst
Expand Up @@ -89,7 +89,8 @@ test()
def test(args=None, build_dir=None, target=None)
Executes ninja test target, which usually means building and running unit tests.
Executes ninja test target, which usually means building and running unit tests. When this function
is called :ref:`env_vars_conan_run_tests` will be evaluated to check if tests should run.

Parameters:
- **args** (Optional, Defaulted to ``None``): A list of additional arguments to be passed to the ``ninja`` command. Each argument will be escaped
Expand Down
5 changes: 2 additions & 3 deletions reference/env_vars.rst
Expand Up @@ -477,7 +477,7 @@ or declared in command line when invoking :command:`conan install` to reduce the
See how to retrieve the value with :ref:`tools.get_env() <tools_get_env>` and check a use case
with :ref:`a header only with unit tests recipe <header_only_unit_tests_tip>` while cross building.

See example of build method in ``conanfile.py`` to enable/disable running tests with CMake:
This variable is evaluated inside the build helper call to ``test()`` and will not run the tests if set to ``False``.

.. code-block:: python
Expand All @@ -491,8 +491,7 @@ See example of build method in ``conanfile.py`` to enable/disable running tests
cmake = CMake(self)
cmake.configure()
cmake.build()
if tools.get_env("CONAN_RUN_TESTS", True):
cmake.test()
cmake.test()
.. _env_vars_conan_skip_vs_project_upgrade:

Expand Down

0 comments on commit ed74600

Please sign in to comment.