Skip to content

Commit

Permalink
Add a feature_check workspace crate to test feature macro hygiene.
Browse files Browse the repository at this point in the history
New `feature_check` crate is a non-default member of the workspace and
verifies that the `storage_types!` macro expands properly based on `uom`'s
features and not features in the calling crate. Part of #61.
  • Loading branch information
iliekturtles committed Apr 16, 2018
1 parent e0aa5ad commit d0efe67
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ install:
build: false
test_script:
- cargo build --verbose --all-features
- cargo test --verbose --features serde
- cargo test --all --verbose --features serde

notifications:
- provider: Email
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ before_script: |
script: |
cargo build --verbose --all-features &&
(test "$TRAVIS_RUST_VERSION" == "1.20.0" || cargo test --verbose --features serde)
(test "$TRAVIS_RUST_VERSION" == "1.20.0" || cargo test --all --verbose --features serde)
after_success: |
test "$TRAVIS_RUST_VERSION" != "stable" || cargo coveralls
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ travis-ci = { repository = "iliekturtles/uom" }
coveralls = { repository = "iliekturtles/uom" }
maintenance = { status = "actively-developed" }

[workspace]
members = ["tests/feature_check"]

[dependencies]
num = "0.1"
serde = { version = "1.0", optional = true, default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions tests/feature_check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "feature_check"
version = "0.1.0"

[dependencies]
uom = { path = "../.." }
37 changes: 37 additions & 0 deletions tests/feature_check/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! Validate that the feature_check crate has no `f32` feature and `storage_types!` still generates
//! code for the `f32` type.
//!
//! ```
//! #[macro_use]
//! extern crate uom;
//!
//! #[cfg(feature = "f32")]
//! compile_error!("Unexpected feature `f32` in feature_check test crate.");
//!
//! storage_types! {
//! types: i32, f32;
//!
//! pub fn do_work(v: V) {}
//! }
//!
//! fn main() {
//! ::f32::do_work(1.0);
//! }
//! ```
//!
//! Validate that `storage_types!` does not generate code for the `i32` type.
//!
//! ```rust,compile_fail
//! #[macro_use]
//! extern crate uom;
//!
//! storage_types! {
//! types: i32, f32;
//!
//! pub fn do_work(v: V) {}
//! }
//!
//! fn main() {
//! ::i32::do_work(1.0);
//! }
//! ```

0 comments on commit d0efe67

Please sign in to comment.