| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| |
| |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| |
| <title>add_test — CMake 3.8.2 Documentation</title> |
| |
| |
| <link rel="stylesheet" href="../_static/cmake.css" type="text/css" /> |
| <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT: '../', |
| VERSION: '3.8.2', |
| COLLAPSE_INDEX: false, |
| FILE_SUFFIX: '.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '.txt' |
| }; |
| </script> |
| <script type="text/javascript" src="../_static/jquery.js"></script> |
| <script type="text/javascript" src="../_static/underscore.js"></script> |
| <script type="text/javascript" src="../_static/doctools.js"></script> |
| <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/> |
| <link rel="index" title="Index" href="../genindex.html" /> |
| <link rel="search" title="Search" href="../search.html" /> |
| <link rel="next" title="aux_source_directory" href="aux_source_directory.html" /> |
| <link rel="prev" title="add_subdirectory" href="add_subdirectory.html" /> |
| </head> |
| <body role="document"> |
| <div class="related" role="navigation" aria-label="related navigation"> |
| <h3>Navigation</h3> |
| <ul> |
| <li class="right" style="margin-right: 10px"> |
| <a href="../genindex.html" title="General Index" |
| accesskey="I">index</a></li> |
| <li class="right" > |
| <a href="aux_source_directory.html" title="aux_source_directory" |
| accesskey="N">next</a> |</li> |
| <li class="right" > |
| <a href="add_subdirectory.html" title="add_subdirectory" |
| accesskey="P">previous</a> |</li> |
| <li> |
| <img src="../_static/cmake-logo-16.png" alt="" |
| style="vertical-align: middle; margin-top: -2px" /> |
| </li> |
| <li> |
| <a href="https://cmake.org/">CMake</a> » |
| </li> |
| <li> |
| <a href="../index.html">3.8.2 Documentation</a> » |
| </li> |
| |
| <li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" accesskey="U">cmake-commands(7)</a> »</li> |
| </ul> |
| </div> |
| |
| <div class="document"> |
| <div class="documentwrapper"> |
| <div class="bodywrapper"> |
| <div class="body" role="main"> |
| |
| <div class="section" id="add-test"> |
| <span id="command:add_test"></span><h1>add_test<a class="headerlink" href="#add-test" title="Permalink to this headline">ΒΆ</a></h1> |
| <p>Add a test to the project to be run by <span class="target" id="index-0-manual:ctest(1)"></span><a class="reference internal" href="../manual/ctest.1.html#manual:ctest(1)" title="ctest(1)"><code class="xref cmake cmake-manual docutils literal"><span class="pre">ctest(1)</span></code></a>.</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">add_test</span><span class="p">(</span><span class="n">NAME</span> <span class="o"><</span><span class="n">name</span><span class="o">></span> <span class="n">COMMAND</span> <span class="o"><</span><span class="n">command</span><span class="o">></span> <span class="p">[</span><span class="o"><</span><span class="n">arg</span><span class="o">>...</span><span class="p">]</span> |
| <span class="p">[</span><span class="n">CONFIGURATIONS</span> <span class="o"><</span><span class="n">config</span><span class="o">>...</span><span class="p">]</span> |
| <span class="p">[</span><span class="n">WORKING_DIRECTORY</span> <span class="o"><</span><span class="nb">dir</span><span class="o">></span><span class="p">])</span> |
| </pre></div> |
| </div> |
| <p>Add a test called <code class="docutils literal"><span class="pre"><name></span></code>. The test name may not contain spaces, |
| quotes, or other characters special in CMake syntax. The options are:</p> |
| <dl class="docutils"> |
| <dt><code class="docutils literal"><span class="pre">COMMAND</span></code></dt> |
| <dd>Specify the test command-line. If <code class="docutils literal"><span class="pre"><command></span></code> specifies an |
| executable target (created by <span class="target" id="index-0-command:add_executable"></span><a class="reference internal" href="add_executable.html#command:add_executable" title="add_executable"><code class="xref cmake cmake-command docutils literal"><span class="pre">add_executable()</span></code></a>) it will |
| automatically be replaced by the location of the executable created |
| at build time.</dd> |
| <dt><code class="docutils literal"><span class="pre">CONFIGURATIONS</span></code></dt> |
| <dd>Restrict execution of the test only to the named configurations.</dd> |
| <dt><code class="docutils literal"><span class="pre">WORKING_DIRECTORY</span></code></dt> |
| <dd>Set the <span class="target" id="index-0-prop_test:WORKING_DIRECTORY"></span><a class="reference internal" href="../prop_test/WORKING_DIRECTORY.html#prop_test:WORKING_DIRECTORY" title="WORKING_DIRECTORY"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">WORKING_DIRECTORY</span></code></a> test property to |
| specify the working directory in which to execute the test. |
| If not specified the test will be run with the current working |
| directory set to the build directory corresponding to the |
| current source directory.</dd> |
| </dl> |
| <p>The given test command is expected to exit with code <code class="docutils literal"><span class="pre">0</span></code> to pass and |
| non-zero to fail, or vice-versa if the <span class="target" id="index-0-prop_test:WILL_FAIL"></span><a class="reference internal" href="../prop_test/WILL_FAIL.html#prop_test:WILL_FAIL" title="WILL_FAIL"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">WILL_FAIL</span></code></a> test |
| property is set. Any output written to stdout or stderr will be |
| captured by <span class="target" id="index-1-manual:ctest(1)"></span><a class="reference internal" href="../manual/ctest.1.html#manual:ctest(1)" title="ctest(1)"><code class="xref cmake cmake-manual docutils literal"><span class="pre">ctest(1)</span></code></a> but does not affect the pass/fail status |
| unless the <span class="target" id="index-0-prop_test:PASS_REGULAR_EXPRESSION"></span><a class="reference internal" href="../prop_test/PASS_REGULAR_EXPRESSION.html#prop_test:PASS_REGULAR_EXPRESSION" title="PASS_REGULAR_EXPRESSION"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">PASS_REGULAR_EXPRESSION</span></code></a> or |
| <span class="target" id="index-0-prop_test:FAIL_REGULAR_EXPRESSION"></span><a class="reference internal" href="../prop_test/FAIL_REGULAR_EXPRESSION.html#prop_test:FAIL_REGULAR_EXPRESSION" title="FAIL_REGULAR_EXPRESSION"><code class="xref cmake cmake-prop_test docutils literal"><span class="pre">FAIL_REGULAR_EXPRESSION</span></code></a> test property is used.</p> |
| <p>The <code class="docutils literal"><span class="pre">COMMAND</span></code> and <code class="docutils literal"><span class="pre">WORKING_DIRECTORY</span></code> options may use “generator |
| expressions” with the syntax <code class="docutils literal"><span class="pre">$<...></span></code>. See the |
| <span class="target" id="index-0-manual:cmake-generator-expressions(7)"></span><a class="reference internal" href="../manual/cmake-generator-expressions.7.html#manual:cmake-generator-expressions(7)" title="cmake-generator-expressions(7)"><code class="xref cmake cmake-manual docutils literal"><span class="pre">cmake-generator-expressions(7)</span></code></a> manual for available expressions.</p> |
| <p>Example usage:</p> |
| <div class="highlight-default"><div class="highlight"><pre><span></span>add_test(NAME mytest |
| COMMAND testDriver --config $<CONFIGURATION> |
| --exe $<TARGET_FILE:myexe>) |
| </pre></div> |
| </div> |
| <p>This creates a test <code class="docutils literal"><span class="pre">mytest</span></code> whose command runs a <code class="docutils literal"><span class="pre">testDriver</span></code> tool |
| passing the configuration name and the full path to the executable |
| file produced by target <code class="docutils literal"><span class="pre">myexe</span></code>.</p> |
| <div class="admonition note"> |
| <p class="first admonition-title">Note</p> |
| <p class="last">CMake will generate tests only if the <span class="target" id="index-0-command:enable_testing"></span><a class="reference internal" href="enable_testing.html#command:enable_testing" title="enable_testing"><code class="xref cmake cmake-command docutils literal"><span class="pre">enable_testing()</span></code></a> |
| command has been invoked. The <span class="target" id="index-0-module:CTest"></span><a class="reference internal" href="../module/CTest.html#module:CTest" title="CTest"><code class="xref cmake cmake-module docutils literal"><span class="pre">CTest</span></code></a> module invokes the |
| command automatically when the <code class="docutils literal"><span class="pre">BUILD_TESTING</span></code> option is <code class="docutils literal"><span class="pre">ON</span></code>.</p> |
| </div> |
| <hr class="docutils" /> |
| <div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">add_test</span><span class="p">(</span><span class="o"><</span><span class="n">name</span><span class="o">></span> <span class="o"><</span><span class="n">command</span><span class="o">></span> <span class="p">[</span><span class="o"><</span><span class="n">arg</span><span class="o">>...</span><span class="p">])</span> |
| </pre></div> |
| </div> |
| <p>Add a test called <code class="docutils literal"><span class="pre"><name></span></code> with the given command-line. Unlike |
| the above <code class="docutils literal"><span class="pre">NAME</span></code> signature no transformation is performed on the |
| command-line to support target names or generator expressions.</p> |
| </div> |
| |
| |
| </div> |
| </div> |
| </div> |
| <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> |
| <div class="sphinxsidebarwrapper"> |
| <h4>Previous topic</h4> |
| <p class="topless"><a href="add_subdirectory.html" |
| title="previous chapter">add_subdirectory</a></p> |
| <h4>Next topic</h4> |
| <p class="topless"><a href="aux_source_directory.html" |
| title="next chapter">aux_source_directory</a></p> |
| <div role="note" aria-label="source link"> |
| <h3>This Page</h3> |
| <ul class="this-page-menu"> |
| <li><a href="../_sources/command/add_test.rst.txt" |
| rel="nofollow">Show Source</a></li> |
| </ul> |
| </div> |
| <div id="searchbox" style="display: none" role="search"> |
| <h3>Quick search</h3> |
| <form class="search" action="../search.html" method="get"> |
| <div><input type="text" name="q" /></div> |
| <div><input type="submit" value="Go" /></div> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| <script type="text/javascript">$('#searchbox').show(0);</script> |
| </div> |
| </div> |
| <div class="clearer"></div> |
| </div> |
| <div class="related" role="navigation" aria-label="related navigation"> |
| <h3>Navigation</h3> |
| <ul> |
| <li class="right" style="margin-right: 10px"> |
| <a href="../genindex.html" title="General Index" |
| >index</a></li> |
| <li class="right" > |
| <a href="aux_source_directory.html" title="aux_source_directory" |
| >next</a> |</li> |
| <li class="right" > |
| <a href="add_subdirectory.html" title="add_subdirectory" |
| >previous</a> |</li> |
| <li> |
| <img src="../_static/cmake-logo-16.png" alt="" |
| style="vertical-align: middle; margin-top: -2px" /> |
| </li> |
| <li> |
| <a href="https://cmake.org/">CMake</a> » |
| </li> |
| <li> |
| <a href="../index.html">3.8.2 Documentation</a> » |
| </li> |
| |
| <li class="nav-item nav-item-1"><a href="../manual/cmake-commands.7.html" >cmake-commands(7)</a> »</li> |
| </ul> |
| </div> |
| <div class="footer" role="contentinfo"> |
| © Copyright 2000-2017 Kitware, Inc. and Contributors. |
| Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.2. |
| </div> |
| </body> |
| </html> |