diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2017-05-15 15:28:56 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2017-05-16 10:12:51 +0200 |
commit | cf2ae86373cb4565f37d6a204a0d0c8096fa7e6c (patch) | |
tree | f2f5407fd5a8265ab58ea1d53d7bd0435c718cf4 /components | |
parent | 1afc89e944c7ea7e4510b4b678a95a8faaa309b1 (diff) | |
download | servo-cf2ae86373cb4565f37d6a204a0d0c8096fa7e6c.tar.gz servo-cf2ae86373cb4565f37d6a204a0d0c8096fa7e6c.zip |
Add size_of_test crate
Diffstat (limited to 'components')
-rw-r--r-- | components/size_of_test/Cargo.toml | 9 | ||||
-rw-r--r-- | components/size_of_test/lib.rs | 28 |
2 files changed, 37 insertions, 0 deletions
diff --git a/components/size_of_test/Cargo.toml b/components/size_of_test/Cargo.toml new file mode 100644 index 00000000000..bb6c8182443 --- /dev/null +++ b/components/size_of_test/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "size_of_test" +version = "0.0.1" +authors = ["The Servo Project Developers"] +license = "MPL-2.0" +publish = false + +[lib] +path = "lib.rs" diff --git a/components/size_of_test/lib.rs b/components/size_of_test/lib.rs new file mode 100644 index 00000000000..fdd2cd62ec9 --- /dev/null +++ b/components/size_of_test/lib.rs @@ -0,0 +1,28 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#[macro_export] +macro_rules! size_of_test { + ($testname: ident, $t: ty, $expected_size: expr) => { + #[test] + fn $testname() { + let new = ::std::mem::size_of::<$t>(); + let old = $expected_size; + if new < old { + panic!( + "Your changes have decreased the stack size of {} from {} to {}. \ + Good work! Please update the expected size in {}.", + stringify!($t), old, new, file!() + ) + } else if new > old { + panic!( + "Your changes have increased the stack size of {} from {} to {}. \ + Please consider choosing a design which avoids this increase. \ + If you feel that the increase is necessary, update the size in {}.", + stringify!($t), old, new, file!() + ) + } + } + } +} |