Skip to content

Commit bb5695b

Browse files
committed
auto merge of #15245 : sfackler/rust/coretest, r=alexcrichton
Libcore's test infrastructure is complicated by the fact that many lang items are defined in the crate. The current approach (realcore/realstd imports) is hacky and hard to work with (tests inside of core::cmp haven't been run for months!). Moving tests to a separate crate does mean that they can only test the public API of libcore, but I don't feel that that is too much of an issue. The only tests that I had to get rid of were some checking the various numeric formatters, but those are also exercised through normal format! calls in other tests.
2 parents a490871 + 1ed646e commit bb5695b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3348
-3339
lines changed

mk/tests.mk

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
######################################################################
1515

1616
# The names of crates that must be tested
17-
TEST_TARGET_CRATES = $(TARGET_CRATES)
17+
18+
# libcore tests are in a separate crate
19+
DEPS_coretest :=
20+
$(eval $(call RUST_CRATE,coretest))
21+
22+
TEST_TARGET_CRATES = $(filter-out core,$(TARGET_CRATES)) coretest
1823
TEST_DOC_CRATES = $(DOC_CRATES)
1924
TEST_HOST_CRATES = $(HOST_CRATES)
2025
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
@@ -172,7 +177,7 @@ check-notidy: cleantmptestlogs cleantestlibs all check-stage2
172177
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
173178

174179
check-lite: cleantestlibs cleantmptestlogs \
175-
$(foreach crate,$(TARGET_CRATES),check-stage2-$(crate)) \
180+
$(foreach crate,$(TEST_TARGET_CRATES),check-stage2-$(crate)) \
176181
check-stage2-rpass \
177182
check-stage2-rfail check-stage2-cfail check-stage2-rmake
178183
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log

src/liballoc/owned.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,51 @@ impl fmt::Show for Box<Any> {
146146
f.pad("Box<Any>")
147147
}
148148
}
149+
150+
#[cfg(test)]
151+
mod test {
152+
#[test]
153+
fn test_owned_clone() {
154+
let a = box 5i;
155+
let b: Box<int> = a.clone();
156+
assert!(a == b);
157+
}
158+
159+
#[test]
160+
fn any_move() {
161+
let a = box 8u as Box<Any>;
162+
let b = box Test as Box<Any>;
163+
164+
match a.move::<uint>() {
165+
Ok(a) => { assert!(a == box 8u); }
166+
Err(..) => fail!()
167+
}
168+
match b.move::<Test>() {
169+
Ok(a) => { assert!(a == box Test); }
170+
Err(..) => fail!()
171+
}
172+
173+
let a = box 8u as Box<Any>;
174+
let b = box Test as Box<Any>;
175+
176+
assert!(a.move::<Box<Test>>().is_err());
177+
assert!(b.move::<Box<uint>>().is_err());
178+
}
179+
180+
#[test]
181+
fn test_show() {
182+
let a = box 8u as Box<Any>;
183+
let b = box Test as Box<Any>;
184+
let a_str = a.to_str();
185+
let b_str = b.to_str();
186+
assert_eq!(a_str.as_slice(), "Box<Any>");
187+
assert_eq!(b_str.as_slice(), "Box<Any>");
188+
189+
let a = &8u as &Any;
190+
let b = &Test as &Any;
191+
let s = format!("{}", a);
192+
assert_eq!(s.as_slice(), "&Any");
193+
let s = format!("{}", b);
194+
assert_eq!(s.as_slice(), "&Any");
195+
}
196+
}

src/libcore/any.rs

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -115,179 +115,3 @@ impl<'a> AnyMutRefExt<'a> for &'a mut Any {
115115
}
116116
}
117117
}
118-
119-
#[cfg(test)]
120-
mod tests {
121-
use prelude::*;
122-
use super::*;
123-
use realstd::owned::{Box, AnyOwnExt};
124-
use realstd::str::Str;
125-
126-
#[deriving(PartialEq, Show)]
127-
struct Test;
128-
129-
static TEST: &'static str = "Test";
130-
131-
#[test]
132-
fn any_referenced() {
133-
let (a, b, c) = (&5u as &Any, &TEST as &Any, &Test as &Any);
134-
135-
assert!(a.is::<uint>());
136-
assert!(!b.is::<uint>());
137-
assert!(!c.is::<uint>());
138-
139-
assert!(!a.is::<&'static str>());
140-
assert!(b.is::<&'static str>());
141-
assert!(!c.is::<&'static str>());
142-
143-
assert!(!a.is::<Test>());
144-
assert!(!b.is::<Test>());
145-
assert!(c.is::<Test>());
146-
}
147-
148-
#[test]
149-
fn any_owning() {
150-
let (a, b, c) = (box 5u as Box<Any>, box TEST as Box<Any>, box Test as Box<Any>);
151-
152-
assert!(a.is::<uint>());
153-
assert!(!b.is::<uint>());
154-
assert!(!c.is::<uint>());
155-
156-
assert!(!a.is::<&'static str>());
157-
assert!(b.is::<&'static str>());
158-
assert!(!c.is::<&'static str>());
159-
160-
assert!(!a.is::<Test>());
161-
assert!(!b.is::<Test>());
162-
assert!(c.is::<Test>());
163-
}
164-
165-
#[test]
166-
fn any_as_ref() {
167-
let a = &5u as &Any;
168-
169-
match a.as_ref::<uint>() {
170-
Some(&5) => {}
171-
x => fail!("Unexpected value {}", x)
172-
}
173-
174-
match a.as_ref::<Test>() {
175-
None => {}
176-
x => fail!("Unexpected value {}", x)
177-
}
178-
}
179-
180-
#[test]
181-
fn any_as_mut() {
182-
let mut a = 5u;
183-
let mut b = box 7u;
184-
185-
let a_r = &mut a as &mut Any;
186-
let tmp: &mut uint = &mut *b;
187-
let b_r = tmp as &mut Any;
188-
189-
match a_r.as_mut::<uint>() {
190-
Some(x) => {
191-
assert_eq!(*x, 5u);
192-
*x = 612;
193-
}
194-
x => fail!("Unexpected value {}", x)
195-
}
196-
197-
match b_r.as_mut::<uint>() {
198-
Some(x) => {
199-
assert_eq!(*x, 7u);
200-
*x = 413;
201-
}
202-
x => fail!("Unexpected value {}", x)
203-
}
204-
205-
match a_r.as_mut::<Test>() {
206-
None => (),
207-
x => fail!("Unexpected value {}", x)
208-
}
209-
210-
match b_r.as_mut::<Test>() {
211-
None => (),
212-
x => fail!("Unexpected value {}", x)
213-
}
214-
215-
match a_r.as_mut::<uint>() {
216-
Some(&612) => {}
217-
x => fail!("Unexpected value {}", x)
218-
}
219-
220-
match b_r.as_mut::<uint>() {
221-
Some(&413) => {}
222-
x => fail!("Unexpected value {}", x)
223-
}
224-
}
225-
226-
#[test]
227-
fn any_move() {
228-
use realstd::any::Any;
229-
use realstd::result::{Ok, Err};
230-
let a = box 8u as Box<Any>;
231-
let b = box Test as Box<Any>;
232-
233-
match a.move::<uint>() {
234-
Ok(a) => { assert!(a == box 8u); }
235-
Err(..) => fail!()
236-
}
237-
match b.move::<Test>() {
238-
Ok(a) => { assert!(a == box Test); }
239-
Err(..) => fail!()
240-
}
241-
242-
let a = box 8u as Box<Any>;
243-
let b = box Test as Box<Any>;
244-
245-
assert!(a.move::<Box<Test>>().is_err());
246-
assert!(b.move::<Box<uint>>().is_err());
247-
}
248-
249-
#[test]
250-
fn test_show() {
251-
use realstd::to_str::ToStr;
252-
let a = box 8u as Box<::realstd::any::Any>;
253-
let b = box Test as Box<::realstd::any::Any>;
254-
let a_str = a.to_str();
255-
let b_str = b.to_str();
256-
assert_eq!(a_str.as_slice(), "Box<Any>");
257-
assert_eq!(b_str.as_slice(), "Box<Any>");
258-
259-
let a = &8u as &Any;
260-
let b = &Test as &Any;
261-
let s = format!("{}", a);
262-
assert_eq!(s.as_slice(), "&Any");
263-
let s = format!("{}", b);
264-
assert_eq!(s.as_slice(), "&Any");
265-
}
266-
267-
#[test]
268-
fn any_fixed_vec() {
269-
let test = [0u, ..8];
270-
let test = &test as &Any;
271-
assert!(test.is::<[uint, ..8]>());
272-
assert!(!test.is::<[uint, ..10]>());
273-
}
274-
}
275-
276-
#[cfg(test)]
277-
mod bench {
278-
extern crate test;
279-
280-
use any::{Any, AnyRefExt};
281-
use option::Some;
282-
use self::test::Bencher;
283-
284-
#[bench]
285-
fn bench_as_ref(b: &mut Bencher) {
286-
b.iter(|| {
287-
let mut x = 0i;
288-
let mut y = &mut x as &mut Any;
289-
test::black_box(&mut y);
290-
test::black_box(y.as_ref::<int>() == Some(&0));
291-
});
292-
}
293-
}

src/libcore/atomics.rs

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -693,97 +693,3 @@ pub fn fence(order: Ordering) {
693693
}
694694
}
695695
}
696-
697-
#[cfg(test)]
698-
mod test {
699-
use super::*;
700-
701-
#[test]
702-
fn bool_() {
703-
let a = AtomicBool::new(false);
704-
assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
705-
assert_eq!(a.compare_and_swap(false, true, SeqCst), true);
706-
707-
a.store(false, SeqCst);
708-
assert_eq!(a.compare_and_swap(false, true, SeqCst), false);
709-
}
710-
711-
#[test]
712-
fn bool_and() {
713-
let a = AtomicBool::new(true);
714-
assert_eq!(a.fetch_and(false, SeqCst),true);
715-
assert_eq!(a.load(SeqCst),false);
716-
}
717-
718-
#[test]
719-
fn uint_and() {
720-
let x = AtomicUint::new(0xf731);
721-
assert_eq!(x.fetch_and(0x137f, SeqCst), 0xf731);
722-
assert_eq!(x.load(SeqCst), 0xf731 & 0x137f);
723-
}
724-
725-
#[test]
726-
fn uint_or() {
727-
let x = AtomicUint::new(0xf731);
728-
assert_eq!(x.fetch_or(0x137f, SeqCst), 0xf731);
729-
assert_eq!(x.load(SeqCst), 0xf731 | 0x137f);
730-
}
731-
732-
#[test]
733-
fn uint_xor() {
734-
let x = AtomicUint::new(0xf731);
735-
assert_eq!(x.fetch_xor(0x137f, SeqCst), 0xf731);
736-
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
737-
}
738-
739-
#[test]
740-
fn int_and() {
741-
let x = AtomicInt::new(0xf731);
742-
assert_eq!(x.fetch_and(0x137f, SeqCst), 0xf731);
743-
assert_eq!(x.load(SeqCst), 0xf731 & 0x137f);
744-
}
745-
746-
#[test]
747-
fn int_or() {
748-
let x = AtomicInt::new(0xf731);
749-
assert_eq!(x.fetch_or(0x137f, SeqCst), 0xf731);
750-
assert_eq!(x.load(SeqCst), 0xf731 | 0x137f);
751-
}
752-
753-
#[test]
754-
fn int_xor() {
755-
let x = AtomicInt::new(0xf731);
756-
assert_eq!(x.fetch_xor(0x137f, SeqCst), 0xf731);
757-
assert_eq!(x.load(SeqCst), 0xf731 ^ 0x137f);
758-
}
759-
760-
static mut S_BOOL : AtomicBool = INIT_ATOMIC_BOOL;
761-
static mut S_INT : AtomicInt = INIT_ATOMIC_INT;
762-
static mut S_UINT : AtomicUint = INIT_ATOMIC_UINT;
763-
764-
#[test]
765-
fn static_init() {
766-
unsafe {
767-
assert!(!S_BOOL.load(SeqCst));
768-
assert!(S_INT.load(SeqCst) == 0);
769-
assert!(S_UINT.load(SeqCst) == 0);
770-
}
771-
}
772-
773-
#[test]
774-
fn different_sizes() {
775-
unsafe {
776-
let mut slot = 0u16;
777-
assert_eq!(super::atomic_swap(&mut slot, 1, SeqCst), 0);
778-
779-
let mut slot = 0u8;
780-
assert_eq!(super::atomic_compare_and_swap(&mut slot, 1, 2, SeqCst), 0);
781-
782-
let slot = 0u32;
783-
assert_eq!(super::atomic_load(&slot, SeqCst), 0);
784-
785-
let mut slot = 0u64;
786-
super::atomic_store(&mut slot, 2, SeqCst);
787-
}
788-
}
789-
}

0 commit comments

Comments
 (0)