Skip to content

Commit

Permalink
move specified values size testing entirely into stylo_tests
Browse files Browse the repository at this point in the history
This change means that stylo_tests doesn't depend on a version of the
style crate with the `testing` feature defined.
  • Loading branch information
froydnj committed Aug 4, 2017
1 parent e962ac3 commit 0189688
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 48 deletions.
38 changes: 1 addition & 37 deletions components/style/properties/properties.mako.rs
Expand Up @@ -3414,7 +3414,7 @@ macro_rules! css_properties_accessors {
}
}


#[macro_export]
macro_rules! longhand_properties_idents {
($macro_name: ident) => {
$macro_name! {
Expand All @@ -3424,39 +3424,3 @@ macro_rules! longhand_properties_idents {
}
}
}

/// Testing function to check the size of all SpecifiedValues.
#[cfg(feature = "testing")]
pub fn test_size_of_specified_values() {
use std::mem::size_of;
let threshold = 24;

let mut longhands = vec![];
% for property in data.longhands:
longhands.push(("${property.name}",
size_of::<longhands::${property.ident}::SpecifiedValue>(),
${"true" if property.boxed else "false"}));
% endfor

let mut failing_messages = vec![];

for specified_value in longhands {
if specified_value.1 > threshold && !specified_value.2 {
failing_messages.push(
format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \
increasing the size may negative affect style system performance. Please consider \
using `boxed=\"True\"` in this longhand.",
specified_value.0, specified_value.1, threshold));
} else if specified_value.1 <= threshold && specified_value.2 {
failing_messages.push(
format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
specified_value.0, specified_value.1, threshold));
}
}

if !failing_messages.is_empty() {
panic!("{}", failing_messages.join("\n\n"));
}
}
4 changes: 3 additions & 1 deletion tests/unit/style/lib.rs
Expand Up @@ -19,7 +19,7 @@ extern crate servo_atoms;
extern crate servo_config;
extern crate servo_url;
#[macro_use] extern crate size_of_test;
extern crate style;
#[macro_use] extern crate style;
extern crate style_traits;
extern crate test;

Expand All @@ -32,6 +32,8 @@ mod parsing;
mod properties;
mod rule_tree;
mod size_of;
#[path = "../stylo/specified_values.rs"]
mod specified_values;
mod str;
mod stylesheets;
mod stylist;
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/style/size_of.rs
Expand Up @@ -12,8 +12,3 @@ size_of_test!(test_size_of_property_declaration, properties::PropertyDeclaration
// This is huge, but we allocate it on the stack and then never move it,
// we only pass `&mut SourcePropertyDeclaration` references around.
size_of_test!(test_size_of_parsed_declaration, properties::SourcePropertyDeclaration, 576);

#[test]
fn size_of_specified_values() {
::style::properties::test_size_of_specified_values();
}
1 change: 1 addition & 0 deletions tests/unit/stylo/lib.rs
Expand Up @@ -14,6 +14,7 @@ extern crate style_traits;

mod sanity_checks;
mod size_of;
mod specified_values;

mod servo_function_signatures;

Expand Down
5 changes: 0 additions & 5 deletions tests/unit/stylo/size_of.rs
Expand Up @@ -47,8 +47,3 @@ size_of_test!(test_size_of_rule_node, RuleNode, 80);
// This is huge, but we allocate it on the stack and then never move it,
// we only pass `&mut SourcePropertyDeclaration` references around.
size_of_test!(test_size_of_parsed_declaration, style::properties::SourcePropertyDeclaration, 704);

#[test]
fn size_of_specified_values() {
::style::properties::test_size_of_specified_values();
}
49 changes: 49 additions & 0 deletions tests/unit/stylo/specified_values.rs
@@ -0,0 +1,49 @@
/* 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/. */

use style;

#[test]
fn size_of_specified_values() {
use std::mem::size_of;
let threshold = 24;

let mut bad_properties = vec![];

macro_rules! check_property {
( $( { $name: ident, $boxed: expr } )+ ) => {
$(
let size = size_of::<style::properties::longhands::$name::SpecifiedValue>();
let is_boxed = $boxed;
if (!is_boxed && size > threshold) || (is_boxed && size <= threshold) {
bad_properties.push(("$name", size, is_boxed));
}
)+
}
}

longhand_properties_idents!(check_property);

let mut failing_messages = vec![];

for bad_prop in bad_properties {
if !bad_prop.2 {
failing_messages.push(
format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
currently {}. SpecifiedValues affect size of PropertyDeclaration enum and \
increasing the size may negative affect style system performance. Please consider \
using `boxed=\"True\"` in this longhand.",
bad_prop.0, bad_prop.1, threshold));
} else if bad_prop.2 {
failing_messages.push(
format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
bad_prop.0, bad_prop.1, threshold));
}
}

if !failing_messages.is_empty() {
panic!("{}", failing_messages.join("\n\n"));
}
}

0 comments on commit 0189688

Please sign in to comment.