]> git.lizzy.rs Git - rust.git/commitdiff
update unit tests
authorNiko Matsakis <niko@alum.mit.edu>
Sat, 30 Apr 2016 01:13:42 +0000 (21:13 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 2 May 2016 15:49:26 +0000 (11:49 -0400)
src/libsyntax/errors/emitter.rs
src/libsyntax/errors/mod.rs
src/libsyntax/errors/snippet/mod.rs
src/libsyntax/errors/snippet/test.rs

index 769f6b05397060713cd1571be93ee665a44548fc..486e2ace0876a1b9196c5f409b814e3e710a9c65 100644 (file)
@@ -13,6 +13,7 @@
 use codemap::{self, COMMAND_LINE_SP, DUMMY_SP, Pos, Span, MultiSpan};
 use diagnostics;
 
+use errors::check_old_skool;
 use errors::{Level, RenderSpan, CodeSuggestion, DiagnosticBuilder};
 use errors::RenderSpan::*;
 use errors::Level::*;
@@ -59,10 +60,7 @@ fn emit(&mut self,
     }
 
     fn emit_struct(&mut self, db: &DiagnosticBuilder) {
-        let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-            Ok(_) => false,
-            Err(_) => true,
-        };
+        let old_school = check_old_skool();
         let db_span = FullSpan(db.span.clone());
         self.emit_message(&FullSpan(db.span.clone()),
                           &db.message,
@@ -198,10 +196,7 @@ pub fn stderr(color_config: ColorConfig,
                   registry: Option<diagnostics::registry::Registry>,
                   code_map: Rc<codemap::CodeMap>)
                   -> EmitterWriter {
-        let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-            Ok(_) => false,
-            Err(_) => true,
-        };
+        let old_school = check_old_skool();
         if color_config.use_color() {
             let dst = Destination::from_stderr();
             EmitterWriter { dst: dst,
@@ -222,10 +217,7 @@ pub fn new(dst: Box<Write + Send>,
                registry: Option<diagnostics::registry::Registry>,
                code_map: Rc<codemap::CodeMap>)
                -> EmitterWriter {
-        let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-            Ok(_) => false,
-            Err(_) => true,
-        };
+        let old_school = check_old_skool();
         EmitterWriter { dst: Raw(dst),
                         registry: registry,
                         cm: code_map,
@@ -454,10 +446,7 @@ fn print_diagnostic(dst: &mut Destination,
                     code: Option<&str>)
                     -> io::Result<()> {
     if !topic.is_empty() {
-        let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-            Ok(_) => false,
-            Err(_) => true,
-        };
+        let old_school = check_old_skool();
         if !old_school {
             write!(dst, "{}: ", topic)?;
         }
index feac8aadc1e05b39fa9f3e9442e584d553cb3ce0..4ade537c8ce04778e8b3cb0259f6705ba43ed22d 100644 (file)
@@ -683,3 +683,20 @@ pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where
         None => diag.bug(&msg()),
     }
 }
+
+/// True if we should use the old-skool error format style. This is
+/// the default setting until the new errors are deemed stable enough
+/// for general use.
+///
+/// FIXME(#33240)
+#[cfg(not(test))]
+fn check_old_skool() -> bool {
+    use std::env;
+    env::var("RUST_NEW_ERROR_FORMAT").is_err()
+}
+
+/// For unit tests, use the new format.
+#[cfg(test)]
+fn check_old_skool() -> bool {
+    false
+}
index 18a64cc399c42c7a6a2f03056d173fe0129e8d06..6c90bfd08186b19f4a80ae5464df3543b69aad6a 100644 (file)
@@ -11,6 +11,7 @@
 // Code for annotating snippets.
 
 use codemap::{CharPos, CodeMap, FileMap, LineInfo, Span};
+use errors::check_old_skool;
 use std::cmp;
 use std::rc::Rc;
 use std::mem;
@@ -432,10 +433,8 @@ fn ensure_source_line(&mut self, line_index: usize) -> usize {
     }
 
     fn render_file_lines(&self, codemap: &Rc<CodeMap>) -> Vec<RenderedLine> {
-        let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-            Ok(_) => false,
-            Err(_) => true,
-        };
+        let old_school = check_old_skool();
+
         // As a first step, we elide any instance of more than one
         // continuous unannotated line.
 
@@ -525,10 +524,7 @@ fn render_file_lines(&self, codemap: &Rc<CodeMap>) -> Vec<RenderedLine> {
     }
 
     fn render_line(&self, line: &Line) -> Vec<RenderedLine> {
-        let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-            Ok(_) => false,
-            Err(_) => true,
-        };
+        let old_school = check_old_skool();
         let source_string = self.file.get_line(line.line_index)
                                      .unwrap_or("");
         let source_kind = RenderedLineKind::SourceText {
@@ -709,10 +705,7 @@ fn render_line(&self, line: &Line) -> Vec<RenderedLine> {
 }
 
 fn prepend_prefixes(rendered_lines: &mut [RenderedLine]) {
-    let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
-        Ok(_) => false,
-        Err(_) => true,
-    };
+    let old_school = check_old_skool();
     if old_school {
         return;
     }
index 56c891daa12fb120e3ca5bd3bcb9cb1b7601e9a4..569d11199190c42ea28db9ac891b8bacbb5b65ef 100644 (file)
@@ -105,7 +105,7 @@ fn foo() {
 
     println!("text=\n{}", text);
     assert_eq!(&text[..], &r#"
->>>> foo.rs
+ ::: foo.rs
 3 |>     vec.push(vec.pop().unwrap());
   |>     ---      ---                - previous borrow ends here
   |>     |        |
@@ -180,7 +180,7 @@ fn bar() {
     |>     |        |
     |>     |        b
     |>     a
->>>>>> bar.rs
+   ::: bar.rs
 17  |>     vec.push();
     |>     ---       - f
     |>     |
@@ -224,7 +224,7 @@ fn foo() {
 
     println!("text=\n{}", text);
     assert_eq!(&text[..], &r#"
->>>>>> foo.rs
+   ::: foo.rs
 3   |>     let name = find_id(&data, 22).unwrap();
     |>                         ---- immutable borrow begins here
 ...
@@ -263,7 +263,7 @@ fn foo() {
 
     println!("text=r#\"\n{}\".trim_left()", text);
     assert_eq!(&text[..], &r#"
->>>> foo.rs
+ ::: foo.rs
 3 |>     vec.push(vec.pop().unwrap());
   |>     --------           ------ D
   |>     ||
@@ -299,7 +299,7 @@ fn foo() {
 
     println!("text=r#\"\n{}\".trim_left()", text);
     assert_eq!(&text[..], &r#"
->>>> foo.rs
+ ::: foo.rs
 3 |>     vec.push(vec.pop().unwrap());
   |>     ---      ---                - previous borrow ends here
   |>     |        |
@@ -337,7 +337,7 @@ fn foo() {
     let text: String = make_string(&lines);
     println!("text=r#\"\n{}\".trim_left()", text);
     assert_eq!(&text[..], &r#"
->>>>>> foo.rs
+   ::: foo.rs
 4   |>     let mut vec2 = vec;
     |>                    --- `vec` moved here because it has type `collections::vec::Vec<i32>`
 ...
@@ -373,7 +373,7 @@ fn foo() {
     let text: String = make_string(&lines);
     println!("text=&r#\"\n{}\n\"#[1..]", text);
     assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
 3 |>     let mut vec = vec![0, 1, 2];
   |>             ---   ---
 4 |>     let mut vec2 = vec;
@@ -404,7 +404,7 @@ fn foo(x: u32) {
     let text: String = make_string(&lines);
     println!("r#\"\n{}\"", text);
     assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
 3 |>     fn foo(x: u32) {
   |>     -
 "#[1..]);
@@ -433,7 +433,7 @@ fn foo(x: u32) {
     let text: String = make_string(&lines);
     println!("r#\"\n{}\"", text);
     assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
 2 |>     fn foo(x: u32) {
   |>     --------------
   |>     |      |
@@ -467,7 +467,7 @@ fn foo(x: u32) {
     let text: String = make_string(&lines);
     println!("r#\"\n{}\"", text);
     assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
 2 |>     fn foo(x: u32) {
   |>     --------------
   |>     |      |
@@ -512,7 +512,7 @@ fn foo() {
     let text: String = make_string(&lines);
     println!("r#\"\n{}\"", text);
     assert_eq!(text, &r#"
->>>> foo.rs
+ ::: foo.rs
 3 |>        let closure = || {
   |>                      - foo
 4 |>            inner