diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-07-30 08:53:22 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-08-04 14:02:36 -0700 |
| commit | 0d8340327c03f319b49cb91e2e64aa66dd1e76c7 (patch) | |
| tree | 308af0af76da6c6a020ee5e8d9e5dbb40152307a /src/libtest | |
| parent | 5cccf3cd256420d9f32c265e83036dea1d5f94d8 (diff) | |
| download | rust-0d8340327c03f319b49cb91e2e64aa66dd1e76c7.tar.gz rust-0d8340327c03f319b49cb91e2e64aa66dd1e76c7.zip | |
syntax: Don't assume `std` exists for tests
This commit removes the injection of `std::env::args()` from `--test` expanded code, relying on the test runner itself to call this funciton. This is more hygienic because we can't assume that `std` exists at the top layer all the time, and it meaks the injected test module entirely self contained.
Diffstat (limited to 'src/libtest')
| -rw-r--r-- | src/libtest/lib.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 194b6c8e3e2..7777ea51f82 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -197,7 +197,8 @@ pub struct Bencher { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum ShouldPanic { No, - Yes(Option<&'static str>) + Yes, + YesWithMessage(&'static str) } // The definition of a single test. A test runner will run a list of @@ -262,8 +263,8 @@ pub fn test_main(args: &[String], tests: Vec<TestDescAndFn> ) { // a Vec<TestDescAndFn> is used in order to effect ownership-transfer // semantics into parallel test runners, which in turn requires a Vec<> // rather than a &[]. -pub fn test_main_static(args: env::Args, tests: &[TestDescAndFn]) { - let args = args.collect::<Vec<_>>(); +pub fn test_main_static(tests: &[TestDescAndFn]) { + let args = env::args().collect::<Vec<_>>(); let owned_tests = tests.iter().map(|t| { match t.testfn { StaticTestFn(f) => TestDescAndFn { testfn: StaticTestFn(f), desc: t.desc.clone() }, @@ -1027,8 +1028,8 @@ pub fn run_test(opts: &TestOpts, fn calc_result(desc: &TestDesc, task_result: Result<(), Box<Any+Send>>) -> TestResult { match (&desc.should_panic, task_result) { (&ShouldPanic::No, Ok(())) | - (&ShouldPanic::Yes(None), Err(_)) => TrOk, - (&ShouldPanic::Yes(Some(msg)), Err(ref err)) + (&ShouldPanic::Yes, Err(_)) => TrOk, + (&ShouldPanic::YesWithMessage(msg), Err(ref err)) if err.downcast_ref::<String>() .map(|e| &**e) .or_else(|| err.downcast_ref::<&'static str>().map(|e| *e)) @@ -1276,7 +1277,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(None) + should_panic: ShouldPanic::Yes, }, testfn: DynTestFn(Box::new(move|| f())), }; @@ -1293,7 +1294,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(Some("error message")) + should_panic: ShouldPanic::YesWithMessage("error message"), }, testfn: DynTestFn(Box::new(move|| f())), }; @@ -1310,7 +1311,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(Some("foobar")) + should_panic: ShouldPanic::YesWithMessage("foobar"), }, testfn: DynTestFn(Box::new(move|| f())), }; @@ -1327,7 +1328,7 @@ mod tests { desc: TestDesc { name: StaticTestName("whatever"), ignore: false, - should_panic: ShouldPanic::Yes(None) + should_panic: ShouldPanic::Yes, }, testfn: DynTestFn(Box::new(move|| f())), }; |
