Skip to content

Commit

Permalink
rustdoc: Capture all output from rustc by default
Browse files Browse the repository at this point in the history
This helps prevent interleaving of error messages when running rustdoc tests.
This has an interesting bit of shuffling with I/O handles, but other than that
this is just using the APIs laid out in the previous commit.

Closes #12623
  • Loading branch information
alexcrichton committed Mar 1, 2014
1 parent 3245471 commit 0e1a860
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn get_ast_and_resolve(cpath: &Path,
};


let diagnostic_handler = syntax::diagnostic::mk_handler();
let diagnostic_handler = syntax::diagnostic::default_handler();
let span_diagnostic_handler =
syntax::diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use t = syntax::parse::token;
/// Highlights some source code, returning the HTML output.
pub fn highlight(src: &str) -> ~str {
let sess = parse::new_parse_sess();
let handler = diagnostic::mk_handler();
let handler = diagnostic::default_handler();
let span_handler = diagnostic::mk_span_handler(handler, sess.cm);
let fm = parse::string_to_filemap(sess, src.to_owned(), ~"<stdin>");
Expand Down
28 changes: 26 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn run(input: &str, matches: &getopts::Matches) -> int {


let cm = @CodeMap::new();
let diagnostic_handler = diagnostic::mk_handler();
let diagnostic_handler = diagnostic::default_handler();
let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, cm);
let parsesess = parse::new_parse_sess_special_handler(span_diagnostic_handler,
Expand Down Expand Up @@ -115,7 +115,30 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool)
.. (*session::basic_options()).clone()
};

let diagnostic_handler = diagnostic::mk_handler();
// Shuffle around a few input and output handles here. We're going to pass
// an explicit handle into rustc to collect output messages, but we also
// want to catch the error message that rustc prints when it fails.
//
// We take our task-local stderr (likely set by the test runner), and move
// it into another task. This helper task then acts as a sink for both the
// stderr of this task and stderr of rustc itself, copying all the info onto
// the stderr channel we originally started with.
//
// The basic idea is to not use a default_handler() for rustc, and then also
// not print things by default to the actual stderr.
let (p, c) = Chan::new();
let w1 = io::ChanWriter::new(c);
let w2 = w1.clone();
let old = io::stdio::set_stderr(~w1);
spawn(proc() {
let mut p = io::PortReader::new(p);
let mut err = old.unwrap_or(~io::stderr() as ~Writer);
io::util::copy(&mut p, &mut err).unwrap();
});
let emitter = diagnostic::EmitterWriter::new(~w2);

// Compile the code
let diagnostic_handler = diagnostic::mk_handler(~emitter);
let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);

Expand All @@ -129,6 +152,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool)
let cfg = driver::build_configuration(sess);
driver::compile_input(sess, cfg, &input, &out, &None);

// Run the code!
let exe = outdir.path().join("rust_out");
let out = Process::output(exe.as_str().unwrap(), []);
match out {
Expand Down
6 changes: 5 additions & 1 deletion src/libsyntax/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,7 @@ mod test {
use diagnostic;
use parse::token;
use parse::token::{str_to_ident};
use std::io::util;

// represents a testing reader (incl. both reader and interner)
struct Env {
Expand All @@ -1014,7 +1015,10 @@ mod test {
fn setup(teststr: ~str) -> Env {
let cm = CodeMap::new();
let fm = cm.new_filemap(~"zebra.rs", teststr);
let span_handler = diagnostic::mk_span_handler(diagnostic::mk_handler(), @cm);
let writer = ~util::NullWriter;
let emitter = diagnostic::EmitterWriter::new(writer);
let handler = diagnostic::mk_handler(~emitter);
let span_handler = diagnostic::mk_span_handler(handler, @cm);
Env {
string_reader: new_string_reader(span_handler,fm)
}
Expand Down

12 comments on commit 0e1a860

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@0e1a860

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/issue-12623 = 0e1a860 into auto

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/issue-12623 = 0e1a860 merged ok, testing candidate = 02156a2d

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@0e1a860

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/issue-12623 = 0e1a860 into issue-12623-bors-integration

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/issue-12623 = 0e1a860 merged ok, testing candidate = 20ab6f29

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No active merge of candidate 0e1a860 found, likely manual push to master

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/issue-12623 = 0e1a860 into auto

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/issue-12623 = 0e1a860 merged ok, testing candidate = cb498cc

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 0e1a860 Mar 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = cb498cc

Please sign in to comment.