Skip to content

Commit 9bd3abe

Browse files
authored
Auto merge of #274 - YoniFeng:common-usage-tests, r=jdm
test: add common dependents' usage As a response to #271, added tests with common usage. I modified the project structure, so I could make use of the canonical (according to [the docs](https://doc.rust-lang.org/book/ch11-03-test-organization.html)) "external tests" support. I'm not familiar with the nitty gritty and ramifications of this change, so absolutely looking for guidance/advice/instructions. Concerns I'm aware of: 1. Integration tests can't have their own `build.rs`, so I moved it to be under the main crate. Does it matter that it'll run with `cargo build` now, where previously it would only run with `cargo test` 2. The `bench.rs` is apparently only supported in nightly? It didn't run with `cargo test`. Is it in use at all? How can I make sure that it runs properly under the new structure (with the same command that would run it previously)?
2 parents df9093d + 126c173 commit 9bd3abe

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

integration-tests/src/common-usage.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// Test common usage by popular dependents (html5ever, lalrpop, browserlists-rs), to ensure no API-surface breaking changes
2+
/// Created after https://github.com/servo/string-cache/issues/271
3+
use std::collections::HashMap;
4+
5+
use crate::Atom;
6+
use crate::TestAtom;
7+
8+
#[test]
9+
fn usage_with_hashmap() {
10+
let mut map: HashMap<TestAtom, i32> = HashMap::new();
11+
12+
map.insert(test_atom!("area"), 1);
13+
map.insert("str_into".into(), 2);
14+
map.insert("atom_from".into(), 3);
15+
16+
assert_eq!(map.get(&"area".into()).unwrap(), &1);
17+
assert_eq!(map.get(&"str_into".into()).unwrap(), &2);
18+
assert_eq!(map.get(&Atom::from("atom_from")).unwrap(), &3);
19+
}

integration-tests/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ fn test_try_static() {
296296
assert!(Atom::try_static("not in the static table").is_none());
297297
}
298298

299+
#[cfg(test)]
300+
#[path = "common-usage.rs"]
301+
mod common_usage;
302+
299303
#[cfg(all(test, feature = "unstable"))]
300304
#[path = "bench.rs"]
301305
mod bench;

0 commit comments

Comments
 (0)