From 53b9d1a3248143aafe421566ba31742579da9722 Mon Sep 17 00:00:00 2001 From: Liigo Zhuang Date: Fri, 14 Feb 2014 09:49:11 +0800 Subject: [PATCH] move extra::test to libtest --- mk/crates.mk | 8 ++- src/compiletest/compiletest.rs | 5 +- src/compiletest/runtest.rs | 2 +- src/doc/guide-testing.md | 17 ++--- src/doc/rustdoc.md | 2 +- src/libarena/lib.rs | 6 +- src/libcollections/bitv.rs | 3 +- src/libcollections/deque.rs | 3 +- src/libcollections/dlist.rs | 3 +- src/libcollections/lib.rs | 2 +- src/libcollections/ringbuf.rs | 3 +- src/libcollections/smallintmap.rs | 4 +- src/libcollections/treemap.rs | 4 +- src/libextra/lib.rs | 11 +-- src/libextra/stats.rs | 3 +- src/libnum/bigint.rs | 5 +- src/libnum/rational.rs | 3 +- src/librustc/front/test.rs | 45 ++++++------ src/librustc/util/sha2.rs | 3 +- src/librustdoc/lib.rs | 1 + src/librustdoc/plugins.rs | 4 +- src/librustdoc/test.rs | 14 ++-- src/libserialize/base64.rs | 5 +- src/libserialize/ebml.rs | 3 +- src/libserialize/hex.rs | 3 +- src/libserialize/lib.rs | 2 +- src/libstd/c_str.rs | 3 +- src/libstd/io/buffered.rs | 3 +- src/libstd/io/extensions.rs | 3 +- src/libstd/mem.rs | 4 +- src/libstd/num/f32.rs | 1 - src/libstd/num/f64.rs | 1 - src/libstd/num/mod.rs | 3 +- src/libstd/num/strconv.rs | 3 +- src/libstd/ops.rs | 4 +- src/libstd/path/posix.rs | 3 +- src/libstd/rand/distributions/exponential.rs | 3 +- src/libstd/rand/distributions/gamma.rs | 3 +- src/libstd/rand/distributions/normal.rs | 3 +- src/libstd/rand/mod.rs | 3 +- src/libstd/rt/global_heap.rs | 3 +- src/libstd/rt/local_heap.rs | 3 +- src/libstd/str.rs | 3 +- src/libstd/trie.rs | 3 +- src/libstd/vec.rs | 3 +- src/libsyntax/ast.rs | 5 +- src/libsyntax/lib.rs | 1 - src/libsyntax/parse/mod.rs | 7 +- src/{libextra/test.rs => libtest/lib.rs} | 76 +++++++++++++------- src/libuuid/lib.rs | 5 +- 50 files changed, 176 insertions(+), 137 deletions(-) rename src/{libextra/test.rs => libtest/lib.rs} (96%) diff --git a/mk/crates.mk b/mk/crates.mk index 8af8f966e30..f8bb9fbb408 100644 --- a/mk/crates.mk +++ b/mk/crates.mk @@ -50,7 +50,7 @@ ################################################################################ TARGET_CRATES := std extra green rustuv native flate arena glob term semver \ - uuid serialize sync getopts collections num + uuid serialize sync getopts collections num test HOST_CRATES := syntax rustc rustdoc fourcc CRATES := $(TARGET_CRATES) $(HOST_CRATES) TOOLS := compiletest rustdoc rustc @@ -63,7 +63,8 @@ DEPS_native := std DEPS_syntax := std term serialize collections DEPS_rustc := syntax native:rustllvm flate arena serialize sync getopts \ collections extra -DEPS_rustdoc := rustc native:sundown serialize sync getopts collections +DEPS_rustdoc := rustc native:sundown serialize sync getopts collections \ + test DEPS_flate := std native:miniz DEPS_arena := std collections DEPS_glob := std @@ -76,8 +77,9 @@ DEPS_getopts := std DEPS_collections := std serialize DEPS_fourcc := syntax std DEPS_num := std extra +DEPS_test := std extra collections getopts serialize term -TOOL_DEPS_compiletest := extra green rustuv getopts +TOOL_DEPS_compiletest := test green rustuv getopts TOOL_DEPS_rustdoc := rustdoc green rustuv TOOL_DEPS_rustc := rustc green rustuv TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 15aa68aaebb..c5ec1981306 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -13,16 +13,13 @@ #[allow(non_camel_case_types)]; #[deny(warnings)]; -extern crate extra; +extern crate test; extern crate getopts; use std::os; use std::io; use std::io::fs; - use getopts::{optopt, optflag, reqopt}; -use extra::test; - use common::config; use common::mode_run_pass; use common::mode_run_fail; diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 8b45d987864..83d6bf742c4 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -34,7 +34,7 @@ use std::str; use std::task; use std::vec; -use extra::test::MetricMap; +use test::MetricMap; pub fn run(config: config, testfile: ~str) { diff --git a/src/doc/guide-testing.md b/src/doc/guide-testing.md index e51988565b0..f129f7db729 100644 --- a/src/doc/guide-testing.md +++ b/src/doc/guide-testing.md @@ -170,7 +170,7 @@ runner. The type signature of a benchmark function differs from a unit test: it takes a mutable reference to type -`extra::test::BenchHarness`. Inside the benchmark function, any +`test::BenchHarness`. Inside the benchmark function, any time-variable or "setup" code should execute first, followed by a call to `iter` on the benchmark harness, passing a closure that contains the portion of the benchmark you wish to actually measure the @@ -185,9 +185,10 @@ amount. For example: ~~~ -extern crate extra; +extern crate test; + use std::vec; -use extra::test::BenchHarness; +use test::BenchHarness; #[bench] fn bench_sum_1024_ints(b: &mut BenchHarness) { @@ -243,8 +244,8 @@ recognize that some calculation has no external effects and remove it entirely. ~~~ -extern crate extra; -use extra::test::BenchHarness; +extern crate test; +use test::BenchHarness; #[bench] fn bench_xor_1000_ints(bh: &mut BenchHarness) { @@ -273,15 +274,15 @@ example above by adjusting the `bh.iter` call to bh.iter(|| range(0, 1000).fold(0, |old, new| old ^ new)) ~~~ -Or, the other option is to call the generic `extra::test::black_box` +Or, the other option is to call the generic `test::black_box` function, which is an opaque "black box" to the optimizer and so forces it to consider any argument as used. ~~~ -use extra::test::black_box +extern crate test; bh.iter(|| { - black_box(range(0, 1000).fold(0, |old, new| old ^ new)); + test::black_box(range(0, 1000).fold(0, |old, new| old ^ new)); }); ~~~ diff --git a/src/doc/rustdoc.md b/src/doc/rustdoc.md index 3809dcd3f48..77aa9273734 100644 --- a/src/doc/rustdoc.md +++ b/src/doc/rustdoc.md @@ -154,7 +154,7 @@ testing this code, the `fib` function will be included (so it can compile). Running tests often requires some special configuration to filter tests, find libraries, or try running ignored examples. The testing framework that rustdoc -uses is build on `extra::test`, which is also used when you compile crates with +uses is build on crate `test`, which is also used when you compile crates with rustc's `--test` flag. Extra arguments can be passed to rustdoc's test harness with the `--test-args` flag. diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index d827e45eddb..0f291a56a70 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -503,10 +503,10 @@ impl Drop for TypedArena { } #[cfg(test)] -mod test { - extern crate extra; +mod tests { + extern crate test; + use self::test::BenchHarness; use super::{Arena, TypedArena}; - use self::extra::test::BenchHarness; struct Point { x: int, diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index bee9ec6240b..0e14b28eda3 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -938,7 +938,8 @@ impl<'a> Iterator for BitPositions<'a> { #[cfg(test)] mod tests { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use bitv::{Bitv, SmallBitv, BigBitv, BitvSet, from_bools, from_fn, from_bytes}; diff --git a/src/libcollections/deque.rs b/src/libcollections/deque.rs index 14c6bc5ce28..ac3861f4e36 100644 --- a/src/libcollections/deque.rs +++ b/src/libcollections/deque.rs @@ -41,10 +41,11 @@ pub trait Deque : Mutable { #[cfg(test)] pub mod bench { + extern crate test; + use self::test::BenchHarness; use std::container::MutableMap; use std::{vec, rand}; use std::rand::Rng; - use extra::test::BenchHarness; pub fn insert_rand_n>(n: uint, map: &mut M, diff --git a/src/libcollections/dlist.rs b/src/libcollections/dlist.rs index 28e7b9460dc..591561d775e 100644 --- a/src/libcollections/dlist.rs +++ b/src/libcollections/dlist.rs @@ -657,8 +657,9 @@ impl> Decodable for DList { #[cfg(test)] mod tests { + extern crate test; + use self::test::BenchHarness; use deque::Deque; - use extra::test; use std::rand; use super::{DList, Node, ListInsertion}; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index e97eeac4f66..5b9ded3d1c7 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -20,7 +20,7 @@ #[feature(macro_rules, managed_boxes)]; extern crate serialize; -#[cfg(test)] extern crate extra; // benchmark tests need this +#[cfg(test)] extern crate test; pub use bitv::Bitv; pub use btree::BTree; diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 325f55b4634..8abc5a3ca11 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -431,8 +431,9 @@ impl> Decodable for RingBuf { #[cfg(test)] mod tests { + extern crate test; + use self::test::BenchHarness; use deque::Deque; - use extra::test; use std::clone::Clone; use std::cmp::Eq; use super::RingBuf; diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index 714bce9d032..d7b0e66aad7 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -470,9 +470,9 @@ mod test_map { #[cfg(test)] mod bench { - + extern crate test; + use self::test::BenchHarness; use super::SmallIntMap; - use extra::test::BenchHarness; use deque::bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n}; // Find seq diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index b4ecd02a8fb..a4b23579606 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -1494,9 +1494,9 @@ mod test_treemap { #[cfg(test)] mod bench { - + extern crate test; + use self::test::BenchHarness; use super::TreeMap; - use extra::test::BenchHarness; use deque::bench::{insert_rand_n, insert_seq_n, find_rand_n, find_seq_n}; // Find seq diff --git a/src/libextra/lib.rs b/src/libextra/lib.rs index be7aa216e30..dc5624f9de9 100644 --- a/src/libextra/lib.rs +++ b/src/libextra/lib.rs @@ -36,15 +36,10 @@ Rust extras are part of the standard Rust distribution. extern crate sync; extern crate serialize; - extern crate collections; // Utility modules - pub mod c_vec; - -// And ... other stuff - pub mod url; pub mod json; pub mod tempfile; @@ -56,15 +51,11 @@ pub mod stats; #[cfg(unicode)] mod unicode; -// Compiler support modules - -pub mod test; - // A curious inner-module that's not exported that contains the binding // 'extra' so that macro-expanded references to extra::serialize and such // can be resolved within libextra. #[doc(hidden)] pub mod extra { pub use serialize; - pub use test; } + diff --git a/src/libextra/stats.rs b/src/libextra/stats.rs index 799157f9a1a..1687f5550b4 100644 --- a/src/libextra/stats.rs +++ b/src/libextra/stats.rs @@ -1025,7 +1025,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use std::vec; use stats::Stats; diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 7197b0dba1d..6b833804e9b 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -2546,11 +2546,12 @@ mod bigint_tests { #[cfg(test)] mod bench { - use super::{BigInt, BigUint}; + extern crate test; + use self::test::BenchHarness; + use super::BigUint; use std::iter; use std::mem::replace; use std::num::{FromPrimitive, Zero, One}; - use extra::test::BenchHarness; fn factorial(n: uint) -> BigUint { let mut f: BigUint = One::one(); diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index a41996d044f..a483946322f 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -430,8 +430,7 @@ mod test { mod arith { use super::{_0, _1, _2, _1_2, _3_2, _neg1_2, to_big}; - use super::super::{Ratio, Rational, BigRational}; - + use super::super::{Ratio, Rational}; #[test] fn test_add() { diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index be9fcf4a1e9..45b1a42898c 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -46,7 +46,7 @@ struct TestCtxt<'a> { path: RefCell<~[ast::Ident]>, ext_cx: ExtCtxt<'a>, testfns: RefCell<~[Test]>, - is_extra: bool, + is_test_crate: bool, config: ast::CrateConfig, } @@ -164,7 +164,7 @@ fn generate_test_harness(sess: session::Session, krate: ast::Crate) ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone(), loader), path: RefCell::new(~[]), testfns: RefCell::new(~[]), - is_extra: is_extra(&krate), + is_test_crate: is_test_crate(&krate), config: krate.config.clone(), }; @@ -275,13 +275,12 @@ We're going to be building a module that looks more or less like: mod __test { #[!resolve_unexported] - extern crate extra (name = "extra", vers = "..."); + extern crate test (name = "test", vers = "..."); fn main() { - #[main]; - extra::test::test_main_static(::os::args(), tests) + test::test_main_static(::os::args(), tests) } - static tests : &'static [extra::test::TestDescAndFn] = &[ + static tests : &'static [test::TestDescAndFn] = &[ ... the list of tests in the crate ... ]; } @@ -289,15 +288,15 @@ mod __test { */ fn mk_std(cx: &TestCtxt) -> ast::ViewItem { - let id_extra = token::str_to_ident("extra"); - let vi = if cx.is_extra { + let id_test = token::str_to_ident("test"); + let vi = if cx.is_test_crate { ast::ViewItemUse( - ~[@nospan(ast::ViewPathSimple(id_extra, - path_node(~[id_extra]), + ~[@nospan(ast::ViewPathSimple(id_test, + path_node(~[id_test]), ast::DUMMY_NODE_ID))]) } else { - ast::ViewItemExternMod(id_extra, - with_version("extra"), + ast::ViewItemExternMod(id_test, + with_version("test"), ast::DUMMY_NODE_ID) }; ast::ViewItem { @@ -310,7 +309,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem { fn mk_test_module(cx: &TestCtxt) -> @ast::Item { - // Link to extra + // Link to test crate let view_items = ~[mk_std(cx)]; // A constant vector of test descriptors. @@ -321,7 +320,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::Item { let mainfn = (quote_item!(&cx.ext_cx, pub fn main() { #[main]; - extra::test::test_main_static(::std::os::args(), TESTS); + test::test_main_static(::std::os::args(), TESTS); } )).unwrap(); @@ -383,15 +382,15 @@ fn mk_tests(cx: &TestCtxt) -> @ast::Item { let test_descs = mk_test_descs(cx); (quote_item!(&cx.ext_cx, - pub static TESTS : &'static [self::extra::test::TestDescAndFn] = + pub static TESTS : &'static [self::test::TestDescAndFn] = $test_descs ; )).unwrap() } -fn is_extra(krate: &ast::Crate) -> bool { +fn is_test_crate(krate: &ast::Crate) -> bool { match attr::find_crateid(krate.attrs) { - Some(ref s) if "extra" == s.name => true, + Some(ref s) if "test" == s.name => true, _ => false } } @@ -444,9 +443,9 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr { }; let t_expr = if test.bench { - quote_expr!(&cx.ext_cx, self::extra::test::StaticBenchFn($fn_expr) ) + quote_expr!(&cx.ext_cx, self::test::StaticBenchFn($fn_expr) ) } else { - quote_expr!(&cx.ext_cx, self::extra::test::StaticTestFn($fn_expr) ) + quote_expr!(&cx.ext_cx, self::test::StaticTestFn($fn_expr) ) }; let ignore_expr = if test.ignore { @@ -462,9 +461,9 @@ fn mk_test_desc_and_fn_rec(cx: &TestCtxt, test: &Test) -> @ast::Expr { }; let e = quote_expr!(&cx.ext_cx, - self::extra::test::TestDescAndFn { - desc: self::extra::test::TestDesc { - name: self::extra::test::StaticTestName($name_expr), + self::test::TestDescAndFn { + desc: self::test::TestDesc { + name: self::test::StaticTestName($name_expr), ignore: $ignore_expr, should_fail: $fail_expr }, diff --git a/src/librustc/util/sha2.rs b/src/librustc/util/sha2.rs index 940cebf7847..bd17f6b5814 100644 --- a/src/librustc/util/sha2.rs +++ b/src/librustc/util/sha2.rs @@ -635,7 +635,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use super::{Sha256, FixedBuffer, Digest}; #[bench] diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4194f5e4729..de992e68fe0 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -23,6 +23,7 @@ extern crate serialize; extern crate sync; extern crate getopts; extern crate collections; +extern crate testing = "test"; use std::local_data; use std::io; diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 2fcf5527a34..104cec9c814 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -10,10 +10,10 @@ use clean; -use extra; +use extra::json; use dl = std::unstable::dynamic_lib; -pub type PluginJson = Option<(~str, extra::json::Json)>; +pub type PluginJson = Option<(~str, json::Json)>; pub type PluginResult = (clean::Crate, PluginJson); pub type plugin_callback = extern fn (clean::Crate) -> PluginResult; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index db4842b79a0..c0f8d2696ca 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -15,8 +15,8 @@ use std::os; use std::run; use std::str; +use testing; use extra::tempfile::TempDir; -use extra::test; use rustc::back::link; use rustc::driver::driver; use rustc::driver::session; @@ -89,7 +89,7 @@ pub fn run(input: &str, matches: &getopts::Matches) -> int { let mut args = args.to_owned_vec(); args.unshift(~"rustdoctest"); - test::test_main(args, collector.tests); + testing::test_main(args, collector.tests); 0 } @@ -164,7 +164,7 @@ fn maketest(s: &str, cratename: &str) -> ~str { } pub struct Collector { - priv tests: ~[test::TestDescAndFn], + priv tests: ~[testing::TestDescAndFn], priv names: ~[~str], priv libs: @RefCell>, priv cnt: uint, @@ -180,13 +180,13 @@ impl Collector { let libs = (*libs.get()).clone(); let cratename = self.cratename.to_owned(); debug!("Creating test {}: {}", name, test); - self.tests.push(test::TestDescAndFn { - desc: test::TestDesc { - name: test::DynTestName(name), + self.tests.push(testing::TestDescAndFn { + desc: testing::TestDesc { + name: testing::DynTestName(name), ignore: false, should_fail: false, // compiler failures are test failures }, - testfn: test::DynTestFn(proc() { + testfn: testing::DynTestFn(proc() { runtest(test, cratename, libs, should_fail); }), }); diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 918c5e85857..839450ce57c 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -260,8 +260,9 @@ impl<'a> FromBase64 for &'a str { } #[cfg(test)] -mod test { - use extra::test::BenchHarness; +mod tests { + extern crate test; + use self::test::BenchHarness; use base64::{Config, FromBase64, ToBase64, STANDARD, URL_SAFE}; #[test] diff --git a/src/libserialize/ebml.rs b/src/libserialize/ebml.rs index 3d57a32a830..6dc23f586db 100644 --- a/src/libserialize/ebml.rs +++ b/src/libserialize/ebml.rs @@ -1037,8 +1037,9 @@ mod tests { #[cfg(test)] mod bench { + extern crate test; + use self::test::BenchHarness; use ebml::reader; - use extra::test::BenchHarness; #[bench] pub fn vuint_at_A_aligned(bh: &mut BenchHarness) { diff --git a/src/libserialize/hex.rs b/src/libserialize/hex.rs index 08a3dda854e..223a586a5a0 100644 --- a/src/libserialize/hex.rs +++ b/src/libserialize/hex.rs @@ -139,7 +139,8 @@ impl<'a> FromHex for &'a str { #[cfg(test)] mod tests { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use hex::{FromHex, ToHex}; #[test] diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 7a4b1cff6e4..f89f56c0f34 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -24,7 +24,7 @@ Core encoding and decoding interfaces. // test harness access #[cfg(test)] -extern crate extra; +extern crate test; pub use self::serialize::{Decoder, Encoder, Decodable, Encodable, DecoderHelpers, EncoderHelpers}; diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index adbd4be316c..e6b0958617e 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -664,7 +664,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use libc; use prelude::*; diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index fbed53ee30d..227f3a0a083 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -346,11 +346,12 @@ impl Writer for BufferedStream { #[cfg(test)] mod test { + extern crate test; use io; use prelude::*; use super::*; use super::super::mem::{MemReader, MemWriter, BufReader}; - use Harness = extra::test::BenchHarness; + use Harness = self::test::BenchHarness; /// A type, free to create, primarily intended for benchmarking creation of /// wrappers that, just for construction, don't need a Reader/Writer that diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index da4697d0e48..ee366e96f23 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -456,7 +456,8 @@ mod test { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use container::Container; macro_rules! u64_from_be_bytes_bench_impl( diff --git a/src/libstd/mem.rs b/src/libstd/mem.rs index c322e9bf572..11053f01ded 100644 --- a/src/libstd/mem.rs +++ b/src/libstd/mem.rs @@ -267,8 +267,8 @@ mod tests { /// Completely miscellaneous language-construct benchmarks. #[cfg(test)] mod bench { - - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use option::{Some,None}; // Static/dynamic method dispatch diff --git a/src/libstd/num/f32.rs b/src/libstd/num/f32.rs index 688e8347d9a..da3f2c1636f 100644 --- a/src/libstd/num/f32.rs +++ b/src/libstd/num/f32.rs @@ -865,7 +865,6 @@ impl num::FromStrRadix for f32 { #[cfg(test)] mod tests { use f32::*; - use num::*; use num; diff --git a/src/libstd/num/f64.rs b/src/libstd/num/f64.rs index dafb3187ff8..24165cbef50 100644 --- a/src/libstd/num/f64.rs +++ b/src/libstd/num/f64.rs @@ -867,7 +867,6 @@ impl num::FromStrRadix for f64 { #[cfg(test)] mod tests { use f64::*; - use num::*; use num; diff --git a/src/libstd/num/mod.rs b/src/libstd/num/mod.rs index 026e7ebbd48..8a417096c3e 100644 --- a/src/libstd/num/mod.rs +++ b/src/libstd/num/mod.rs @@ -1734,10 +1734,11 @@ mod tests { #[cfg(test)] mod bench { + extern crate test; + use self::test::BenchHarness; use num; use vec; use prelude::*; - use extra::test::BenchHarness; #[bench] fn bench_pow_function(b: &mut BenchHarness) { diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 1ecabff8758..6be829f51d7 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -803,7 +803,8 @@ mod test { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use rand::{XorShiftRng, Rng}; use to_str::ToStr; use f64; diff --git a/src/libstd/ops.rs b/src/libstd/ops.rs index a15ce4f0102..ac329e6fe83 100644 --- a/src/libstd/ops.rs +++ b/src/libstd/ops.rs @@ -466,8 +466,8 @@ pub trait Index { #[cfg(test)] mod bench { - - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use ops::Drop; // Overhead of dtors diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index f8e9d0ae344..9aaa86c4cfe 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -1250,7 +1250,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use super::*; use prelude::*; diff --git a/src/libstd/rand/distributions/exponential.rs b/src/libstd/rand/distributions/exponential.rs index 09c36d945eb..2fa9cf8bd48 100644 --- a/src/libstd/rand/distributions/exponential.rs +++ b/src/libstd/rand/distributions/exponential.rs @@ -119,7 +119,8 @@ mod test { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use mem::size_of; use prelude::*; use rand::{XorShiftRng, RAND_BENCH_N}; diff --git a/src/libstd/rand/distributions/gamma.rs b/src/libstd/rand/distributions/gamma.rs index a14b58188bd..b9702ccd48d 100644 --- a/src/libstd/rand/distributions/gamma.rs +++ b/src/libstd/rand/distributions/gamma.rs @@ -371,7 +371,8 @@ mod test { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use mem::size_of; use prelude::*; use rand::distributions::IndependentSample; diff --git a/src/libstd/rand/distributions/normal.rs b/src/libstd/rand/distributions/normal.rs index c9dc3c8abc1..b2f952e2a4c 100644 --- a/src/libstd/rand/distributions/normal.rs +++ b/src/libstd/rand/distributions/normal.rs @@ -187,7 +187,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use mem::size_of; use prelude::*; use rand::{XorShiftRng, RAND_BENCH_N}; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 44962684300..7218f83d662 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -845,8 +845,9 @@ static RAND_BENCH_N: u64 = 100; #[cfg(test)] mod bench { + extern crate test; + use self::test::BenchHarness; use prelude::*; - use extra::test::BenchHarness; use rand::{XorShiftRng, StdRng, IsaacRng, Isaac64Rng, Rng, RAND_BENCH_N}; use mem::size_of; diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index ab279fd3102..8128bb02148 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -107,7 +107,8 @@ pub unsafe fn exchange_free(ptr: *u8) { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; #[bench] fn alloc_owned_small(bh: &mut BenchHarness) { diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index f3474b9401e..8a42cd73565 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -308,7 +308,8 @@ pub fn live_allocs() -> *mut Box { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; #[bench] fn alloc_managed_small(bh: &mut BenchHarness) { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 2ac3a981787..c3f79ff7139 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -4498,7 +4498,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use super::*; use prelude::*; diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index f57c5bc649a..d17d59f8665 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -902,10 +902,11 @@ mod test_map { #[cfg(test)] mod bench_map { + extern crate test; + use self::test::BenchHarness; use super::*; use prelude::*; use rand::{weak_rng, Rng}; - use extra::test::BenchHarness; #[bench] fn bench_iter_small(bh: &mut BenchHarness) { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 9d9ebad1c69..d16ad54a25d 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -4360,7 +4360,8 @@ mod tests { #[cfg(test)] mod bench { - use extra::test::BenchHarness; + extern crate test; + use self::test::BenchHarness; use mem; use prelude::*; use ptr; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a3025d394da..e8edc1a0dfc 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1196,8 +1196,9 @@ pub enum InlinedItem { #[cfg(test)] mod test { + extern crate extra; + use self::extra::json; use serialize; - use extra; use codemap::*; use super::*; @@ -1223,6 +1224,6 @@ mod test { }, }; // doesn't matter which encoder we use.... - let _f = (&e as &serialize::Encodable); + let _f = (&e as &serialize::Encodable); } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 3cbdad9a71d..42c9ab461aa 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -32,7 +32,6 @@ This API is completely unstable and subject to change. #[deny(non_camel_case_types)]; -#[cfg(test)] extern crate extra; extern crate serialize; extern crate term; extern crate collections; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index b4139714a2e..08aec075770 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -283,9 +283,10 @@ pub fn maybe_aborted(result: T, mut p: Parser) -> T { #[cfg(test)] mod test { + extern crate extra; + use self::extra::json; use super::*; use serialize::Encodable; - use extra; use std::io; use std::io::MemWriter; use std::str; @@ -300,9 +301,9 @@ mod test { use util::parser_testing::string_to_stmt; #[cfg(test)] - fn to_json_str<'a, E: Encodable>>(val: &E) -> ~str { + fn to_json_str<'a, E: Encodable>>(val: &E) -> ~str { let mut writer = MemWriter::new(); - let mut encoder = extra::json::Encoder::new(&mut writer as &mut io::Writer); + let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer); val.encode(&mut encoder); str::from_utf8_owned(writer.unwrap()).unwrap() } diff --git a/src/libextra/test.rs b/src/libtest/lib.rs similarity index 96% rename from src/libextra/test.rs rename to src/libtest/lib.rs index 4b883d14986..226dd75d740 100644 --- a/src/libextra/test.rs +++ b/src/libtest/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,23 +8,35 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[doc(hidden)]; - // Support code for rustc's built in test runner generator. Currently, // none of this is meant for users. It is intended to support the // simplest interface possible for representing and running tests // while providing a base that other test frameworks may build off of. +#[crate_id = "test#0.10-pre"]; +#[comment = "Rust internal test library only used by rustc"]; +#[license = "MIT/ASL2"]; +#[crate_type = "rlib"]; +#[crate_type = "dylib"]; + +#[feature(asm)]; + +extern crate collections; +extern crate extra; extern crate getopts; +extern crate serialize; extern crate term; -use json::ToJson; -use json; -use serialize::Decodable; -use stats::Stats; -use stats; -use time::precise_time_ns; use collections::TreeMap; +use extra::json::ToJson; +use extra::json; +use extra::stats::Stats; +use extra::stats; +use extra::time::precise_time_ns; +use getopts::{OptGroup, optflag, optopt}; +use serialize::Decodable; +use term::Terminal; +use term::color::{Color, RED, YELLOW, GREEN, CYAN}; use std::cmp; use std::io; @@ -36,6 +48,17 @@ use std::to_str::ToStr; use std::f64; use std::os; +// to be used by rustc to compile tests in libtest +pub mod test { + pub use {BenchHarness, TestName, TestResult, TestDesc, + TestDescAndFn, TestOpts, TrFailed, TrIgnored, TrOk, + Metric, MetricMap, MetricAdded, MetricRemoved, + MetricChange, Improvement, Regression, LikelyNoise, + StaticTestFn, StaticTestName, DynTestName, DynTestFn, + run_test, test_main, test_main_static, filter_tests, + parse_opts}; +} + // The name of a test. By convention this follows the rules for rust // paths; i.e. it should be a series of identifiers separated by double // colons. This way if some test runner wants to arrange the tests @@ -131,6 +154,12 @@ pub struct Metric { priv noise: f64 } +impl Metric { + pub fn new(value: f64, noise: f64) -> Metric { + Metric {value: value, noise: noise} + } +} + #[deriving(Eq)] pub struct MetricMap(TreeMap<~str,Metric>); @@ -245,7 +274,7 @@ Test Attributes: #[test] - Indicates a function is a test to be run. This function takes no arguments. #[bench] - Indicates a function is a benchmark to be run. This - function takes one argument (extra::test::BenchHarness). + function takes one argument (test::BenchHarness). #[should_fail] - This function (also labeled with #[test]) will only pass if the code causes a failure (an assertion failure or fail!) #[ignore] - When applied to a function which is already attributed as a @@ -783,7 +812,7 @@ fn run_tests(opts: &TestOpts, remaining.reverse(); let mut pending = 0; - let (p, ch) = Chan::new(); + let (p, ch) = Chan::::new(); while pending > 0 || !remaining.is_empty() { while pending < concurrency && !remaining.is_empty() { @@ -929,12 +958,12 @@ pub fn run_test(force_ignore: bool, match testfn { DynBenchFn(bencher) => { - let bs = ::test::bench::benchmark(|harness| bencher.run(harness)); + let bs = ::bench::benchmark(|harness| bencher.run(harness)); monitor_ch.send((desc, TrBench(bs), ~[])); return; } StaticBenchFn(benchfn) => { - let bs = ::test::bench::benchmark(|harness| benchfn(harness)); + let bs = ::bench::benchmark(|harness| benchfn(harness)); monitor_ch.send((desc, TrBench(bs), ~[])); return; } @@ -1230,15 +1259,11 @@ impl BenchHarness { n *= 2; } } - - - - } pub mod bench { use std::cmp; - use test::{BenchHarness, BenchSamples}; + use super::{BenchHarness, BenchSamples}; pub fn benchmark(f: |&mut BenchHarness|) -> BenchSamples { let mut bs = BenchHarness { @@ -1264,13 +1289,11 @@ pub mod bench { #[cfg(test)] mod tests { use test::{TrFailed, TrIgnored, TrOk, filter_tests, parse_opts, - TestDesc, TestDescAndFn, + TestDesc, TestDescAndFn, TestOpts, run_test, Metric, MetricMap, MetricAdded, MetricRemoved, Improvement, Regression, LikelyNoise, StaticTestName, DynTestName, DynTestFn}; - use test::{TestOpts, run_test}; - - use tempfile::TempDir; + use extra::tempfile::TempDir; #[test] pub fn do_not_run_ignored_tests() { @@ -1532,8 +1555,8 @@ mod tests { let m3 = MetricMap::load(&pth); let MetricMap(m3) = m3; assert_eq!(m3.len(), 2); - assert_eq!(*(m3.find(&~"runtime").unwrap()), Metric { value: 1000.0, noise: 2.0 }); - assert_eq!(*(m3.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 }); + assert_eq!(*(m3.find(&~"runtime").unwrap()), Metric::new(1000.0, 2.0)); + assert_eq!(*(m3.find(&~"throughput").unwrap()), Metric::new(50.0, 2.0)); // Ask for a ratchet with an explicit noise-percentage override, // that should advance. @@ -1547,7 +1570,8 @@ mod tests { let m4 = MetricMap::load(&pth); let MetricMap(m4) = m4; assert_eq!(m4.len(), 2); - assert_eq!(*(m4.find(&~"runtime").unwrap()), Metric { value: 1100.0, noise: 2.0 }); - assert_eq!(*(m4.find(&~"throughput").unwrap()), Metric { value: 50.0, noise: 2.0 }); + assert_eq!(*(m4.find(&~"runtime").unwrap()), Metric::new(1100.0, 2.0)); + assert_eq!(*(m4.find(&~"throughput").unwrap()), Metric::new(50.0, 2.0)); } } + diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 180838d4132..5941afb7d75 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -61,7 +61,7 @@ Examples of string representations: // test harness access #[cfg(test)] -extern crate extra; +extern crate test; extern crate serialize; use std::str; @@ -812,8 +812,9 @@ mod test { #[cfg(test)] mod bench { + extern crate test; + use self::test::BenchHarness; use super::Uuid; - use extra::test::BenchHarness; #[bench] pub fn create_uuids(bh: &mut BenchHarness) {