From cfc28ebc05cab1fa94ebd129a38f38f7d2e1edd9 Mon Sep 17 00:00:00 2001 From: Knight Date: Sat, 6 Aug 2016 11:18:34 +0800 Subject: [PATCH 1/2] tests: extern crates in separated test modules --- tests/common/macros.rs | 0 tests/common/util.rs | 9 +++++---- tests/test_factor.rs | 11 ++++++++--- tests/test_mktemp.rs | 3 ++- tests/test_split.rs | 4 ++-- tests/tests.rs | 13 ------------- 6 files changed, 17 insertions(+), 23 deletions(-) mode change 100755 => 100644 tests/common/macros.rs mode change 100755 => 100644 tests/common/util.rs diff --git a/tests/common/macros.rs b/tests/common/macros.rs old mode 100755 new mode 100644 diff --git a/tests/common/util.rs b/tests/common/util.rs old mode 100755 new mode 100644 index 1193b79b0..76af81e18 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +extern crate tempdir; use std::env; use std::fs::{self, File, OpenOptions}; @@ -14,7 +15,7 @@ use std::ffi::OsStr; use std::rc::Rc; use std::thread::sleep; use std::time::Duration; -use tempdir::TempDir; +use self::tempdir::TempDir; #[cfg(windows)] static PROGNAME: &'static str = "uutils.exe"; @@ -64,7 +65,7 @@ impl CmdResult { assert!(!self.success); Box::new(self) } - + /// asserts that the command resulted in empty (zero-length) stderr stream output /// generally, it's better to use stdout_only() instead, /// but you might find yourself using this function if @@ -74,7 +75,7 @@ impl CmdResult { assert_eq!(0, self.stderr.len()); Box::new(self) } - + /// asserts that the command resulted in empty (zero-length) stderr stream output /// unless asserting there was neither stdout or stderr, stderr_only is usually a better choice /// generally, it's better to use stderr_only() instead, @@ -93,7 +94,7 @@ impl CmdResult { assert_eq!(String::from(msg.as_ref()).trim_right(), self.stdout.trim_right()); Box::new(self) } - + /// like stdout_is(...), but expects the contents of the file at the provided relative path pub fn stdout_is_fixture>(&self, file_rel_path: T) -> Box<&CmdResult> { let contents = read_scenario_fixture(&self.tmpd, file_rel_path); diff --git a/tests/test_factor.rs b/tests/test_factor.rs index 33b8a2418..1912a24e5 100644 --- a/tests/test_factor.rs +++ b/tests/test_factor.rs @@ -8,9 +8,14 @@ // use common::util::*; -use rand::{weak_rng, Rng}; -use rand::distributions::{IndependentSample, Range}; -use sieve::Sieve; + +#[path="../src/factor/sieve.rs"] +mod sieve; +use self::sieve::Sieve; + +extern crate rand; +use self::rand::{weak_rng, Rng}; +use self::rand::distributions::{IndependentSample, Range}; const NUM_PRIMES: usize = 10000; const LOG_PRIMES: f64 = 14.0; // ceil(log2(NUM_PRIMES)) diff --git a/tests/test_mktemp.rs b/tests/test_mktemp.rs index 99c4f0a70..0783c5d2c 100644 --- a/tests/test_mktemp.rs +++ b/tests/test_mktemp.rs @@ -1,5 +1,6 @@ use common::util::*; -use tempdir::TempDir; +extern crate tempdir; +use self::tempdir::TempDir; static UTIL_NAME: &'static str = "mktemp"; diff --git a/tests/test_split.rs b/tests/test_split.rs index a01817a79..582f3e0b1 100644 --- a/tests/test_split.rs +++ b/tests/test_split.rs @@ -4,8 +4,8 @@ extern crate regex; use std::fs::{File, read_dir}; use std::io::{Read, Write}; use std::path::Path; -use rand::{Rng, thread_rng}; -use regex::Regex; +use self::rand::{Rng, thread_rng}; +use self::regex::Regex; use common::util::*; static UTIL_NAME: &'static str = "split"; diff --git a/tests/tests.rs b/tests/tests.rs index b9145f8a0..86f489fa0 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,19 +1,6 @@ -extern crate filetime; -extern crate libc; -extern crate rand; -extern crate regex; -extern crate tempdir; -extern crate time; - -#[cfg(windows)] extern crate kernel32; -#[cfg(windows)] extern crate winapi; - #[macro_use] mod common; -#[path="../src/factor/sieve.rs"] -mod sieve; - // For conditional compilation macro_rules! unix_only { ($($fea:expr, $m:ident);+) => { From a23f1a13e76504e464ecc8f287c191e34a0d757a Mon Sep 17 00:00:00 2001 From: Knight Date: Sun, 7 Aug 2016 01:22:17 +0800 Subject: [PATCH 2/2] Remove useless crates --- Cargo.toml | 6 ------ tests/test_install.rs | 9 +-------- tests/test_link.rs | 2 -- tests/test_mv.rs | 3 --- tests/test_rmdir.rs | 2 -- 5 files changed, 1 insertion(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c88f9c23e..1263c63c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -192,14 +192,8 @@ yes = { optional=true, path="src/yes" } [dev-dependencies] time = "*" -kernel32-sys = "*" -winapi = "*" filetime = "*" libc = "*" -memchr = "*" -primal = "*" -aho-corasick= "*" -regex-syntax= "*" regex="*" rand="*" tempdir="*" diff --git a/tests/test_install.rs b/tests/test_install.rs index a86a5e4e1..52ace1983 100644 --- a/tests/test_install.rs +++ b/tests/test_install.rs @@ -1,10 +1,3 @@ -extern crate libc; -extern crate time; -extern crate kernel32; -extern crate winapi; -extern crate filetime; - -use self::filetime::*; use common::util::*; use std::os::unix::fs::PermissionsExt; @@ -17,7 +10,7 @@ fn at_and_ucmd() -> (AtPath, UCommand) { #[test] fn test_install_help() { - let (at, mut ucmd) = at_and_ucmd(); + let (_, mut ucmd) = at_and_ucmd(); let result = ucmd.arg("--help").run(); diff --git a/tests/test_link.rs b/tests/test_link.rs index 45f28967a..4915be825 100644 --- a/tests/test_link.rs +++ b/tests/test_link.rs @@ -1,5 +1,3 @@ -extern crate libc; - use common::util::*; static UTIL_NAME: &'static str = "link"; diff --git a/tests/test_mv.rs b/tests/test_mv.rs index 34073c5f9..c8f677cec 100644 --- a/tests/test_mv.rs +++ b/tests/test_mv.rs @@ -1,7 +1,4 @@ -extern crate libc; extern crate time; -extern crate kernel32; -extern crate winapi; extern crate filetime; use self::filetime::*; diff --git a/tests/test_rmdir.rs b/tests/test_rmdir.rs index 021b0b4ef..248b11379 100644 --- a/tests/test_rmdir.rs +++ b/tests/test_rmdir.rs @@ -1,5 +1,3 @@ -extern crate libc; - use common::util::*; static UTIL_NAME: &'static str = "rmdir";