title: Passing custom command-line arguments to a Rust test
body: <p>I have a Rust test which delegates to a C++ test suite using <a href="https://github.com/onqtam/doctest/" rel="noreferrer">doctest</a> and wants to pass command-line parameters to it. My first attempt was</p>
  <pre><code>// in mod ffi
  pub fn run_tests(cli_args: &amp;mut [String]) -&gt; bool;
  
  #[test]
  fn run_cpp_test_suite() {
      let mut cli_args: Vec&lt;String&gt; = env::args().collect();
      if !ffi::run_tests(
          cli_args.as_mut_slice(),
      ) {
          panic!(&quot;C++ test suite reported errors&quot;);
      }
  }
  </code></pre>
  <p>Because <code>cargo test help</code> shows</p>
  <pre><code>USAGE:
      cargo.exe test [OPTIONS] [TESTNAME] [-- &lt;args&gt;...]
  </code></pre>
  <p>I expected</p>
  <pre><code>cargo test -- --test-case=&quot;X&quot;
  </code></pre>
  <p>to let <code>run_cpp_test_suite</code> access and pass on the <code>--test-case=&quot;X&quot;</code> parameter. But it doesn't; I get <code>error: Unrecognized option: 'test-case'</code> and <code>cargo test -- --help</code> shows it has a fixed set of options</p>
  <pre><code>Usage: --help [OPTIONS] [FILTER]
  
  Options:
          --include-ignored 
                          Run ignored and not ignored tests
          --ignored       Run only ignored tests
  ...
  </code></pre>
  <p>My other idea was to pass the arguments in an environment variable, that is</p>
  <pre><code>DOCTEST_ARGS=&quot;--test-case='X'&quot; cargo test
  </code></pre>
  <p>but then I need to somehow split that string into arguments (handling at least spaces and quotes correctly) either in Rust or in C++.</p>