about summary refs log tree commit diff
path: root/src/libtest
diff options
context:
space:
mode:
authorJorge Aparicio <japaricious@gmail.com>2015-02-01 21:53:25 -0500
committerJorge Aparicio <japaricious@gmail.com>2015-02-05 13:45:01 -0500
commit17bc7d8d5be3be9674d702ccad2fa88c487d23b0 (patch)
tree325defba0f55b48273cd3f0814fe6c083dee5d41 /src/libtest
parent2c05354211b04a52cc66a0b8ad8b2225eaf9e972 (diff)
downloadrust-17bc7d8d5be3be9674d702ccad2fa88c487d23b0.tar.gz
rust-17bc7d8d5be3be9674d702ccad2fa88c487d23b0.zip
cleanup: replace `as[_mut]_slice()` calls with deref coercions
Diffstat (limited to 'src/libtest')
-rw-r--r--src/libtest/lib.rs52
-rw-r--r--src/libtest/stats.rs18
2 files changed, 33 insertions, 37 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index c369e354875..f3edd90b4fa 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -105,7 +105,7 @@ impl TestName {
     fn as_slice<'a>(&'a self) -> &'a str {
         match *self {
             StaticTestName(s) => s,
-            DynTestName(ref s) => s.as_slice()
+            DynTestName(ref s) => s
         }
     }
 }
@@ -130,11 +130,11 @@ impl TestDesc {
         match align {
             PadNone => name,
             PadOnLeft => {
-                pad.push_str(name.as_slice());
+                pad.push_str(&name);
                 pad
             }
             PadOnRight => {
-                name.push_str(pad.as_slice());
+                name.push_str(&pad);
                 name
             }
         }
@@ -354,20 +354,19 @@ Test Attributes:
                      test, then the test runner will ignore these tests during
                      normal test runs. Running with --ignored will run these
                      tests."#,
-             usage = getopts::usage(message.as_slice(),
-                                    optgroups().as_slice()));
+             usage = getopts::usage(&message, &optgroups()));
 }
 
 // Parses command line arguments into test options
 pub fn parse_opts(args: &[String]) -> Option<OptRes> {
     let args_ = args.tail();
     let matches =
-        match getopts::getopts(args_.as_slice(), optgroups().as_slice()) {
+        match getopts::getopts(args_, &optgroups()) {
           Ok(m) => m,
           Err(f) => return Some(Err(f.to_string()))
         };
 
-    if matches.opt_present("h") { usage(args[0].as_slice()); return None; }
+    if matches.opt_present("h") { usage(&args[0]); return None; }
 
     let filter = if matches.free.len() > 0 {
         Some(matches.free[0].clone())
@@ -389,7 +388,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
         nocapture = env::var("RUST_TEST_NOCAPTURE").is_some();
     }
 
-    let color = match matches.opt_str("color").as_ref().map(|s| s.as_slice()) {
+    let color = match matches.opt_str("color").as_ref().map(|s| &**s) {
         Some("auto") | None => AutoColor,
         Some("always") => AlwaysColor,
         Some("never") => NeverColor,
@@ -523,13 +522,13 @@ impl<T: Writer> ConsoleTestState<T> {
     pub fn write_run_start(&mut self, len: uint) -> old_io::IoResult<()> {
         self.total = len;
         let noun = if len != 1 { "tests" } else { "test" };
-        self.write_plain(format!("\nrunning {} {}\n", len, noun).as_slice())
+        self.write_plain(&format!("\nrunning {} {}\n", len, noun))
     }
 
     pub fn write_test_start(&mut self, test: &TestDesc,
                             align: NamePadding) -> old_io::IoResult<()> {
         let name = test.padded_name(self.max_name_len, align);
-        self.write_plain(format!("test {} ... ", name).as_slice())
+        self.write_plain(&format!("test {} ... ", name))
     }
 
     pub fn write_result(&mut self, result: &TestResult) -> old_io::IoResult<()> {
@@ -539,13 +538,12 @@ impl<T: Writer> ConsoleTestState<T> {
             TrIgnored => self.write_ignored(),
             TrMetrics(ref mm) => {
                 try!(self.write_metric());
-                self.write_plain(format!(": {}", mm.fmt_metrics()).as_slice())
+                self.write_plain(&format!(": {}", mm.fmt_metrics()))
             }
             TrBench(ref bs) => {
                 try!(self.write_bench());
 
-                try!(self.write_plain(format!(": {}",
-                                              fmt_bench_samples(bs)).as_slice()));
+                try!(self.write_plain(&format!(": {}", fmt_bench_samples(bs))));
 
                 Ok(())
             }
@@ -564,7 +562,7 @@ impl<T: Writer> ConsoleTestState<T> {
                         TrIgnored => "ignored".to_string(),
                         TrMetrics(ref mm) => mm.fmt_metrics(),
                         TrBench(ref bs) => fmt_bench_samples(bs)
-                    }, test.name.as_slice());
+                    }, test.name);
                 o.write_all(s.as_bytes())
             }
         }
@@ -577,23 +575,21 @@ impl<T: Writer> ConsoleTestState<T> {
         for &(ref f, ref stdout) in &self.failures {
             failures.push(f.name.to_string());
             if stdout.len() > 0 {
-                fail_out.push_str(format!("---- {} stdout ----\n\t",
-                                          f.name.as_slice()).as_slice());
-                let output = String::from_utf8_lossy(stdout.as_slice());
-                fail_out.push_str(output.as_slice());
+                fail_out.push_str(&format!("---- {} stdout ----\n\t", f.name));
+                let output = String::from_utf8_lossy(stdout);
+                fail_out.push_str(&output);
                 fail_out.push_str("\n");
             }
         }
         if fail_out.len() > 0 {
             try!(self.write_plain("\n"));
-            try!(self.write_plain(fail_out.as_slice()));
+            try!(self.write_plain(&fail_out));
         }
 
         try!(self.write_plain("\nfailures:\n"));
         failures.sort();
         for name in &failures {
-            try!(self.write_plain(format!("    {}\n",
-                                          name.as_slice()).as_slice()));
+            try!(self.write_plain(&format!("    {}\n", name)));
         }
         Ok(())
     }
@@ -615,7 +611,7 @@ impl<T: Writer> ConsoleTestState<T> {
         }
         let s = format!(". {} passed; {} failed; {} ignored; {} measured\n\n",
                         self.passed, self.failed, self.ignored, self.measured);
-        try!(self.write_plain(s.as_slice()));
+        try!(self.write_plain(&s));
         return Ok(success);
     }
 }
@@ -648,13 +644,13 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn> ) -> old_io:
                     TrOk => st.passed += 1,
                     TrIgnored => st.ignored += 1,
                     TrMetrics(mm) => {
-                        let tname = test.name.as_slice();
+                        let tname = test.name;
                         let MetricMap(mm) = mm;
                         for (k,v) in &mm {
                             st.metrics
-                              .insert_metric(format!("{}.{}",
-                                                     tname,
-                                                     k).as_slice(),
+                              .insert_metric(&format!("{}.{}",
+                                                      tname,
+                                                      k),
                                              v.value,
                                              v.noise);
                         }
@@ -686,7 +682,7 @@ pub fn run_tests_console(opts: &TestOpts, tests: Vec<TestDescAndFn> ) -> old_io:
     match tests.iter().max_by(|t|len_if_padded(*t)) {
         Some(t) => {
             let n = t.desc.name.as_slice();
-            st.max_name_len = n.len();
+            st.max_name_len = n.as_slice().len();
         },
         None => {}
     }
@@ -1237,7 +1233,7 @@ mod tests {
         let args = vec!("progname".to_string(),
                         "filter".to_string(),
                         "--ignored".to_string());
-        let opts = match parse_opts(args.as_slice()) {
+        let opts = match parse_opts(&args) {
             Some(Ok(o)) => o,
             _ => panic!("Malformed arg in parse_ignored_flag")
         };
diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs
index ebd86dbf61c..04617757465 100644
--- a/src/libtest/stats.rs
+++ b/src/libtest/stats.rs
@@ -260,19 +260,19 @@ impl<T: Float + FromPrimitive> Stats<T> for [T] {
 
     fn percentile(&self, pct: T) -> T {
         let mut tmp = self.to_vec();
-        local_sort(tmp.as_mut_slice());
-        percentile_of_sorted(tmp.as_slice(), pct)
+        local_sort(&mut tmp);
+        percentile_of_sorted(&tmp, pct)
     }
 
     fn quartiles(&self) -> (T,T,T) {
         let mut tmp = self.to_vec();
-        local_sort(tmp.as_mut_slice());
+        local_sort(&mut tmp);
         let first = FromPrimitive::from_uint(25).unwrap();
-        let a = percentile_of_sorted(tmp.as_slice(), first);
+        let a = percentile_of_sorted(&tmp, first);
         let secound = FromPrimitive::from_uint(50).unwrap();
-        let b = percentile_of_sorted(tmp.as_slice(), secound);
+        let b = percentile_of_sorted(&tmp, secound);
         let third = FromPrimitive::from_uint(75).unwrap();
-        let c = percentile_of_sorted(tmp.as_slice(), third);
+        let c = percentile_of_sorted(&tmp, third);
         (a,b,c)
     }
 
@@ -317,10 +317,10 @@ fn percentile_of_sorted<T: Float + FromPrimitive>(sorted_samples: &[T],
 /// See: http://en.wikipedia.org/wiki/Winsorising
 pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
     let mut tmp = samples.to_vec();
-    local_sort(tmp.as_mut_slice());
-    let lo = percentile_of_sorted(tmp.as_slice(), pct);
+    local_sort(&mut tmp);
+    let lo = percentile_of_sorted(&tmp, pct);
     let hundred: T = FromPrimitive::from_uint(100).unwrap();
-    let hi = percentile_of_sorted(tmp.as_slice(), hundred-pct);
+    let hi = percentile_of_sorted(&tmp, hundred-pct);
     for samp in samples {
         if *samp > hi {
             *samp = hi