title: How does one test optional features in Rust?
body: <p>I have a package I want to add an optional feature to. I've added an appropriate section to my Cargo.toml:</p>
  
  <pre><code>[features]
  foo = []
  </code></pre>
  
  <p>I wrote an experimental test for the basic functionality of the <code>cfg!</code> macro:</p>
  
  <pre><code>#[test]
  fn testing_with_foo() {
      assert!(cfg!(foo));
  }
  </code></pre>
  
  <p>It looks as though I can activate features during testing via either of the options <code>--features</code> or <code>--all-features</code>:</p>
  
  <pre><code>(master *=) $ cargo help test
  cargo-test 
  Execute all unit and integration tests and build examples of a local package
  
  USAGE:
      cargo test [OPTIONS] [TESTNAME] [-- &lt;args&gt;...]
  
  OPTIONS:
      -q, --quiet                      Display one character per test instead of one line
          ...
          --features &lt;FEATURES&gt;...     Space-separated list of features to activate
          --all-features               Activate all available features
  </code></pre>
  
  <p>Neither <code>cargo test --features foo testing_with_foo</code> nor <code>cargo test --all-features testing_with_foo</code> works, though.</p>
  
  <p>What is the proper way to do this?</p>