mirror of
https://github.com/servo/servo.git
synced 2025-07-02 21:13:39 +01:00
Add size_of_test crate
This commit is contained in:
parent
1afc89e944
commit
cf2ae86373
6 changed files with 46 additions and 30 deletions
9
components/size_of_test/Cargo.toml
Normal file
9
components/size_of_test/Cargo.toml
Normal file
|
@ -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"
|
28
components/size_of_test/lib.rs
Normal file
28
components/size_of_test/lib.rs
Normal file
|
@ -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!()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue