Buck: cxx_test()

cxx_test()

This is liable to change in the future.

A cxx_test() rule builds a C/C++ binary against a C/C++ testing framework and runs it as part of buck test.

Arguments

  • name (required) #

    The name of the rule.

  • srcs (defaults to []) #

    The set of C, C++, Objective-C, Objective-C++, or assembly source files to be preprocessed, compiled, and assembled by this rule. We determine which stages to run on each input source based on its file extension. See the GCC documentation for more detail on how file extensions are interpreted. Each element can be either a string specifying a source file (e.g. 'foo/bar.c') or a tuple of a string specifying a source file and a list of compilation flags (e.g. ('foo/bar.c', ['-Wall', '-Werror'])). In the latter case the specified flags will be used in addition to the rule's other flags when preprocessing and compiling that file (if applicable).

  • headers (defaults to []) #

    The set of header files that are made available for inclusion to the source files in this target. These should be specified as either a list of header files or a dictionary of header names to header files. The header name can contain forward slashes (/). The headers can be included with #include "$HEADER_NAMESPACE/$HEADER_NAME" or #include <$HEADER_NAMESPACE/$HEADER_NAME>, where $HEADER_NAMESPACE is the value of the target's header_namespace attribute, and $HEADER_NAME is the header name if specified, and the filename of the header file otherwise. See header_namespace for more information.

  • preprocessor_flags (defaults to []) #

    Flags to use when preprocessing any of the above sources (which require preprocessing).

  • compiler_flags (defaults to []) #

    Flags to use when compiling any of the above sources (which require compilation).

  • linker_flags (defaults to []) #

    Flags to use whenever this rule is involved in a link operation (e.g linked into an executable or shared library).

  • precompiled_header (defaults to None) #

    Path to a cxx_precompiled_header to use when compiling this rule's sources. The precompiled header (PCH) is built on-demand, using compiler flags matching those used in this rule's compile jobs. This is to ensure compatibility between this rule and the PCH. Also, this rule will inherit additional deps from the PCH rule, and as a result, additional include paths as well (e.g. -I, -isystem, -iquote path lists, and framework paths specified with -F).

  • resources (defaults to []) #

    Additional data or source files which this test uses.

  • framework (defaults to "gtest") #

    The testing framework to build against and run with. We currently support gtest and boost.

    When set to gtest, you must also set cxx.gtest_dep.

  • env (defaults to {}) #

    A map of environment names and values to set when running the test.

    It is also possible to expand references to other rules within the values of these environment variables, using builtin string parameter macros:

    $(location //path/to:target)
    Expands to the location of the output of the build rule. This means that you can refer to these without needing to be aware of how Buck is storing data on the disk mid-build.

  • args (defaults to {}) #

    A list of additional arguments to pass to the test when it's run.

    It is also possible to expand references to other rules within these arguments, using builtin string parameter macros:

    $(location //path/to:target)
    Expands to the location of the output of the build rule. This means that you can refer to these without needing to be aware of how Buck is storing data on the disk mid-build.

  • run_test_separately (defaults to False) #

    If set to True, the test(s) in this rule are run separately from all other tests. (This is useful for integration tests which access a physical device or other limited resource.)

    If unset, the test(s) in this rule in parallel with all other tests.

  • test_rule_timeout_ms (defaults to []) #

    If set specifies the maximum amount of time (in milliseconds) in which all of the tests in this rule should complete. This overrides the default rule_timeout if any has been specified in test.rule_timeout.

  • visibility (defaults to []) #

    List of build target patterns that identify the build rules that can include this rule in its deps.

  • licenses (defaults to []) #

    Set of license files for this library. To get the list of license files for a given build rule and all of its dependencies, you can use buck query.

Examples

# A rule that builds and runs C/C++ test using gtest.
cxx_test(
  name = 'echo_test',
  srcs = [
    'echo_test.cpp',
  ],
)