title: How can I programmatically set target_os in a unit test?
body: <p>I tried the following approaches:</p>
  <pre class="lang-rust prettyprint-override"><code>fn get_system_extension(&amp;self) -&gt; String {
      if cfg!(target_os = &quot;windows&quot;) {
          String::from(&quot;.lib&quot;)
      } else {
          String::new()
      }
  }
  
  mod test {
      #[allow(unused_imports)]
      use super::*;
  
      use std::env;
  
      #[test]
      fn get_system_extension_one() -&gt; Result&lt;(), CcrustyError&gt; {
          env::set_var(&quot;CARGO_BUILD_TARGET&quot;, &quot;linux&quot;);
  
          let result = get_system_extension();
  
          assert_eq!(String::new(), result);
  
          Ok(())
      }
  
      #[test]
      fn get_system_extension_two() -&gt; Result&lt;(), CcrustyError&gt; {
          env::set_var(&quot;CARGO_CFG_UNIX&quot;, &quot;&quot;);
  
          let result = get_system_extension();
  
          assert_eq!(String::new(), result);
  
          Ok(())
      }
  }
  </code></pre>
  <p>According to <a href="https://doc.rust-lang.org/cargo/reference/environment-variables.html" rel="nofollow noreferrer">the documentation</a> those could be set in a file, but I have no clue how to dynamically link them to tests.</p>