move extra::test to libtest
This commit is contained in:
parent
0cc8ba0c20
commit
53b9d1a324
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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));
|
||||
});
|
||||
~~~
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -503,10 +503,10 @@ impl<T> Drop for TypedArena<T> {
|
||||
}
|
||||
|
||||
#[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,
|
||||
|
@ -938,7 +938,8 @@ impl<'a> Iterator<uint> 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};
|
||||
|
@ -41,10 +41,11 @@ pub trait Deque<T> : 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<M:MutableMap<uint,uint>>(n: uint,
|
||||
map: &mut M,
|
||||
|
@ -657,8 +657,9 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for DList<T> {
|
||||
|
||||
#[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};
|
||||
|
||||
|
@ -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;
|
||||
|
@ -431,8 +431,9 @@ impl<D:Decoder,T:Decodable<D>> Decodable<D> for RingBuf<T> {
|
||||
|
||||
#[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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
@ -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
|
||||
},
|
||||
|
@ -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]
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<HashSet<Path>>,
|
||||
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);
|
||||
}),
|
||||
});
|
||||
|
@ -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]
|
||||
|
@ -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) {
|
||||
|
@ -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]
|
||||
|
@ -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};
|
||||
|
@ -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::*;
|
||||
|
||||
|
@ -346,11 +346,12 @@ impl<S: Stream> Writer for BufferedStream<S> {
|
||||
|
||||
#[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
|
||||
|
@ -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(
|
||||
|
@ -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
|
||||
|
@ -865,7 +865,6 @@ impl num::FromStrRadix for f32 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use f32::*;
|
||||
|
||||
use num::*;
|
||||
use num;
|
||||
|
||||
|
@ -867,7 +867,6 @@ impl num::FromStrRadix for f64 {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use f64::*;
|
||||
|
||||
use num::*;
|
||||
use num;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -466,8 +466,8 @@ pub trait Index<Index,Result> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod bench {
|
||||
|
||||
use extra::test::BenchHarness;
|
||||
extern crate test;
|
||||
use self::test::BenchHarness;
|
||||
use ops::Drop;
|
||||
|
||||
// Overhead of dtors
|
||||
|
@ -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::*;
|
||||
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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::*;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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<extra::json::Encoder>);
|
||||
let _f = (&e as &serialize::Encodable<json::Encoder>);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -283,9 +283,10 @@ pub fn maybe_aborted<T>(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<extra::json::Encoder<'a>>>(val: &E) -> ~str {
|
||||
fn to_json_str<'a, E: Encodable<json::Encoder<'a>>>(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()
|
||||
}
|
||||
|
@ -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::<MonitorMsg>::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));
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user