1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 pub use self::Level::*;
12 pub use self::RenderSpan::*;
13 pub use self::ColorConfig::*;
14 use self::Destination::*;
16 use codemap::{self, COMMAND_LINE_SP, COMMAND_LINE_EXPN, Pos, Span};
19 use std::cell::{RefCell, Cell};
20 use std::{cmp, error, fmt};
21 use std::io::prelude::*;
23 use term::{self, WriterWrapper};
26 /// maximum number of lines we will print for each error; arbitrary.
27 const MAX_LINES: usize = 6;
31 /// A FullSpan renders with both with an initial line for the
32 /// message, prefixed by file:linenum, followed by a summary of
33 /// the source code covered by the span.
36 /// Similar to a FullSpan, but the cited position is the end of
37 /// the span, instead of the start. Used, at least, for telling
38 /// compiletest/runtest to look at the last line of the span
39 /// (since `end_highlight_lines` displays an arrow to the end
43 /// A suggestion renders with both with an initial line for the
44 /// message, prefixed by file:linenum, followed by a summary
45 /// of hypothetical source code, where the `String` is spliced
46 /// into the lines in place of the code covered by the span.
47 Suggestion(Span, String),
49 /// A FileLine renders with just a line for the message prefixed
55 fn span(&self) -> Span {
66 #[derive(Clone, Copy)]
67 pub enum ColorConfig {
74 fn emit(&mut self, cmsp: Option<(&codemap::CodeMap, Span)>,
75 msg: &str, code: Option<&str>, lvl: Level);
76 fn custom_emit(&mut self, cm: &codemap::CodeMap,
77 sp: RenderSpan, msg: &str, lvl: Level);
80 /// Used as a return value to signify a fatal error occurred. (It is also
81 /// used as the argument to panic at the moment, but that will eventually
83 #[derive(Copy, Clone, Debug)]
85 pub struct FatalError;
87 impl fmt::Display for FatalError {
88 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
89 write!(f, "parser fatal error")
93 impl error::Error for FatalError {
94 fn description(&self) -> &str {
95 "The parser has encountered a fatal error"
99 /// Signifies that the compiler died with an explicit call to `.bug`
100 /// or `.span_bug` rather than a failed assertion, etc.
101 #[derive(Copy, Clone, Debug)]
102 pub struct ExplicitBug;
104 impl fmt::Display for ExplicitBug {
105 fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
106 write!(f, "parser internal bug")
110 impl error::Error for ExplicitBug {
111 fn description(&self) -> &str {
112 "The parser has encountered an internal bug"
116 /// A span-handler is like a handler but also
117 /// accepts span information for source-location
119 pub struct SpanHandler {
120 pub handler: Handler,
121 pub cm: codemap::CodeMap,
125 pub fn new(handler: Handler, cm: codemap::CodeMap) -> SpanHandler {
131 pub fn span_fatal(&self, sp: Span, msg: &str) -> FatalError {
132 self.handler.emit(Some((&self.cm, sp)), msg, Fatal);
135 pub fn span_fatal_with_code(&self, sp: Span, msg: &str, code: &str) -> FatalError {
136 self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Fatal);
139 pub fn span_err(&self, sp: Span, msg: &str) {
140 self.handler.emit(Some((&self.cm, sp)), msg, Error);
141 self.handler.bump_err_count();
143 pub fn span_err_with_code(&self, sp: Span, msg: &str, code: &str) {
144 self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Error);
145 self.handler.bump_err_count();
147 pub fn span_warn(&self, sp: Span, msg: &str) {
148 self.handler.emit(Some((&self.cm, sp)), msg, Warning);
150 pub fn span_warn_with_code(&self, sp: Span, msg: &str, code: &str) {
151 self.handler.emit_with_code(Some((&self.cm, sp)), msg, code, Warning);
153 pub fn span_note(&self, sp: Span, msg: &str) {
154 self.handler.emit(Some((&self.cm, sp)), msg, Note);
156 pub fn span_end_note(&self, sp: Span, msg: &str) {
157 self.handler.custom_emit(&self.cm, EndSpan(sp), msg, Note);
159 pub fn span_help(&self, sp: Span, msg: &str) {
160 self.handler.emit(Some((&self.cm, sp)), msg, Help);
162 /// Prints out a message with a suggested edit of the code.
164 /// See `diagnostic::RenderSpan::Suggestion` for more information.
165 pub fn span_suggestion(&self, sp: Span, msg: &str, suggestion: String) {
166 self.handler.custom_emit(&self.cm, Suggestion(sp, suggestion), msg, Help);
168 pub fn fileline_note(&self, sp: Span, msg: &str) {
169 self.handler.custom_emit(&self.cm, FileLine(sp), msg, Note);
171 pub fn fileline_help(&self, sp: Span, msg: &str) {
172 self.handler.custom_emit(&self.cm, FileLine(sp), msg, Help);
174 pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
175 self.handler.emit(Some((&self.cm, sp)), msg, Bug);
178 pub fn span_unimpl(&self, sp: Span, msg: &str) -> ! {
179 self.span_bug(sp, &format!("unimplemented {}", msg));
181 pub fn handler<'a>(&'a self) -> &'a Handler {
186 /// A handler deals with errors; certain errors
187 /// (fatal, bug, unimpl) may cause immediate exit,
188 /// others log errors for later reporting.
190 err_count: Cell<usize>,
191 emit: RefCell<Box<Emitter + Send>>,
192 pub can_emit_warnings: bool
196 pub fn new(color_config: ColorConfig,
197 registry: Option<diagnostics::registry::Registry>,
198 can_emit_warnings: bool) -> Handler {
199 let emitter = Box::new(EmitterWriter::stderr(color_config, registry));
200 Handler::with_emitter(can_emit_warnings, emitter)
202 pub fn with_emitter(can_emit_warnings: bool, e: Box<Emitter + Send>) -> Handler {
204 err_count: Cell::new(0),
205 emit: RefCell::new(e),
206 can_emit_warnings: can_emit_warnings
209 pub fn fatal(&self, msg: &str) -> ! {
210 self.emit.borrow_mut().emit(None, msg, None, Fatal);
213 pub fn err(&self, msg: &str) {
214 self.emit.borrow_mut().emit(None, msg, None, Error);
215 self.bump_err_count();
217 pub fn bump_err_count(&self) {
218 self.err_count.set(self.err_count.get() + 1);
220 pub fn err_count(&self) -> usize {
223 pub fn has_errors(&self) -> bool {
224 self.err_count.get() > 0
226 pub fn abort_if_errors(&self) {
228 match self.err_count.get() {
230 1 => s = "aborting due to previous error".to_string(),
232 s = format!("aborting due to {} previous errors",
233 self.err_count.get());
238 pub fn warn(&self, msg: &str) {
239 self.emit.borrow_mut().emit(None, msg, None, Warning);
241 pub fn note(&self, msg: &str) {
242 self.emit.borrow_mut().emit(None, msg, None, Note);
244 pub fn help(&self, msg: &str) {
245 self.emit.borrow_mut().emit(None, msg, None, Help);
247 pub fn bug(&self, msg: &str) -> ! {
248 self.emit.borrow_mut().emit(None, msg, None, Bug);
251 pub fn unimpl(&self, msg: &str) -> ! {
252 self.bug(&format!("unimplemented {}", msg));
255 cmsp: Option<(&codemap::CodeMap, Span)>,
258 if lvl == Warning && !self.can_emit_warnings { return }
259 self.emit.borrow_mut().emit(cmsp, msg, None, lvl);
261 pub fn emit_with_code(&self,
262 cmsp: Option<(&codemap::CodeMap, Span)>,
266 if lvl == Warning && !self.can_emit_warnings { return }
267 self.emit.borrow_mut().emit(cmsp, msg, Some(code), lvl);
269 pub fn custom_emit(&self, cm: &codemap::CodeMap,
270 sp: RenderSpan, msg: &str, lvl: Level) {
271 if lvl == Warning && !self.can_emit_warnings { return }
272 self.emit.borrow_mut().custom_emit(cm, sp, msg, lvl);
276 #[derive(Copy, PartialEq, Clone, Debug)]
286 impl fmt::Display for Level {
287 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
288 use std::fmt::Display;
291 Bug => "error: internal compiler error".fmt(f),
292 Fatal | Error => "error".fmt(f),
293 Warning => "warning".fmt(f),
294 Note => "note".fmt(f),
295 Help => "help".fmt(f),
301 fn color(self) -> term::color::Color {
303 Bug | Fatal | Error => term::color::BRIGHT_RED,
304 Warning => term::color::BRIGHT_YELLOW,
305 Note => term::color::BRIGHT_GREEN,
306 Help => term::color::BRIGHT_CYAN,
311 pub struct EmitterWriter {
313 registry: Option<diagnostics::registry::Registry>
317 Terminal(Box<term::Terminal<WriterWrapper> + Send>),
318 Raw(Box<Write + Send>),
322 pub fn stderr(color_config: ColorConfig,
323 registry: Option<diagnostics::registry::Registry>) -> EmitterWriter {
324 let stderr = io::stderr();
326 let use_color = match color_config {
329 Auto => stderr_isatty(),
333 let dst = match term::stderr() {
334 Some(t) => Terminal(t),
335 None => Raw(Box::new(stderr)),
337 EmitterWriter { dst: dst, registry: registry }
339 EmitterWriter { dst: Raw(Box::new(stderr)), registry: registry }
343 pub fn new(dst: Box<Write + Send>,
344 registry: Option<diagnostics::registry::Registry>) -> EmitterWriter {
345 EmitterWriter { dst: Raw(dst), registry: registry }
348 fn print_maybe_styled(&mut self,
350 color: term::attr::Attr) -> io::Result<()> {
352 Terminal(ref mut t) => {
354 // If `msg` ends in a newline, we need to reset the color before
355 // the newline. We're making the assumption that we end up writing
356 // to a `LineBufferedWriter`, which means that emitting the reset
357 // after the newline ends up buffering the reset until we print
358 // another line or exit. Buffering the reset is a problem if we're
359 // sharing the terminal with any other programs (e.g. other rustc
360 // instances via `make -jN`).
362 // Note that if `msg` contains any internal newlines, this will
363 // result in the `LineBufferedWriter` flushing twice instead of
364 // once, which still leaves the opportunity for interleaved output
365 // to be miscolored. We assume this is rare enough that we don't
366 // have to worry about it.
367 if msg.ends_with("\n") {
368 try!(t.write_all(msg[..msg.len()-1].as_bytes()));
370 try!(t.write_all(b"\n"));
372 try!(t.write_all(msg.as_bytes()));
377 Raw(ref mut w) => w.write_all(msg.as_bytes()),
381 fn print_diagnostic(&mut self, topic: &str, lvl: Level,
382 msg: &str, code: Option<&str>) -> io::Result<()> {
383 if !topic.is_empty() {
384 try!(write!(&mut self.dst, "{} ", topic));
387 try!(self.print_maybe_styled(&format!("{}: ", lvl.to_string()),
388 term::attr::ForegroundColor(lvl.color())));
389 try!(self.print_maybe_styled(&format!("{}", msg),
394 let style = term::attr::ForegroundColor(term::color::BRIGHT_MAGENTA);
395 try!(self.print_maybe_styled(&format!(" [{}]", code.clone()), style));
399 try!(write!(&mut self.dst, "\n"));
403 fn emit_(&mut self, cm: &codemap::CodeMap, rsp: RenderSpan,
404 msg: &str, code: Option<&str>, lvl: Level) -> io::Result<()> {
407 // We cannot check equality directly with COMMAND_LINE_SP
408 // since PartialEq is manually implemented to ignore the ExpnId
409 let ss = if sp.expn_id == COMMAND_LINE_EXPN {
410 "<command line option>".to_string()
411 } else if let EndSpan(_) = rsp {
412 let span_end = Span { lo: sp.hi, hi: sp.hi, expn_id: sp.expn_id};
413 cm.span_to_string(span_end)
415 cm.span_to_string(sp)
418 try!(self.print_diagnostic(&ss[..], lvl, msg, code));
422 try!(self.highlight_lines(cm, sp, lvl, cm.span_to_lines(sp)));
423 try!(self.print_macro_backtrace(cm, sp));
426 try!(self.end_highlight_lines(cm, sp, lvl, cm.span_to_lines(sp)));
427 try!(self.print_macro_backtrace(cm, sp));
429 Suggestion(_, ref suggestion) => {
430 try!(self.highlight_suggestion(cm, sp, suggestion));
431 try!(self.print_macro_backtrace(cm, sp));
434 // no source text in this case!
440 match self.registry.as_ref().and_then(|registry| registry.find_description(code)) {
442 try!(self.print_diagnostic(&ss[..], Help,
443 &format!("run `rustc --explain {}` to see a \
444 detailed explanation", code), None));
453 fn highlight_suggestion(&mut self,
454 cm: &codemap::CodeMap,
459 let lines = cm.span_to_lines(sp).unwrap();
460 assert!(!lines.lines.is_empty());
462 // To build up the result, we want to take the snippet from the first
463 // line that precedes the span, prepend that with the suggestion, and
464 // then append the snippet from the last line that trails the span.
465 let fm = &lines.file;
467 let first_line = &lines.lines[0];
468 let prefix = fm.get_line(first_line.line_index)
469 .map(|l| &l[..first_line.start_col.0])
472 let last_line = lines.lines.last().unwrap();
473 let suffix = fm.get_line(last_line.line_index)
474 .map(|l| &l[last_line.end_col.0..])
477 let complete = format!("{}{}{}", prefix, suggestion, suffix);
479 // print the suggestion without any line numbers, but leave
480 // space for them. This helps with lining up with previous
481 // snippets from the actual error being reported.
482 let fm = &*lines.file;
483 let mut lines = complete.lines();
484 for (line, line_index) in lines.by_ref().take(MAX_LINES).zip(first_line.line_index..) {
485 let elided_line_num = format!("{}", line_index+1);
486 try!(write!(&mut self.dst, "{0}:{1:2$} {3}\n",
487 fm.name, "", elided_line_num.len(), line));
490 // if we elided some lines, add an ellipsis
491 if lines.next().is_some() {
492 let elided_line_num = format!("{}", first_line.line_index + MAX_LINES + 1);
493 try!(write!(&mut self.dst, "{0:1$} {0:2$} ...\n",
494 "", fm.name.len(), elided_line_num.len()));
500 fn highlight_lines(&mut self,
501 cm: &codemap::CodeMap,
504 lines: codemap::FileLinesResult)
507 let lines = match lines {
510 try!(write!(&mut self.dst, "(internal compiler error: unprintable span)\n"));
515 let fm = &*lines.file;
517 let line_strings: Option<Vec<&str>> =
519 .map(|info| fm.get_line(info.line_index))
522 let line_strings = match line_strings {
523 None => { return Ok(()); }
524 Some(line_strings) => line_strings
527 // Display only the first MAX_LINES lines.
528 let all_lines = lines.lines.len();
529 let display_lines = cmp::min(all_lines, MAX_LINES);
530 let display_line_infos = &lines.lines[..display_lines];
531 let display_line_strings = &line_strings[..display_lines];
533 // Calculate the widest number to format evenly and fix #11715
534 assert!(display_line_infos.len() > 0);
535 let mut max_line_num = display_line_infos[display_line_infos.len() - 1].line_index + 1;
537 while max_line_num > 0 {
542 // Print the offending lines
543 for (line_info, line) in display_line_infos.iter().zip(display_line_strings) {
544 try!(write!(&mut self.dst, "{}:{:>width$} {}\n",
546 line_info.line_index + 1,
551 // If we elided something, put an ellipsis.
552 if display_lines < all_lines {
553 let last_line_index = display_line_infos.last().unwrap().line_index;
554 let s = format!("{}:{} ", fm.name, last_line_index + 1);
555 try!(write!(&mut self.dst, "{0:1$}...\n", "", s.len()));
559 // If there's one line at fault we can easily point to the problem
560 if lines.lines.len() == 1 {
561 let lo = cm.lookup_char_pos(sp.lo);
563 let mut num = (lines.lines[0].line_index + 1) / 10;
565 // how many digits must be indent past?
566 while num > 0 { num /= 10; digits += 1; }
568 let mut s = String::new();
569 // Skip is the number of characters we need to skip because they are
570 // part of the 'filename:line ' part of the previous line.
571 let skip = fm.name.chars().count() + digits + 3;
575 if let Some(orig) = fm.get_line(lines.lines[0].line_index) {
578 let mut iter = orig.chars().enumerate();
579 for (pos, ch) in iter.by_ref() {
581 if pos >= lo.col.to_usize() { break; }
582 // Whenever a tab occurs on the previous line, we insert one on
583 // the error-point-squiggly-line as well (instead of a space).
584 // That way the squiggly line will usually appear in the correct
598 try!(write!(&mut self.dst, "{}", s));
599 let mut s = String::from("^");
600 let count = match lastc {
601 // Most terminals have a tab stop every eight columns by default
606 s.extend(::std::iter::repeat('~').take(count));
608 let hi = cm.lookup_char_pos(sp.hi);
609 if hi.col != lo.col {
610 for (pos, ch) in iter {
611 if pos >= hi.col.to_usize() { break; }
612 let count = match ch {
617 s.extend(::std::iter::repeat('~').take(count));
622 // One extra squiggly is replaced by a "^"
626 try!(self.print_maybe_styled(&format!("{}\n", s),
627 term::attr::ForegroundColor(lvl.color())));
633 /// Here are the differences between this and the normal `highlight_lines`:
634 /// `end_highlight_lines` will always put arrow on the last byte of the
635 /// span (instead of the first byte). Also, when the span is too long (more
636 /// than 6 lines), `end_highlight_lines` will print the first line, then
637 /// dot dot dot, then last line, whereas `highlight_lines` prints the first
640 fn end_highlight_lines(&mut self,
641 cm: &codemap::CodeMap,
644 lines: codemap::FileLinesResult)
646 let lines = match lines {
649 try!(write!(&mut self.dst, "(internal compiler error: unprintable span)\n"));
654 let fm = &*lines.file;
656 let lines = &lines.lines[..];
657 if lines.len() > MAX_LINES {
658 if let Some(line) = fm.get_line(lines[0].line_index) {
659 try!(write!(&mut self.dst, "{}:{} {}\n", fm.name,
660 lines[0].line_index + 1, line));
662 try!(write!(&mut self.dst, "...\n"));
663 let last_line_index = lines[lines.len() - 1].line_index;
664 if let Some(last_line) = fm.get_line(last_line_index) {
665 try!(write!(&mut self.dst, "{}:{} {}\n", fm.name,
666 last_line_index + 1, last_line));
669 for line_info in lines {
670 if let Some(line) = fm.get_line(line_info.line_index) {
671 try!(write!(&mut self.dst, "{}:{} {}\n", fm.name,
672 line_info.line_index + 1, line));
676 let last_line_start = format!("{}:{} ", fm.name, lines[lines.len()-1].line_index + 1);
677 let hi = cm.lookup_char_pos(sp.hi);
678 let skip = last_line_start.chars().count();
679 let mut s = String::new();
683 if let Some(orig) = fm.get_line(lines[0].line_index) {
684 let iter = orig.chars().enumerate();
685 for (pos, ch) in iter {
686 // Span seems to use half-opened interval, so subtract 1
687 if pos >= hi.col.to_usize() - 1 { break; }
688 // Whenever a tab occurs on the previous line, we insert one on
689 // the error-point-squiggly-line as well (instead of a space).
690 // That way the squiggly line will usually appear in the correct
693 '\t' => s.push('\t'),
700 self.print_maybe_styled(&s[..],
701 term::attr::ForegroundColor(lvl.color()))
704 fn print_macro_backtrace(&mut self,
705 cm: &codemap::CodeMap,
708 let cs = try!(cm.with_expn_info(sp.expn_id, |expn_info| -> io::Result<_> {
711 let ss = ei.callee.span.map_or(String::new(),
712 |span| cm.span_to_string(span));
713 let (pre, post) = match ei.callee.format {
714 codemap::MacroAttribute => ("#[", "]"),
715 codemap::MacroBang => ("", "!"),
716 codemap::CompilerExpansion => ("", ""),
718 try!(self.print_diagnostic(&ss, Note,
719 &format!("in expansion of {}{}{}",
724 let ss = cm.span_to_string(ei.call_site);
725 try!(self.print_diagnostic(&ss, Note, "expansion site", None));
726 Ok(Some(ei.call_site))
731 cs.map_or(Ok(()), |call_site| self.print_macro_backtrace(cm, call_site))
736 fn stderr_isatty() -> bool {
737 unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
740 fn stderr_isatty() -> bool {
741 const STD_ERROR_HANDLE: libc::DWORD = -12i32 as libc::DWORD;
743 fn GetStdHandle(which: libc::DWORD) -> libc::HANDLE;
744 fn GetConsoleMode(hConsoleHandle: libc::HANDLE,
745 lpMode: libc::LPDWORD) -> libc::BOOL;
748 let handle = GetStdHandle(STD_ERROR_HANDLE);
750 GetConsoleMode(handle, &mut out) != 0
754 impl Write for Destination {
755 fn write(&mut self, bytes: &[u8]) -> io::Result<usize> {
757 Terminal(ref mut t) => t.write(bytes),
758 Raw(ref mut w) => w.write(bytes),
761 fn flush(&mut self) -> io::Result<()> {
763 Terminal(ref mut t) => t.flush(),
764 Raw(ref mut w) => w.flush(),
769 impl Emitter for EmitterWriter {
771 cmsp: Option<(&codemap::CodeMap, Span)>,
772 msg: &str, code: Option<&str>, lvl: Level) {
773 let error = match cmsp {
774 Some((cm, COMMAND_LINE_SP)) => self.emit_(cm,
775 FileLine(COMMAND_LINE_SP),
777 Some((cm, sp)) => self.emit_(cm, FullSpan(sp), msg, code, lvl),
778 None => self.print_diagnostic("", lvl, msg, code),
783 Err(e) => panic!("failed to print diagnostics: {:?}", e),
787 fn custom_emit(&mut self, cm: &codemap::CodeMap,
788 sp: RenderSpan, msg: &str, lvl: Level) {
789 match self.emit_(cm, sp, msg, None, lvl) {
791 Err(e) => panic!("failed to print diagnostics: {:?}", e),
796 pub fn expect<T, M>(diag: &SpanHandler, opt: Option<T>, msg: M) -> T where
797 M: FnOnce() -> String,
801 None => diag.handler().bug(&msg()),
807 use super::{EmitterWriter, Level};
808 use codemap::{mk_sp, CodeMap, BytePos};
809 use std::sync::{Arc, Mutex};
810 use std::io::{self, Write};
811 use std::str::from_utf8;
813 // Diagnostic doesn't align properly in span where line number increases by one digit
815 fn test_hilight_suggestion_issue_11715() {
816 struct Sink(Arc<Mutex<Vec<u8>>>);
817 impl Write for Sink {
818 fn write(&mut self, data: &[u8]) -> io::Result<usize> {
819 Write::write(&mut *self.0.lock().unwrap(), data)
821 fn flush(&mut self) -> io::Result<()> { Ok(()) }
823 let data = Arc::new(Mutex::new(Vec::new()));
824 let mut ew = EmitterWriter::new(Box::new(Sink(data.clone())), None);
825 let cm = CodeMap::new();
826 let content = "abcdefg
840 let file = cm.new_filemap("dummy.txt".to_string(), content.to_string());
841 for (i, b) in content.bytes().enumerate() {
843 file.next_line(BytePos(i as u32));
846 let start = file.lines.borrow()[7];
847 let end = file.lines.borrow()[11];
848 let sp = mk_sp(start, end);
849 let lvl = Level::Error;
850 println!("span_to_lines");
851 let lines = cm.span_to_lines(sp);
852 println!("highlight_lines");
853 ew.highlight_lines(&cm, sp, lvl, lines).unwrap();
855 let vec = data.lock().unwrap().clone();
856 let vec: &[u8] = &vec;
857 let str = from_utf8(vec).unwrap();
859 assert_eq!(str, "dummy.txt: 8 line8\n\
860 dummy.txt: 9 line9\n\
861 dummy.txt:10 line10\n\
862 dummy.txt:11 e-lä-vän\n\
863 dummy.txt:12 tolv\n");