Skip to content

Commit

Permalink
[ci skip] Correct macros to generate valid 2015/2018 edition code.
Browse files Browse the repository at this point in the history
Doc test on the `$quantities!` macro would fail with the error `no
``mks`` external crate` when the `system!` macro was invoked in a crate
using the 2018 edition. All invocations of the `$quantities!` macro are
corrected and a new test crate, `edition_check`, is added to validate
`uom` can be used in 2018 edition code. Resolves #119.
  • Loading branch information
iliekturtles committed Mar 26, 2019
1 parent 54cc327 commit ddd7039
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ maintenance = { status = "actively-developed" }
[workspace]
members = [
"uom-macros",
"tests/edition_check",
"tests/feature_check",
]

Expand Down
2 changes: 1 addition & 1 deletion examples/mks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ mod f32 {
pub use *;
}

Q!(f32::s, f32);
Q!(crate::f32::s, f32);
}
2 changes: 1 addition & 1 deletion src/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
/// # }
/// # }
/// # mod f32 {
/// # Q!(mks, f32/*, (centimeter, gram, second)*/);
/// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/);
/// # }
/// # }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
/// }
/// }
/// # mod f32 {
/// # Q!(mks, f32/*, (centimeter, gram, second)*/);
/// # Q!(crate::mks, f32/*, (centimeter, gram, second)*/);
/// # }
/// # }
/// ```
Expand Down Expand Up @@ -1455,7 +1455,7 @@ macro_rules! system {
/// # }
/// # }
/// mod f32 {
/// Q!(mks, f32/*, (centimeter, gram, second)*/);
/// Q!(super, f32/*, (centimeter, gram, second)*/);
/// }
/// # }
/// ```
Expand Down
4 changes: 2 additions & 2 deletions src/tests/quantities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn plural() {
storage_types! {
use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

#[test]
fn struct_literal() {
Expand Down Expand Up @@ -118,7 +118,7 @@ mod float {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

#[test]
fn floor() {
Expand Down
18 changes: 9 additions & 9 deletions src/tests/quantity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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() {
Expand Down
16 changes: 8 additions & 8 deletions src/tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ storage_types! {
type KilometerFahrenheitBase = Units<V, length = kilometer, mass = kilogram,
thermodynamic_temperature = degree_fahrenheit>;

Q!(tests, V);
Q!(crate::tests, V);

#[test]
fn zero() {
Expand Down Expand Up @@ -237,7 +237,7 @@ mod prim_int {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

quickcheck! {
#[allow(trivial_casts)]
Expand All @@ -263,7 +263,7 @@ mod float {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

#[test]
fn fp_categories() {
Expand Down Expand Up @@ -393,7 +393,7 @@ mod signed {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

quickcheck! {
#[allow(trivial_casts)]
Expand Down Expand Up @@ -423,7 +423,7 @@ mod non_ratio {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

#[test]
fn default() {
Expand All @@ -438,7 +438,7 @@ mod non_big {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

quickcheck! {
#[allow(trivial_casts)]
Expand Down Expand Up @@ -513,7 +513,7 @@ mod primitive {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

#[test]
fn sum() {
Expand Down Expand Up @@ -555,7 +555,7 @@ mod fixed {

use tests::*;

Q!(tests, V);
Q!(crate::tests, V);

quickcheck! {
#[allow(trivial_casts)]
Expand Down
11 changes: 11 additions & 0 deletions tests/edition_check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 = []
63 changes: 63 additions & 0 deletions tests/edition_check/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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, m<sup>1</sup>).
quantity: Length; "length";
/// Length dimension, m<sup>1</sup>.
dimension: Q<P1 /*length*/, Z0 /*mass*/, Z0 /*time*/>;
units {
@meter: 1.0E0; "m", "meter", "meters";
@foot: 3.048E-1; "ft", "foot", "feet";
}
}
}

mod mass {
quantity! {
/// Mass (base unit kilogram, kg<sup>1</sup>).
quantity: Mass; "mass";
/// Mass dimension, kg<sup>1</sup>.
dimension: Q<Z0 /*length*/, P1 /*mass*/, Z0 /*time*/>;
units {
@kilogram: 1.0; "kg", "kilogram", "kilograms";
}
}
}

mod time {
quantity! {
/// Time (base unit second, s<sup>1</sup>).
quantity: Time; "time";
/// Time dimension, s<sup>1</sup>.
dimension: Q<Z0 /*length*/, Z0 /*mass*/, P1 /*time*/>;
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)*/);
}
}
3 changes: 2 additions & 1 deletion tests/feature_check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
2 changes: 1 addition & 1 deletion tests/feature_check/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
//! mod f32 {
//! mod s { pub use *; }
//!
//! Q!(f32::s, f32);
//! Q!(crate::f32::s, f32);
//! }
//!
//! fn main() {
Expand Down

0 comments on commit ddd7039

Please sign in to comment.