Using different features for regular build and test build

I want to enable different features of dependencies in when using cargo build and when using cargo test. How would I go about this? Is this even supported?

Say I have a crate named lib with the contents of src/lib.rs:

pub fn feature_foo_enabled() -> bool {
    cfg!(feature="foo")
}

And a crate named bin with the contents of src/main.rs:

extern crate lib;

fn main() {
    println!("Foo enabled: {}",lib::feature_foo_enabled());
}

#[test]
fn test() {
    println!("Foo enabled: {}",lib::feature_foo_enabled());
    assert!(false)
}

How do I make these output something different on cargo run and cargo test?

You can add the same dependency as both a normal and dev dependency to add features for tests: rust-postgres-array/Cargo.toml at master · sfackler/rust-postgres-array · GitHub

This seems to result in those features always being included, even for the non-dev version.

Er, that's unfortunate. @alexcrichton that seems like a bug?

Filed as https://github.com/rust-lang/cargo/issues/2596

Thanks!