本文档翻译自:https://docs.conan.io/en/latest/reference/commands/creator/test.html

    1. $ conan test [-h] [-tbf TEST_BUILD_FOLDER] [-b [BUILD]] [-r REMOTE] [-u]
    2. [-l [LOCKFILE]] [-e ENV_HOST] [-e:b ENV_BUILD]
    3. [-e:h ENV_HOST] [-o OPTIONS_HOST] [-o:b OPTIONS_BUILD]
    4. [-o:h OPTIONS_HOST] [-pr PROFILE_HOST] [-pr:b PROFILE_BUILD]
    5. [-pr:h PROFILE_HOST] [-s SETTINGS_HOST]
    6. [-s:b SETTINGS_BUILD] [-s:h SETTINGS_HOST]
    7. path reference

    使用test()方法从conanfile.py测试使用它的程序包。
    此命令将安装conanfile依赖项(包括已测试的软件包),调用“ conan build”以构建测试应用程序,并最终执行test()方法。 测试配方不需要名称或版本,也不要求package()或package_info()方法的定义。 要测试的程序包必须存在于本地缓存或任何已配置的远程服务器中。

    1. positional arguments:
    2. path Path to the "testing" folder containing a conanfile.py
    3. or to a recipe file with test() methode.g. conan
    4. test_package/conanfile.py pkg/version@user/channel
    5. reference pkg/version@user/channel of the package to be tested
    6. optional arguments:
    7. -h, --help show this help message and exit
    8. -tbf TEST_BUILD_FOLDER, --test-build-folder TEST_BUILD_FOLDER
    9. Working directory of the build process.
    10. -b [BUILD], --build [BUILD]
    11. Optional, specify which packages to build from source.
    12. Combining multiple '--build' options on one command
    13. line is allowed. For dependencies, the optional
    14. 'build_policy' attribute in their conanfile.py takes
    15. precedence over the command line parameter. Possible
    16. parameters: --build Force build for all packages, do
    17. not use binary packages. --build=never Disallow build
    18. for all packages, use binary packages or fail if a
    19. binary package is not found. Cannot be combined with
    20. other '--build' options. --build=missing Build
    21. packages from source whose binary package is not
    22. found. --build=outdated Build packages from source
    23. whose binary package was not generated from the latest
    24. recipe or is not found. --build=cascade Build packages
    25. from source that have at least one dependency being
    26. built from source. --build=[pattern] Build packages
    27. from source whose package reference matches the
    28. pattern. The pattern uses 'fnmatch' style wildcards.
    29. Default behavior: If you omit the '--build' option,
    30. the 'build_policy' attribute in conanfile.py will be
    31. used if it exists, otherwise the behavior is like '--
    32. build=never'.
    33. -r REMOTE, --remote REMOTE
    34. Look in the specified remote server
    35. -u, --update Check updates exist from upstream remotes
    36. -l [LOCKFILE], --lockfile [LOCKFILE]
    37. Path to a lockfile or folder containing 'conan.lock'
    38. file. Lockfile can be updated if packages change
    39. -e ENV_HOST, --env ENV_HOST
    40. Environment variables that will be set during the
    41. package build (host machine). e.g.: -e
    42. CXX=/usr/bin/clang++
    43. -e:b ENV_BUILD, --env:build ENV_BUILD
    44. Environment variables that will be set during the
    45. package build (build machine). e.g.: -e:b
    46. CXX=/usr/bin/clang++
    47. -e:h ENV_HOST, --env:host ENV_HOST
    48. Environment variables that will be set during the
    49. package build (host machine). e.g.: -e:h
    50. CXX=/usr/bin/clang++
    51. -o OPTIONS_HOST, --options OPTIONS_HOST
    52. Define options values (host machine), e.g.: -o
    53. Pkg:with_qt=true
    54. -o:b OPTIONS_BUILD, --options:build OPTIONS_BUILD
    55. Define options values (build machine), e.g.: -o:b
    56. Pkg:with_qt=true
    57. -o:h OPTIONS_HOST, --options:host OPTIONS_HOST
    58. Define options values (host machine), e.g.: -o:h
    59. Pkg:with_qt=true
    60. -pr PROFILE_HOST, --profile PROFILE_HOST
    61. Apply the specified profile to the host machine
    62. -pr:b PROFILE_BUILD, --profile:build PROFILE_BUILD
    63. Apply the specified profile to the build machine
    64. -pr:h PROFILE_HOST, --profile:host PROFILE_HOST
    65. Apply the specified profile to the host machine
    66. -s SETTINGS_HOST, --settings SETTINGS_HOST
    67. Settings to build the package, overwriting the
    68. defaults (host machine). e.g.: -s compiler=gcc
    69. -s:b SETTINGS_BUILD, --settings:build SETTINGS_BUILD
    70. Settings to build the package, overwriting the
    71. defaults (build machine). e.g.: -s:b compiler=gcc
    72. -s:h SETTINGS_HOST, --settings:host SETTINGS_HOST
    73. Settings to build the package, overwriting the
    74. defaults (host machine). e.g.: -s:h compiler=gcc

    该命令可用于测试以前已构建的现有软件包(例如,使用conan create)。 如果在conanfile.py之外找到了test_package文件夹,或者为conan create提供了—test-folder参数,conan create将自动运行此测试。

    Example:

    1. $ conan new hello/0.1 -s -t
    2. $ mv test_package test_package2
    3. $ conan create . user/testing
    4. # doesn't automatically run test, it has been renamed
    5. # now run test
    6. $ conan test test_package2 hello/0.1@user/testing

    测试包文件夹可以位于其他位置,甚至可以应用于包的不同版本。