]> git.lizzy.rs Git - rust.git/blobdiff - src/libtest/tests.rs
rustc_span: return an impl Iterator instead of a Vec from macro_backtrace.
[rust.git] / src / libtest / tests.rs
index 0bea2b80ecf5e185e2ce40f7c82cb0af14346e98..85a0705f69c0a8fc4ba80bb3571abd24d6e994d8 100644 (file)
@@ -3,17 +3,29 @@
 use crate::{
     bench::Bencher,
     console::OutputLocation,
-    options::OutputFormat,
-    time::{TimeThreshold, TestTimeOptions},
     formatters::PrettyFormatter,
+    options::OutputFormat,
     test::{
-        filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap,
-        RunIgnored, RunStrategy, ShouldPanic, StaticTestName, TestDesc,
-        TestDescAndFn, TestOpts, TrIgnored, TrOk,
+        filter_tests,
+        parse_opts,
+        run_test,
+        DynTestFn,
+        DynTestName,
+        MetricMap,
+        RunIgnored,
+        RunStrategy,
+        ShouldPanic,
+        StaticTestName,
+        TestDesc,
+        TestDescAndFn,
+        TestOpts,
+        TrIgnored,
+        TrOk,
         // FIXME (introduced by #65251)
         // ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TestTimeOptions,
         // TestType, TrFailedMsg, TrIgnored, TrOk,
     },
+    time::{TestTimeOptions, TimeThreshold},
 };
 use std::any::TypeId;
 use std::sync::mpsc::channel;
@@ -190,9 +202,12 @@ fn f() {
         panic!(1i32);
     }
     let expected = "foobar";
-    let failed_msg = format!(r#"expected panic with string value,
+    let failed_msg = format!(
+        r#"expected panic with string value,
  found non-string value: `{:?}`
-     expected substring: `"foobar"`"#, TypeId::of::<i32>());
+     expected substring: `"foobar"`"#,
+        TypeId::of::<i32>()
+    );
     let desc = TestDescAndFn {
         desc: TestDesc {
             name: StaticTestName("whatever"),
@@ -242,16 +257,9 @@ fn f() {}
         },
         testfn: DynTestFn(Box::new(f)),
     };
-    let time_options = if report_time {
-        Some(TestTimeOptions::default())
-    } else {
-        None
-    };
+    let time_options = if report_time { Some(TestTimeOptions::default()) } else { None };
 
-    let test_opts = TestOpts {
-        time_options,
-        ..TestOpts::new()
-    };
+    let test_opts = TestOpts { time_options, ..TestOpts::new() };
     let (tx, rx) = channel();
     run_test(&test_opts, false, desc, RunStrategy::InProcess, tx, Concurrent::No);
     let exec_time = rx.recv().unwrap().exec_time;
@@ -278,7 +286,7 @@ fn f() {}
             ignore: false,
             should_panic: ShouldPanic::No,
             allow_fail: false,
-            test_type
+            test_type,
         },
         testfn: DynTestFn(Box::new(f)),
     };
@@ -286,10 +294,7 @@ fn f() {}
     let mut time_options = TestTimeOptions::default();
     time_options.error_on_excess = true;
 
-    let test_opts = TestOpts {
-        time_options: Some(time_options),
-        ..TestOpts::new()
-    };
+    let test_opts = TestOpts { time_options: Some(time_options), ..TestOpts::new() };
     let (tx, rx) = channel();
     run_test(&test_opts, false, desc, RunStrategy::InProcess, tx, Concurrent::No);
     let result = rx.recv().unwrap().result;
@@ -318,7 +323,7 @@ fn typed_test_desc(test_type: TestType) -> TestDesc {
         ignore: false,
         should_panic: ShouldPanic::No,
         allow_fail: false,
-        test_type
+        test_type,
     }
 }
 
@@ -363,22 +368,14 @@ fn test_time_options_threshold() {
 
 #[test]
 fn parse_ignored_flag() {
-    let args = vec![
-        "progname".to_string(),
-        "filter".to_string(),
-        "--ignored".to_string(),
-    ];
+    let args = vec!["progname".to_string(), "filter".to_string(), "--ignored".to_string()];
     let opts = parse_opts(&args).unwrap().unwrap();
     assert_eq!(opts.run_ignored, RunIgnored::Only);
 }
 
 #[test]
 fn parse_show_output_flag() {
-    let args = vec![
-        "progname".to_string(),
-        "filter".to_string(),
-        "--show-output".to_string(),
-    ];
+    let args = vec!["progname".to_string(), "filter".to_string(), "--show-output".to_string()];
     let opts = parse_opts(&args).unwrap().unwrap();
     assert!(opts.options.display_output);
 }
@@ -471,78 +468,41 @@ fn tests() -> Vec<TestDescAndFn> {
             .collect()
     }
 
-    let substr = filter_tests(
-        &TestOpts {
-            filter: Some("base".into()),
-            ..TestOpts::new()
-        },
-        tests(),
-    );
+    let substr =
+        filter_tests(&TestOpts { filter: Some("base".into()), ..TestOpts::new() }, tests());
     assert_eq!(substr.len(), 4);
 
-    let substr = filter_tests(
-        &TestOpts {
-            filter: Some("bas".into()),
-            ..TestOpts::new()
-        },
-        tests(),
-    );
+    let substr = filter_tests(&TestOpts { filter: Some("bas".into()), ..TestOpts::new() }, tests());
     assert_eq!(substr.len(), 4);
 
-    let substr = filter_tests(
-        &TestOpts {
-            filter: Some("::test".into()),
-            ..TestOpts::new()
-        },
-        tests(),
-    );
+    let substr =
+        filter_tests(&TestOpts { filter: Some("::test".into()), ..TestOpts::new() }, tests());
     assert_eq!(substr.len(), 3);
 
-    let substr = filter_tests(
-        &TestOpts {
-            filter: Some("base::test".into()),
-            ..TestOpts::new()
-        },
-        tests(),
-    );
+    let substr =
+        filter_tests(&TestOpts { filter: Some("base::test".into()), ..TestOpts::new() }, tests());
     assert_eq!(substr.len(), 3);
 
     let exact = filter_tests(
-        &TestOpts {
-            filter: Some("base".into()),
-            filter_exact: true,
-            ..TestOpts::new()
-        },
+        &TestOpts { filter: Some("base".into()), filter_exact: true, ..TestOpts::new() },
         tests(),
     );
     assert_eq!(exact.len(), 1);
 
     let exact = filter_tests(
-        &TestOpts {
-            filter: Some("bas".into()),
-            filter_exact: true,
-            ..TestOpts::new()
-        },
+        &TestOpts { filter: Some("bas".into()), filter_exact: true, ..TestOpts::new() },
         tests(),
     );
     assert_eq!(exact.len(), 0);
 
     let exact = filter_tests(
-        &TestOpts {
-            filter: Some("::test".into()),
-            filter_exact: true,
-            ..TestOpts::new()
-        },
+        &TestOpts { filter: Some("::test".into()), filter_exact: true, ..TestOpts::new() },
         tests(),
     );
     assert_eq!(exact.len(), 0);
 
     let exact = filter_tests(
-        &TestOpts {
-            filter: Some("base::test".into()),
-            filter_exact: true,
-            ..TestOpts::new()
-        },
+        &TestOpts { filter: Some("base::test".into()), filter_exact: true, ..TestOpts::new() },
         tests(),
     );
     assert_eq!(exact.len(), 1);