Skip to content

Commit 9bce81c

Browse files
committed
update unit tests
1 parent a7828be commit 9bce81c

File tree

4 files changed

+38
-39
lines changed

4 files changed

+38
-39
lines changed

src/libsyntax/errors/emitter.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use self::Destination::*;
1313
use codemap::{self, COMMAND_LINE_SP, DUMMY_SP, Pos, Span, MultiSpan};
1414
use diagnostics;
1515

16+
use errors::check_old_skool;
1617
use errors::{Level, RenderSpan, CodeSuggestion, DiagnosticBuilder};
1718
use errors::RenderSpan::*;
1819
use errors::Level::*;
@@ -59,10 +60,7 @@ impl<T: CoreEmitter> Emitter for T {
5960
}
6061

6162
fn emit_struct(&mut self, db: &DiagnosticBuilder) {
62-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
63-
Ok(_) => false,
64-
Err(_) => true,
65-
};
63+
let old_school = check_old_skool();
6664
let db_span = FullSpan(db.span.clone());
6765
self.emit_message(&FullSpan(db.span.clone()),
6866
&db.message,
@@ -198,10 +196,7 @@ impl EmitterWriter {
198196
registry: Option<diagnostics::registry::Registry>,
199197
code_map: Rc<codemap::CodeMap>)
200198
-> EmitterWriter {
201-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
202-
Ok(_) => false,
203-
Err(_) => true,
204-
};
199+
let old_school = check_old_skool();
205200
if color_config.use_color() {
206201
let dst = Destination::from_stderr();
207202
EmitterWriter { dst: dst,
@@ -222,10 +217,7 @@ impl EmitterWriter {
222217
registry: Option<diagnostics::registry::Registry>,
223218
code_map: Rc<codemap::CodeMap>)
224219
-> EmitterWriter {
225-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
226-
Ok(_) => false,
227-
Err(_) => true,
228-
};
220+
let old_school = check_old_skool();
229221
EmitterWriter { dst: Raw(dst),
230222
registry: registry,
231223
cm: code_map,
@@ -454,10 +446,7 @@ fn print_diagnostic(dst: &mut Destination,
454446
code: Option<&str>)
455447
-> io::Result<()> {
456448
if !topic.is_empty() {
457-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
458-
Ok(_) => false,
459-
Err(_) => true,
460-
};
449+
let old_school = check_old_skool();
461450
if !old_school {
462451
write!(dst, "{}: ", topic)?;
463452
}

src/libsyntax/errors/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,20 @@ pub fn expect<T, M>(diag: &Handler, opt: Option<T>, msg: M) -> T where
683683
None => diag.bug(&msg()),
684684
}
685685
}
686+
687+
/// True if we should use the old-skool error format style. This is
688+
/// the default setting until the new errors are deemed stable enough
689+
/// for general use.
690+
///
691+
/// FIXME(#33240)
692+
#[cfg(not(test))]
693+
fn check_old_skool() -> bool {
694+
use std::env;
695+
env::var("RUST_NEW_ERROR_FORMAT").is_err()
696+
}
697+
698+
/// For unit tests, use the new format.
699+
#[cfg(test)]
700+
fn check_old_skool() -> bool {
701+
false
702+
}

src/libsyntax/errors/snippet/mod.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Code for annotating snippets.
1212

1313
use codemap::{CharPos, CodeMap, FileMap, LineInfo, Span};
14+
use errors::check_old_skool;
1415
use std::cmp;
1516
use std::rc::Rc;
1617
use std::mem;
@@ -432,10 +433,8 @@ impl FileInfo {
432433
}
433434

434435
fn render_file_lines(&self, codemap: &Rc<CodeMap>) -> Vec<RenderedLine> {
435-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
436-
Ok(_) => false,
437-
Err(_) => true,
438-
};
436+
let old_school = check_old_skool();
437+
439438
// As a first step, we elide any instance of more than one
440439
// continuous unannotated line.
441440

@@ -525,10 +524,7 @@ impl FileInfo {
525524
}
526525

527526
fn render_line(&self, line: &Line) -> Vec<RenderedLine> {
528-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
529-
Ok(_) => false,
530-
Err(_) => true,
531-
};
527+
let old_school = check_old_skool();
532528
let source_string = self.file.get_line(line.line_index)
533529
.unwrap_or("");
534530
let source_kind = RenderedLineKind::SourceText {
@@ -709,10 +705,7 @@ impl FileInfo {
709705
}
710706

711707
fn prepend_prefixes(rendered_lines: &mut [RenderedLine]) {
712-
let old_school = match ::std::env::var("RUST_NEW_ERROR_FORMAT") {
713-
Ok(_) => false,
714-
Err(_) => true,
715-
};
708+
let old_school = check_old_skool();
716709
if old_school {
717710
return;
718711
}

src/libsyntax/errors/snippet/test.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn foo() {
105105

106106
println!("text=\n{}", text);
107107
assert_eq!(&text[..], &r#"
108-
>>>> foo.rs
108+
::: foo.rs
109109
3 |> vec.push(vec.pop().unwrap());
110110
|> --- --- - previous borrow ends here
111111
|> | |
@@ -180,7 +180,7 @@ fn bar() {
180180
|> | |
181181
|> | b
182182
|> a
183-
>>>>>> bar.rs
183+
::: bar.rs
184184
17 |> vec.push();
185185
|> --- - f
186186
|> |
@@ -224,7 +224,7 @@ fn foo() {
224224

225225
println!("text=\n{}", text);
226226
assert_eq!(&text[..], &r#"
227-
>>>>>> foo.rs
227+
::: foo.rs
228228
3 |> let name = find_id(&data, 22).unwrap();
229229
|> ---- immutable borrow begins here
230230
...
@@ -263,7 +263,7 @@ fn foo() {
263263

264264
println!("text=r#\"\n{}\".trim_left()", text);
265265
assert_eq!(&text[..], &r#"
266-
>>>> foo.rs
266+
::: foo.rs
267267
3 |> vec.push(vec.pop().unwrap());
268268
|> -------- ------ D
269269
|> ||
@@ -299,7 +299,7 @@ fn foo() {
299299

300300
println!("text=r#\"\n{}\".trim_left()", text);
301301
assert_eq!(&text[..], &r#"
302-
>>>> foo.rs
302+
::: foo.rs
303303
3 |> vec.push(vec.pop().unwrap());
304304
|> --- --- - previous borrow ends here
305305
|> | |
@@ -337,7 +337,7 @@ fn foo() {
337337
let text: String = make_string(&lines);
338338
println!("text=r#\"\n{}\".trim_left()", text);
339339
assert_eq!(&text[..], &r#"
340-
>>>>>> foo.rs
340+
::: foo.rs
341341
4 |> let mut vec2 = vec;
342342
|> --- `vec` moved here because it has type `collections::vec::Vec<i32>`
343343
...
@@ -373,7 +373,7 @@ fn foo() {
373373
let text: String = make_string(&lines);
374374
println!("text=&r#\"\n{}\n\"#[1..]", text);
375375
assert_eq!(text, &r#"
376-
>>>> foo.rs
376+
::: foo.rs
377377
3 |> let mut vec = vec![0, 1, 2];
378378
|> --- ---
379379
4 |> let mut vec2 = vec;
@@ -404,7 +404,7 @@ impl SomeTrait for () {
404404
let text: String = make_string(&lines);
405405
println!("r#\"\n{}\"", text);
406406
assert_eq!(text, &r#"
407-
>>>> foo.rs
407+
::: foo.rs
408408
3 |> fn foo(x: u32) {
409409
|> -
410410
"#[1..]);
@@ -433,7 +433,7 @@ fn span_overlap_label() {
433433
let text: String = make_string(&lines);
434434
println!("r#\"\n{}\"", text);
435435
assert_eq!(text, &r#"
436-
>>>> foo.rs
436+
::: foo.rs
437437
2 |> fn foo(x: u32) {
438438
|> --------------
439439
|> | |
@@ -467,7 +467,7 @@ fn span_overlap_label2() {
467467
let text: String = make_string(&lines);
468468
println!("r#\"\n{}\"", text);
469469
assert_eq!(text, &r#"
470-
>>>> foo.rs
470+
::: foo.rs
471471
2 |> fn foo(x: u32) {
472472
|> --------------
473473
|> | |
@@ -512,7 +512,7 @@ fn span_overlap_label3() {
512512
let text: String = make_string(&lines);
513513
println!("r#\"\n{}\"", text);
514514
assert_eq!(text, &r#"
515-
>>>> foo.rs
515+
::: foo.rs
516516
3 |> let closure = || {
517517
|> - foo
518518
4 |> inner

0 commit comments

Comments
 (0)