diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-02-23 03:18:53 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2018-02-26 20:24:00 +0300 |
| commit | cdbd8c2f2aa69c4b8fe6f004449440e87c4ab87e (patch) | |
| tree | 3cb1d034cf3a10a3ff41ef80013322ee7358dbf5 /src/librustc_errors | |
| parent | bedbad61195d2eae69b43eca49c6d3e2aee8f208 (diff) | |
Support flag `-Z ui-testing` for tweaking diagnostic output for UI tests
Diffstat (limited to 'src/librustc_errors')
| -rw-r--r-- | src/librustc_errors/emitter.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 86e77d404ff..31c1ddca794 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -25,6 +25,8 @@ use std::collections::{HashMap, HashSet}; use std::cmp::min; use unicode_width; +const ANONYMIZED_LINE_NUM: &str = "LL"; + /// Emitter trait for emitting errors. pub trait Emitter { /// Emit a structured diagnostic. @@ -108,6 +110,7 @@ pub struct EmitterWriter { short_message: bool, teach: bool, error_codes: HashSet<String>, + ui_testing: bool, } struct FileWithAnnotatedLines { @@ -157,6 +160,7 @@ impl EmitterWriter { short_message, teach, error_codes: HashSet::new(), + ui_testing: false, } } else { EmitterWriter { @@ -165,6 +169,7 @@ impl EmitterWriter { short_message, teach, error_codes: HashSet::new(), + ui_testing: false, } } } @@ -180,9 +185,14 @@ impl EmitterWriter { short_message, teach, error_codes: HashSet::new(), + ui_testing: false, } } + pub fn ui_testing(self, ui_testing: bool) -> Self { + Self { ui_testing, ..self } + } + fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> { fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>, file: Rc<FileMap>, @@ -334,9 +344,14 @@ impl EmitterWriter { // First create the source line we will highlight. buffer.puts(line_offset, code_offset, &source_string, Style::Quotation); + let line_index = if self.ui_testing { + ANONYMIZED_LINE_NUM.to_string() + } else { + line.line_index.to_string() + }; buffer.puts(line_offset, 0, - &(line.line_index.to_string()), + &line_index, Style::LineNumber); draw_col_separator(buffer, line_offset, width_offset - 2); @@ -1288,8 +1303,11 @@ impl EmitterWriter { span: &MultiSpan, children: &Vec<SubDiagnostic>, suggestions: &[CodeSuggestion]) { - let max_line_num = self.get_max_line_num(span, children); - let max_line_num_len = max_line_num.to_string().len(); + let max_line_num_len = if self.ui_testing { + ANONYMIZED_LINE_NUM.len() + } else { + self.get_max_line_num(span, children).to_string().len() + }; match self.emit_message_default(span, message, |
