diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2016-04-29 21:13:42 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2016-05-02 11:49:26 -0400 |
| commit | 95576b8ec40538fc311029dd838d2a22c0e9af7f (patch) | |
| tree | f020be7921415e50f681a9232d48f16c4fdb2e74 /src | |
| parent | 2ba5fac1a460de9936b85f9459668b0992f21f06 (diff) | |
| download | rust-95576b8ec40538fc311029dd838d2a22c0e9af7f.tar.gz rust-95576b8ec40538fc311029dd838d2a22c0e9af7f.zip | |
update unit tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/errors/emitter.rs | 21 | ||||
| -rw-r--r-- | src/libsyntax/errors/mod.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/errors/snippet/mod.rs | 17 | ||||
| -rw-r--r-- | src/libsyntax/errors/snippet/test.rs | 22 |
4 files changed, 38 insertions, 39 deletions
diff --git a/src/libsyntax/errors/emitter.rs b/src/libsyntax/errors/emitter.rs index 769f6b05397..486e2ace087 100644 --- a/src/libsyntax/errors/emitter.rs +++ b/src/libsyntax/errors/emitter.rs @@ -13,6 +13,7 @@ use self::Destination::*; 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 @@ impl<T: CoreEmitter> Emitter for T { } 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 @@ impl EmitterWriter { 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 @@ impl EmitterWriter { 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)?; } diff --git a/src/libsyntax/errors/mod.rs b/src/libsyntax/errors/mod.rs index feac8aadc1e..4ade537c8ce 100644 --- a/src/libsyntax/errors/mod.rs +++ b/src/libsyntax/errors/mod.rs @@ -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 +} diff --git a/src/libsyntax/errors/snippet/mod.rs b/src/libsyntax/errors/snippet/mod.rs index 18a64cc399c..6c90bfd0818 100644 --- a/src/libsyntax/errors/snippet/mod.rs +++ b/src/libsyntax/errors/snippet/mod.rs @@ -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 @@ impl FileInfo { } 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 @@ impl FileInfo { } 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 @@ impl FileInfo { } 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; } diff --git a/src/libsyntax/errors/snippet/test.rs b/src/libsyntax/errors/snippet/test.rs index 56c891daa12..569d1119919 100644 --- a/src/libsyntax/errors/snippet/test.rs +++ b/src/libsyntax/errors/snippet/test.rs @@ -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 @@ impl SomeTrait for () { 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 span_overlap_label() { 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 span_overlap_label2() { 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 span_overlap_label3() { let text: String = make_string(&lines); println!("r#\"\n{}\"", text); assert_eq!(text, &r#" ->>>> foo.rs + ::: foo.rs 3 |> let closure = || { |> - foo 4 |> inner |
