diff --git a/.travis.yml b/.travis.yml index 78123dc8..40ad6ad1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,8 @@ matrix: script: | set -e cargo test --verbose --features "use_serde" - cargo test --manifest-path tests/feature_check/Cargo.toml --verbose + cargo test -p feature_check --verbose + cargo test -p edition_check --verbose cargo test --verbose --no-default-features --features "autoconvert f32 f64 si use_serde" cargo test --verbose --no-run --no-default-features --features "autoconvert usize u8 u16 u32 u64 isize i8 i16 i32 i64 bigint biguint rational rational32 rational64 bigrational f32 f64 std use_serde" - name: Rustfmt diff --git a/Cargo.toml b/Cargo.toml index 3d4c0a14..ef801304 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ maintenance = { status = "actively-developed" } [workspace] members = [ "uom-macros", + "tests/edition_check", "tests/feature_check", ] diff --git a/examples/mks.rs b/examples/mks.rs index 2f7fa907..b1621c00 100644 --- a/examples/mks.rs +++ b/examples/mks.rs @@ -85,5 +85,5 @@ mod f32 { pub use *; } - Q!(f32::s, f32); + Q!(crate::f32::s, f32); } diff --git a/src/quantity.rs b/src/quantity.rs index b0ca6b27..f664ff62 100644 --- a/src/quantity.rs +++ b/src/quantity.rs @@ -86,7 +86,7 @@ /// # } /// # } /// # mod f32 { -/// # Q!(mks, f32/*, (centimeter, gram, second)*/); +/// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/); /// # } /// # } /// ``` diff --git a/src/si/mod.rs b/src/si/mod.rs index 52892ce5..ac4486b3 100644 --- a/src/si/mod.rs +++ b/src/si/mod.rs @@ -59,12 +59,12 @@ system! { /// [`Quantity`](struct.Quantity.html) type aliases using the default base units and parameterized /// on the underlying storage type. pub mod quantities { - ISQ!(si); + ISQ!(::si); } storage_types! { /// [`Quantity`](struct.Quantity.html) type aliases using the default base units. pub types: All; - ISQ!(si, V); + ISQ!(::si, V); } diff --git a/src/system.rs b/src/system.rs index 930a4a55..b935ea5a 100644 --- a/src/system.rs +++ b/src/system.rs @@ -77,7 +77,7 @@ /// } /// } /// # mod f32 { -/// # Q!(mks, f32/*, (centimeter, gram, second)*/); +/// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/); /// # } /// # } /// ``` @@ -1455,7 +1455,7 @@ macro_rules! system { /// # } /// # } /// mod f32 { - /// Q!(mks, f32/*, (centimeter, gram, second)*/); + /// Q!(super, f32/*, (centimeter, gram, second)*/); /// } /// # } /// ``` diff --git a/src/tests/quantities.rs b/src/tests/quantities.rs index 83e324fe..e9a56a12 100644 --- a/src/tests/quantities.rs +++ b/src/tests/quantities.rs @@ -42,7 +42,7 @@ fn plural() { storage_types! { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); #[test] fn struct_literal() { @@ -118,7 +118,7 @@ mod float { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); #[test] fn floor() { diff --git a/src/tests/quantity.rs b/src/tests/quantity.rs index 2075dfaf..a54707ae 100644 --- a/src/tests/quantity.rs +++ b/src/tests/quantity.rs @@ -3,8 +3,8 @@ storage_types! { use tests::*; - mod f { Q!(tests, super::V); } - mod k { Q!(tests, super::V, (kilometer, kilogram, kelvin)); } + mod f { Q!(crate::tests, super::V); } + mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } #[test] fn new() { @@ -207,7 +207,7 @@ mod fmt { storage_types! { use tests::*; - mod f { Q!(tests, super::V); } + mod f { Q!(crate::tests, super::V); } quickcheck! { #[allow(trivial_casts)] @@ -238,7 +238,7 @@ mod fmt { use tests::*; - mod f { Q!(tests, super::V); } + mod f { Q!(crate::tests, super::V); } quickcheck! { #[allow(trivial_casts)] @@ -261,7 +261,7 @@ mod fmt { use tests::*; - mod f { Q!(tests, super::V); } + mod f { Q!(crate::tests, super::V); } quickcheck! { #[allow(trivial_casts)] @@ -295,8 +295,8 @@ mod non_big { use tests::*; - mod f { Q!(tests, super::V); } - mod k { Q!(tests, super::V, (kilometer, kilogram, kelvin)); } + mod f { Q!(crate::tests, super::V); } + mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } quickcheck! { #[allow(trivial_casts)] @@ -345,8 +345,8 @@ mod float { use tests::*; - mod f { Q!(tests, super::V); } - mod k { Q!(tests, super::V, (kilometer, kilogram, kelvin)); } + mod f { Q!(crate::tests, super::V); } + mod k { Q!(crate::tests, super::V, (kilometer, kilogram, kelvin)); } #[test] fn floor() { diff --git a/src/tests/system.rs b/src/tests/system.rs index 6d3d3180..6dd4da17 100644 --- a/src/tests/system.rs +++ b/src/tests/system.rs @@ -8,7 +8,7 @@ storage_types! { type KilometerFahrenheitBase = Units; - Q!(tests, V); + Q!(crate::tests, V); #[test] fn zero() { @@ -237,7 +237,7 @@ mod prim_int { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] @@ -263,7 +263,7 @@ mod float { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); #[test] fn fp_categories() { @@ -393,7 +393,7 @@ mod signed { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] @@ -423,7 +423,7 @@ mod non_ratio { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); #[test] fn default() { @@ -438,7 +438,7 @@ mod non_big { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] @@ -513,7 +513,7 @@ mod primitive { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); #[test] fn sum() { @@ -555,7 +555,7 @@ mod fixed { use tests::*; - Q!(tests, V); + Q!(crate::tests, V); quickcheck! { #[allow(trivial_casts)] diff --git a/tests/edition_check/Cargo.toml b/tests/edition_check/Cargo.toml new file mode 100644 index 00000000..ec0a26a3 --- /dev/null +++ b/tests/edition_check/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "edition_check" +version = "0.1.0" +edition = "2018" + +[dependencies] +# Include `use_serde` to re-use `uom` compiled by `cargo test --verbose --features "use_serde"` +uom = { path = "../..", features = ["use_serde"] } + +[features] +default = [] diff --git a/tests/edition_check/src/lib.rs b/tests/edition_check/src/lib.rs new file mode 100644 index 00000000..546499ef --- /dev/null +++ b/tests/edition_check/src/lib.rs @@ -0,0 +1,63 @@ +//! Validate that the `system!`, `quantity!`, and `$quantities!` macros generate valid code for the +//! 2018 edition. + +#[macro_use] +extern crate uom; + +mod mks { + mod length { + quantity! { + /// Length (base unit meter, m1). + quantity: Length; "length"; + /// Length dimension, m1. + dimension: Q; + units { + @meter: 1.0E0; "m", "meter", "meters"; + @foot: 3.048E-1; "ft", "foot", "feet"; + } + } + } + + mod mass { + quantity! { + /// Mass (base unit kilogram, kg1). + quantity: Mass; "mass"; + /// Mass dimension, kg1. + dimension: Q; + units { + @kilogram: 1.0; "kg", "kilogram", "kilograms"; + } + } + } + + mod time { + quantity! { + /// Time (base unit second, s1). + quantity: Time; "time"; + /// Time dimension, s1. + dimension: Q; + units { + @second: 1.0; "s", "second", "seconds"; + } + } + } + + system! { + /// System of quantities, Q. + quantities: Q { + length: meter, L; + mass: kilogram, M; + time: second, T; + } + /// System of units, U. + units: U { + mod length::Length, + mod mass::Mass, + mod time::Time, + } + } + + mod f32 { + Q!(crate::mks, f32 /*, (centimeter, gram, second)*/); + } +} diff --git a/tests/feature_check/Cargo.toml b/tests/feature_check/Cargo.toml index 4cf062f0..f65f9720 100644 --- a/tests/feature_check/Cargo.toml +++ b/tests/feature_check/Cargo.toml @@ -3,7 +3,8 @@ name = "feature_check" version = "0.1.0" [dependencies] -uom = { path = "../.." } +# Include `use_serde` to re-use `uom` compiled by `cargo test --verbose --features "use_serde"` +uom = { path = "../..", features = ["use_serde"] } [features] default = [] diff --git a/tests/feature_check/src/lib.rs b/tests/feature_check/src/lib.rs index 50d17dae..e4a09023 100644 --- a/tests/feature_check/src/lib.rs +++ b/tests/feature_check/src/lib.rs @@ -44,7 +44,7 @@ //! mod f32 { //! mod s { pub use *; } //! -//! Q!(f32::s, f32); +//! Q!(crate::f32::s, f32); //! } //! //! fn main() {