Auto merge of #21503 - ahmedcharles:remove-test-features, r=alexcrichton
I think this is all of the remaining code to be removed. Let me know if I've missed anything. Closes #19145
This commit is contained in:
commit
4be79d6acd
2 changed files with 18 additions and 222 deletions
|
@ -54,7 +54,7 @@ use self::OutputLocation::*;
|
||||||
use stats::Stats;
|
use stats::Stats;
|
||||||
use getopts::{OptGroup, optflag, optopt};
|
use getopts::{OptGroup, optflag, optopt};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serialize::{json, Decodable, Encodable};
|
use serialize::Encodable;
|
||||||
use term::Terminal;
|
use term::Terminal;
|
||||||
use term::color::{Color, RED, YELLOW, GREEN, CYAN};
|
use term::color::{Color, RED, YELLOW, GREEN, CYAN};
|
||||||
|
|
||||||
|
@ -62,7 +62,6 @@ use std::any::Any;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::fs::PathExtensions;
|
|
||||||
use std::io::stdio::StdWriter;
|
use std::io::stdio::StdWriter;
|
||||||
use std::io::{File, ChanReader, ChanWriter};
|
use std::io::{File, ChanReader, ChanWriter};
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -438,9 +437,6 @@ struct ConsoleTestState<T> {
|
||||||
log_out: Option<File>,
|
log_out: Option<File>,
|
||||||
out: OutputLocation<T>,
|
out: OutputLocation<T>,
|
||||||
use_color: bool,
|
use_color: bool,
|
||||||
show_boxplot: bool,
|
|
||||||
boxplot_width: uint,
|
|
||||||
show_all_stats: bool,
|
|
||||||
total: uint,
|
total: uint,
|
||||||
passed: uint,
|
passed: uint,
|
||||||
failed: uint,
|
failed: uint,
|
||||||
|
@ -467,9 +463,6 @@ impl<T: Writer> ConsoleTestState<T> {
|
||||||
out: out,
|
out: out,
|
||||||
log_out: log_out,
|
log_out: log_out,
|
||||||
use_color: use_color(opts),
|
use_color: use_color(opts),
|
||||||
show_boxplot: false,
|
|
||||||
boxplot_width: 50,
|
|
||||||
show_all_stats: false,
|
|
||||||
total: 0u,
|
total: 0u,
|
||||||
passed: 0u,
|
passed: 0u,
|
||||||
failed: 0u,
|
failed: 0u,
|
||||||
|
@ -545,33 +538,13 @@ impl<T: Writer> ConsoleTestState<T> {
|
||||||
TrIgnored => self.write_ignored(),
|
TrIgnored => self.write_ignored(),
|
||||||
TrMetrics(ref mm) => {
|
TrMetrics(ref mm) => {
|
||||||
try!(self.write_metric());
|
try!(self.write_metric());
|
||||||
self.write_plain(format!(": {}", fmt_metrics(mm)).as_slice())
|
self.write_plain(format!(": {}", mm.fmt_metrics()).as_slice())
|
||||||
}
|
}
|
||||||
TrBench(ref bs) => {
|
TrBench(ref bs) => {
|
||||||
try!(self.write_bench());
|
try!(self.write_bench());
|
||||||
|
|
||||||
if self.show_boxplot {
|
try!(self.write_plain(format!(": {}",
|
||||||
let mut wr = Vec::new();
|
fmt_bench_samples(bs)).as_slice()));
|
||||||
|
|
||||||
try!(stats::write_boxplot(&mut wr, &bs.ns_iter_summ, self.boxplot_width));
|
|
||||||
|
|
||||||
let s = String::from_utf8(wr).unwrap();
|
|
||||||
|
|
||||||
try!(self.write_plain(format!(": {}", s).as_slice()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.show_all_stats {
|
|
||||||
let mut wr = Vec::new();
|
|
||||||
|
|
||||||
try!(stats::write_5_number_summary(&mut wr, &bs.ns_iter_summ));
|
|
||||||
|
|
||||||
let s = String::from_utf8(wr).unwrap();
|
|
||||||
|
|
||||||
try!(self.write_plain(format!(": {}", s).as_slice()));
|
|
||||||
} else {
|
|
||||||
try!(self.write_plain(format!(": {}",
|
|
||||||
fmt_bench_samples(bs)).as_slice()));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -588,7 +561,7 @@ impl<T: Writer> ConsoleTestState<T> {
|
||||||
TrOk => "ok".to_string(),
|
TrOk => "ok".to_string(),
|
||||||
TrFailed => "failed".to_string(),
|
TrFailed => "failed".to_string(),
|
||||||
TrIgnored => "ignored".to_string(),
|
TrIgnored => "ignored".to_string(),
|
||||||
TrMetrics(ref mm) => fmt_metrics(mm),
|
TrMetrics(ref mm) => mm.fmt_metrics(),
|
||||||
TrBench(ref bs) => fmt_bench_samples(bs)
|
TrBench(ref bs) => fmt_bench_samples(bs)
|
||||||
}, test.name.as_slice());
|
}, test.name.as_slice());
|
||||||
o.write(s.as_bytes())
|
o.write(s.as_bytes())
|
||||||
|
@ -624,34 +597,14 @@ impl<T: Writer> ConsoleTestState<T> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_run_finish(&mut self,
|
pub fn write_run_finish(&mut self) -> io::IoResult<bool> {
|
||||||
ratchet_metrics: &Option<Path>,
|
|
||||||
ratchet_pct: Option<f64>) -> io::IoResult<bool> {
|
|
||||||
assert!(self.passed + self.failed + self.ignored + self.measured == self.total);
|
assert!(self.passed + self.failed + self.ignored + self.measured == self.total);
|
||||||
|
|
||||||
let ratchet_success = match *ratchet_metrics {
|
let success = self.failed == 0u;
|
||||||
None => true,
|
if !success {
|
||||||
Some(ref pth) => {
|
|
||||||
try!(self.write_plain(format!("\nusing metrics ratchet: {:?}\n",
|
|
||||||
pth.display()).as_slice()));
|
|
||||||
match ratchet_pct {
|
|
||||||
None => (),
|
|
||||||
Some(pct) =>
|
|
||||||
try!(self.write_plain(format!("with noise-tolerance \
|
|
||||||
forced to: {}%\n",
|
|
||||||
pct).as_slice()))
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let test_success = self.failed == 0u;
|
|
||||||
if !test_success {
|
|
||||||
try!(self.write_failures());
|
try!(self.write_failures());
|
||||||
}
|
}
|
||||||
|
|
||||||
let success = ratchet_success && test_success;
|
|
||||||
|
|
||||||
try!(self.write_plain("\ntest result: "));
|
try!(self.write_plain("\ntest result: "));
|
||||||
if success {
|
if success {
|
||||||
// There's no parallelism at this point so it's safe to use color
|
// There's no parallelism at this point so it's safe to use color
|
||||||
|
@ -666,15 +619,6 @@ impl<T: Writer> ConsoleTestState<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fmt_metrics(mm: &MetricMap) -> String {
|
|
||||||
let MetricMap(ref mm) = *mm;
|
|
||||||
let v : Vec<String> = mm.iter()
|
|
||||||
.map(|(k,v)| format!("{}: {} (+/- {})", *k,
|
|
||||||
v.value as f64, v.noise as f64))
|
|
||||||
.collect();
|
|
||||||
v.connect(", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fmt_bench_samples(bs: &BenchSamples) -> String {
|
pub fn fmt_bench_samples(bs: &BenchSamples) -> String {
|
||||||
if bs.mb_s != 0 {
|
if bs.mb_s != 0 {
|
||||||
format!("{:>9} ns/iter (+/- {}) = {} MB/s",
|
format!("{:>9} ns/iter (+/- {}) = {} MB/s",
|
||||||
|
@ -745,7 +689,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn> ) -> io::IoR
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
try!(run_tests(opts, tests, |x| callback(&x, &mut st)));
|
try!(run_tests(opts, tests, |x| callback(&x, &mut st)));
|
||||||
return st.write_run_finish(&None, None);
|
return st.write_run_finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -766,9 +710,6 @@ fn should_sort_failures_before_printing_them() {
|
||||||
log_out: None,
|
log_out: None,
|
||||||
out: Raw(Vec::new()),
|
out: Raw(Vec::new()),
|
||||||
use_color: false,
|
use_color: false,
|
||||||
show_boxplot: false,
|
|
||||||
boxplot_width: 0,
|
|
||||||
show_all_stats: false,
|
|
||||||
total: 0u,
|
total: 0u,
|
||||||
passed: 0u,
|
passed: 0u,
|
||||||
failed: 0u,
|
failed: 0u,
|
||||||
|
@ -1010,30 +951,6 @@ impl MetricMap {
|
||||||
MetricMap(BTreeMap::new())
|
MetricMap(BTreeMap::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load MetricDiff from a file.
|
|
||||||
///
|
|
||||||
/// # Panics
|
|
||||||
///
|
|
||||||
/// This function will panic if the path does not exist or the path does not
|
|
||||||
/// contain a valid metric map.
|
|
||||||
pub fn load(p: &Path) -> MetricMap {
|
|
||||||
assert!(p.exists());
|
|
||||||
let mut f = File::open(p).unwrap();
|
|
||||||
let value = json::from_reader(&mut f as &mut io::Reader).unwrap();
|
|
||||||
let mut decoder = json::Decoder::new(value);
|
|
||||||
MetricMap(match Decodable::decode(&mut decoder) {
|
|
||||||
Ok(t) => t,
|
|
||||||
Err(e) => panic!("failure decoding JSON: {:?}", e)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Write MetricDiff to a file.
|
|
||||||
pub fn save(&self, p: &Path) -> io::IoResult<()> {
|
|
||||||
let mut file = try!(File::create(p));
|
|
||||||
let MetricMap(ref map) = *self;
|
|
||||||
write!(&mut file, "{}", json::as_json(map))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Insert a named `value` (+/- `noise`) metric into the map. The value
|
/// Insert a named `value` (+/- `noise`) metric into the map. The value
|
||||||
/// must be non-negative. The `noise` indicates the uncertainty of the
|
/// must be non-negative. The `noise` indicates the uncertainty of the
|
||||||
/// metric, which doubles as the "noise range" of acceptable
|
/// metric, which doubles as the "noise range" of acceptable
|
||||||
|
@ -1055,6 +972,15 @@ impl MetricMap {
|
||||||
let MetricMap(ref mut map) = *self;
|
let MetricMap(ref mut map) = *self;
|
||||||
map.insert(name.to_string(), m);
|
map.insert(name.to_string(), m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fmt_metrics(&self) -> String {
|
||||||
|
let MetricMap(ref mm) = *self;
|
||||||
|
let v : Vec<String> = mm.iter()
|
||||||
|
.map(|(k,v)| format!("{}: {} (+/- {})", *k,
|
||||||
|
v.value as f64, v.noise as f64))
|
||||||
|
.collect();
|
||||||
|
v.connect(", ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -13,9 +13,7 @@
|
||||||
use std::cmp::Ordering::{self, Less, Greater, Equal};
|
use std::cmp::Ordering::{self, Less, Greater, Equal};
|
||||||
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
use std::collections::hash_map::Entry::{Occupied, Vacant};
|
||||||
use std::collections::hash_map::{self, Hasher};
|
use std::collections::hash_map::{self, Hasher};
|
||||||
use std::fmt;
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::io;
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::num::{Float, FromPrimitive};
|
use std::num::{Float, FromPrimitive};
|
||||||
|
|
||||||
|
@ -332,111 +330,6 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render writes the min, max and quartiles of the provided `Summary` to the provided `Writer`.
|
|
||||||
pub fn write_5_number_summary<W: Writer, T: Float + fmt::Display + fmt::Debug>(w: &mut W,
|
|
||||||
s: &Summary<T>) -> io::IoResult<()> {
|
|
||||||
let (q1,q2,q3) = s.quartiles;
|
|
||||||
write!(w, "(min={}, q1={}, med={}, q3={}, max={})",
|
|
||||||
s.min,
|
|
||||||
q1,
|
|
||||||
q2,
|
|
||||||
q3,
|
|
||||||
s.max)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Render a boxplot to the provided writer. The boxplot shows the min, max and quartiles of the
|
|
||||||
/// provided `Summary` (thus includes the mean) and is scaled to display within the range of the
|
|
||||||
/// nearest multiple-of-a-power-of-ten above and below the min and max of possible values, and
|
|
||||||
/// target `width_hint` characters of display (though it will be wider if necessary).
|
|
||||||
///
|
|
||||||
/// As an example, the summary with 5-number-summary `(min=15, q1=17, med=20, q3=24, max=31)` might
|
|
||||||
/// display as:
|
|
||||||
///
|
|
||||||
/// ```{.ignore}
|
|
||||||
/// 10 | [--****#******----------] | 40
|
|
||||||
/// ```
|
|
||||||
pub fn write_boxplot<W: Writer, T: Float + fmt::Display + fmt::Debug + FromPrimitive>(
|
|
||||||
w: &mut W,
|
|
||||||
s: &Summary<T>,
|
|
||||||
width_hint: uint)
|
|
||||||
-> io::IoResult<()> {
|
|
||||||
|
|
||||||
let (q1,q2,q3) = s.quartiles;
|
|
||||||
|
|
||||||
// the .abs() handles the case where numbers are negative
|
|
||||||
let ten: T = FromPrimitive::from_uint(10).unwrap();
|
|
||||||
let lomag = ten.powf(s.min.abs().log10().floor());
|
|
||||||
let himag = ten.powf(s.max.abs().log10().floor());
|
|
||||||
|
|
||||||
// need to consider when the limit is zero
|
|
||||||
let zero: T = Float::zero();
|
|
||||||
let lo = if lomag == Float::zero() {
|
|
||||||
zero
|
|
||||||
} else {
|
|
||||||
(s.min / lomag).floor() * lomag
|
|
||||||
};
|
|
||||||
|
|
||||||
let hi = if himag == Float::zero() {
|
|
||||||
zero
|
|
||||||
} else {
|
|
||||||
(s.max / himag).ceil() * himag
|
|
||||||
};
|
|
||||||
|
|
||||||
let range = hi - lo;
|
|
||||||
|
|
||||||
let lostr = lo.to_string();
|
|
||||||
let histr = hi.to_string();
|
|
||||||
|
|
||||||
let overhead_width = lostr.len() + histr.len() + 4;
|
|
||||||
let range_width = width_hint - overhead_width;
|
|
||||||
let range_float = FromPrimitive::from_uint(range_width).unwrap();
|
|
||||||
let char_step = range / range_float;
|
|
||||||
|
|
||||||
try!(write!(w, "{} |", lostr));
|
|
||||||
|
|
||||||
let mut c = 0;
|
|
||||||
let mut v = lo;
|
|
||||||
|
|
||||||
while c < range_width && v < s.min {
|
|
||||||
try!(write!(w, " "));
|
|
||||||
v = v + char_step;
|
|
||||||
c += 1;
|
|
||||||
}
|
|
||||||
try!(write!(w, "["));
|
|
||||||
c += 1;
|
|
||||||
while c < range_width && v < q1 {
|
|
||||||
try!(write!(w, "-"));
|
|
||||||
v = v + char_step;
|
|
||||||
c += 1;
|
|
||||||
}
|
|
||||||
while c < range_width && v < q2 {
|
|
||||||
try!(write!(w, "*"));
|
|
||||||
v = v + char_step;
|
|
||||||
c += 1;
|
|
||||||
}
|
|
||||||
try!(write!(w, "#"));
|
|
||||||
c += 1;
|
|
||||||
while c < range_width && v < q3 {
|
|
||||||
try!(write!(w, "*"));
|
|
||||||
v = v + char_step;
|
|
||||||
c += 1;
|
|
||||||
}
|
|
||||||
while c < range_width && v < s.max {
|
|
||||||
try!(write!(w, "-"));
|
|
||||||
v = v + char_step;
|
|
||||||
c += 1;
|
|
||||||
}
|
|
||||||
try!(write!(w, "]"));
|
|
||||||
while c < range_width {
|
|
||||||
try!(write!(w, " "));
|
|
||||||
v = v + char_step;
|
|
||||||
c += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
try!(write!(w, "| {}", histr));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a HashMap with the number of occurrences of every element in the
|
/// Returns a HashMap with the number of occurrences of every element in the
|
||||||
/// sequence that the iterator exposes.
|
/// sequence that the iterator exposes.
|
||||||
pub fn freq_count<T, U>(mut iter: T) -> hash_map::HashMap<U, uint>
|
pub fn freq_count<T, U>(mut iter: T) -> hash_map::HashMap<U, uint>
|
||||||
|
@ -458,8 +351,6 @@ pub fn freq_count<T, U>(mut iter: T) -> hash_map::HashMap<U, uint>
|
||||||
mod tests {
|
mod tests {
|
||||||
use stats::Stats;
|
use stats::Stats;
|
||||||
use stats::Summary;
|
use stats::Summary;
|
||||||
use stats::write_5_number_summary;
|
|
||||||
use stats::write_boxplot;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
|
|
||||||
|
@ -479,10 +370,6 @@ mod tests {
|
||||||
let mut w = io::stdout();
|
let mut w = io::stdout();
|
||||||
let w = &mut w;
|
let w = &mut w;
|
||||||
(write!(w, "\n")).unwrap();
|
(write!(w, "\n")).unwrap();
|
||||||
write_5_number_summary(w, &summ2).unwrap();
|
|
||||||
(write!(w, "\n")).unwrap();
|
|
||||||
write_boxplot(w, &summ2, 50).unwrap();
|
|
||||||
(write!(w, "\n")).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(summ.sum, summ2.sum);
|
assert_eq!(summ.sum, summ2.sum);
|
||||||
assert_eq!(summ.min, summ2.min);
|
assert_eq!(summ.min, summ2.min);
|
||||||
|
@ -1028,23 +915,6 @@ mod tests {
|
||||||
check(val, summ);
|
check(val, summ);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_boxplot_nonpositive() {
|
|
||||||
fn t(s: &Summary<f64>, expected: String) {
|
|
||||||
let mut m = Vec::new();
|
|
||||||
write_boxplot(&mut m, s, 30).unwrap();
|
|
||||||
let out = String::from_utf8(m).unwrap();
|
|
||||||
assert_eq!(out, expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
t(&Summary::new(&[-2.0f64, -1.0f64]),
|
|
||||||
"-2 |[------******#*****---]| -1".to_string());
|
|
||||||
t(&Summary::new(&[0.0f64, 2.0f64]),
|
|
||||||
"0 |[-------*****#*******---]| 2".to_string());
|
|
||||||
t(&Summary::new(&[-2.0f64, 0.0f64]),
|
|
||||||
"-2 |[------******#******---]| 0".to_string());
|
|
||||||
|
|
||||||
}
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_sum_f64s() {
|
fn test_sum_f64s() {
|
||||||
assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(), 5.2999);
|
assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(), 5.2999);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue