aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock5
-rw-r--r--components/size_of_test/Cargo.toml9
-rw-r--r--components/size_of_test/lib.rs28
-rw-r--r--tests/unit/layout/Cargo.toml1
-rw-r--r--tests/unit/layout/lib.rs1
-rw-r--r--tests/unit/layout/size_of.rs32
6 files changed, 46 insertions, 30 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7eea47f577f..2b9e5c06ab8 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1407,6 +1407,7 @@ dependencies = [
"atomic_refcell 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"layout 0.0.1",
"script_layout_interface 0.0.1",
+ "size_of_test 0.0.1",
]
[[package]]
@@ -2733,6 +2734,10 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "size_of_test"
+version = "0.0.1"
+
+[[package]]
name = "slab"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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!()
+ )
+ }
+ }
+ }
+}
diff --git a/tests/unit/layout/Cargo.toml b/tests/unit/layout/Cargo.toml
index d0c5024a73e..358d5054ca0 100644
--- a/tests/unit/layout/Cargo.toml
+++ b/tests/unit/layout/Cargo.toml
@@ -13,3 +13,4 @@ doctest = false
atomic_refcell = "0.1"
layout = {path = "../../../components/layout"}
script_layout_interface = {path = "../../../components/script_layout_interface"}
+size_of_test = {path = "../../../components/size_of_test"}
diff --git a/tests/unit/layout/lib.rs b/tests/unit/layout/lib.rs
index 12091f920d6..8313aed46a8 100644
--- a/tests/unit/layout/lib.rs
+++ b/tests/unit/layout/lib.rs
@@ -5,6 +5,7 @@
extern crate atomic_refcell;
extern crate layout;
extern crate script_layout_interface;
+#[macro_use] extern crate size_of_test;
#[cfg(test)] mod align_of;
#[cfg(all(test, target_pointer_width = "64"))] mod size_of;
diff --git a/tests/unit/layout/size_of.rs b/tests/unit/layout/size_of.rs
index 08d11df86cd..6b40be0fd86 100644
--- a/tests/unit/layout/size_of.rs
+++ b/tests/unit/layout/size_of.rs
@@ -4,34 +4,6 @@
use layout::Fragment;
use layout::SpecificFragmentInfo;
-use std::mem::size_of;
-fn check_size_for(name: &'static str, expected: usize, actual: usize) {
- if actual < expected {
- panic!("Your changes have decreased the stack size of {} \
- from {} to {}. Good work! Please update the size in tests/unit/layout/size_of.rs",
- name, expected, actual);
- }
-
- if actual > expected {
- 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 \
- tests/unit/layout/size_of.rs.",
- name, expected, actual);
- }
-}
-
-#[test]
-fn test_size_of_fragment() {
- let expected = 160;
- let actual = size_of::<Fragment>();
- check_size_for("layout::fragment::Fragment", expected, actual);
-}
-
-#[test]
-fn test_size_of_specific_fragment_info() {
- let expected = 24;
- let actual = size_of::<SpecificFragmentInfo>();
- check_size_for("layout::fragment::SpecificFragmentInfo", expected, actual);
-}
+size_of_test!(test_size_of_fragment, Fragment, 160);
+size_of_test!(test_size_of_specific_fragment_info, SpecificFragmentInfo, 24);