Closed vext01 closed 6 years ago
Thanks! Is there any particular reason why you'd want to check this at runtime and not compile time? I'd say that usually test are executed as a deployment/build step because the tests are separate binaries which aren't part of the actual program.
Instead of handling such conditions at runtime I'd go for conditional compilation. Either you can use one of the target_*
attributes directly (with #[cfg(target_...)]
) or you could introduce a feature for compiling your program for a particular cpu feature.
To do this add a new feature to your Cargo.toml
[features]
some_cpu_feature = []
Place a gate on the test function
#[cfg(feature = "some_cpu_feature")]
#[test]
fn foo() { ... }
// or if you use a galvanic-test test suite
#[cfg(feature = "some_cpu_feature")]
test foo() { ... }
Now you still need a way to activate the (rust) feature if the cpu feature is present. For this add a build.rs
with the detection code:
...
if (CHECK) {
// printing this to stdout activates the feature in the compilation step
println!("rust-cfg=some_cpu_feature");
}
...
Hi,
I've just found galvanic. Looks nice!
I have a test suite where several tests need to be skipped if the CPU doesn't support a specific feature. It would be neat if there was a way to skip tests based upon a runtime check. Something like:
Would something like this fit inside galvanic?
Thanks