mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-11 06:24:24 +00:00
update unit tests
This commit is contained in:
parent
2ba5fac1a4
commit
95576b8ec4
@ -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)?;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user