Skip to content

Commit a337b61

Browse files
dekellumnox
authored andcommitted
Move tests, bench and codegen deps to sub-package
Closes #225, #226. This removes the codegen build dependency of the string_cache crate, thereby minimizing dep for users that don't need codegen. To allow the now external integration tests and benchmarks to test the same things, public Atom::is_(static|dynamic|inline) -> bool methods were also added.
1 parent 5f6ad92 commit a337b61

File tree

8 files changed

+353
-299
lines changed

8 files changed

+353
-299
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ os:
99
- linux
1010
script:
1111
- cargo build
12-
- "if [ $TRAVIS_RUST_VERSION = nightly ]; then cargo test --features unstable; fi"
13-
- cargo test
14-
- "cd string-cache-codegen/ && cargo build && cd .."
12+
- cargo test --all
13+
- "cd string-cache-codegen && cargo build && cd .."
14+
- "if [ $TRAVIS_RUST_VERSION = nightly ]; then cd integration-tests && cargo test --features unstable && cd ..; fi"

Cargo.toml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ description = "A string interning library for Rust, developed as part of the Ser
66
license = "MIT / Apache-2.0"
77
repository = "https://github.com/servo/string-cache"
88
documentation = "https://docs.rs/string_cache/"
9-
build = "build.rs"
109

1110
# Do not `exclude` ./string-cache-codegen because we want to include
1211
# ./string-cache-codegen/shared.rs, and `include` is a pain to use
@@ -17,10 +16,6 @@ build = "build.rs"
1716
[lib]
1817
name = "string_cache"
1918

20-
[features]
21-
# Use unstable features to optimize space and time (memory and CPU usage).
22-
unstable = []
23-
2419
[dependencies]
2520
precomputed-hash = "0.1"
2621
lazy_static = "1"
@@ -29,13 +24,12 @@ phf_shared = "0.8"
2924
new_debug_unreachable = "1.0"
3025
string_cache_shared = {path = "./shared", version = "0.3"}
3126

32-
[dev-dependencies]
33-
rand = "0.4"
34-
string_cache_codegen = { version = "0.4", path = "./string-cache-codegen" }
35-
36-
[build-dependencies]
37-
string_cache_codegen = { version = "0.4", path = "./string-cache-codegen" }
38-
3927
[[test]]
4028
name = "small-stack"
4129
harness = false
30+
31+
[workspace]
32+
members = [
33+
"string-cache-codegen",
34+
"integration-tests",
35+
]

integration-tests/Cargo.toml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "integration_tests"
3+
version = "0.0.1"
4+
authors = [ "The Servo Project Developers" ]
5+
build = "build.rs"
6+
publish = false
7+
8+
[lib]
9+
doctest = false
10+
test = true
11+
12+
[features]
13+
14+
# Use unstable features to optimize space and time (memory and CPU usage).
15+
unstable = []
16+
17+
[dependencies]
18+
string_cache = { version = "0.7", path = ".." }
19+
20+
[dev-dependencies]
21+
rand = "0.4"
22+
string_cache_codegen = { version = "0.4", path = "../string-cache-codegen" }
23+
24+
[build-dependencies]
25+
string_cache_codegen = { version = "0.4", path = "../string-cache-codegen" }

build.rs renamed to integration-tests/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44
use std::path::Path;
55

66
fn main() {
7-
string_cache_codegen::AtomType::new("atom::tests::TestAtom", "test_atom!")
7+
string_cache_codegen::AtomType::new("TestAtom", "test_atom!")
88
.atoms(&[
99
"a", "b", "address", "area", "body", "font-weight", "br", "html", "head", "id",
1010
])

src/bench.rs renamed to integration-tests/src/bench.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,20 @@ Furthermore, a large part of the point of interning is to make strings small
2626
and cheap to move around, which isn't reflected in these tests.
2727
2828
*/
29+
use crate::TestAtom;
2930

30-
use atom::tests::TestAtom;
3131
use test::{Bencher, black_box};
3232

3333
// Just shorthand
3434
fn mk(x: &str) -> TestAtom {
3535
TestAtom::from(x)
3636
}
3737

38-
macro_rules! check_type (($name:ident, $x:expr, $p:pat) => (
38+
macro_rules! check_type (($name:ident, $x:expr) => (
3939
// NB: "cargo bench" does not run these!
4040
#[test]
4141
fn $name() {
42-
match unsafe { $x.unpack() } {
43-
$p => (),
44-
_ => panic!("atom has wrong type"),
45-
}
42+
assert!($x, "atom has wrong type");
4643
}
4744
));
4845

@@ -62,12 +59,12 @@ macro_rules! bench_tiny_op (($name:ident, $op:ident, $ctor_x:expr, $ctor_y:expr)
6259
));
6360

6461
macro_rules! bench_one (
65-
(x_static $x:expr, $y:expr) => (check_type!(check_type_x, $x, Static(..)););
66-
(x_inline $x:expr, $y:expr) => (check_type!(check_type_x, $x, Inline(..)););
67-
(x_dynamic $x:expr, $y:expr) => (check_type!(check_type_x, $x, Dynamic(..)););
68-
(y_static $x:expr, $y:expr) => (check_type!(check_type_y, $y, Static(..)););
69-
(y_inline $x:expr, $y:expr) => (check_type!(check_type_y, $y, Inline(..)););
70-
(y_dynamic $x:expr, $y:expr) => (check_type!(check_type_y, $y, Dynamic(..)););
62+
(x_static $x:expr, $y:expr) => (check_type!(check_type_x, $x.is_static()););
63+
(x_inline $x:expr, $y:expr) => (check_type!(check_type_x, $x.is_inline()););
64+
(x_dynamic $x:expr, $y:expr) => (check_type!(check_type_x, $x.is_dynamic()););
65+
(y_static $x:expr, $y:expr) => (check_type!(check_type_y, $y.is_static()););
66+
(y_inline $x:expr, $y:expr) => (check_type!(check_type_y, $y.is_inline()););
67+
(y_dynamic $x:expr, $y:expr) => (check_type!(check_type_y, $y.is_dynamic()););
7168
(is_static $x:expr, $y:expr) => (bench_one!(x_static $x, $y); bench_one!(y_static $x, $y););
7269
(is_inline $x:expr, $y:expr) => (bench_one!(x_inline $x, $y); bench_one!(y_inline $x, $y););
7370
(is_dynamic $x:expr, $y:expr) => (bench_one!(x_dynamic $x, $y); bench_one!(y_dynamic $x, $y););
@@ -134,8 +131,7 @@ macro_rules! bench_all (
134131
use std::string::ToString;
135132
use std::iter::repeat;
136133

137-
use atom::tests::TestAtom;
138-
use atom::UnpackedAtom::{Static, Inline, Dynamic};
134+
use crate::TestAtom;
139135

140136
use super::mk;
141137

0 commit comments

Comments
 (0)