2014-12-02 08:20:48 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Implementation of the `test` subcommand. Just a stub for now.
|
|
|
|
|
|
|
|
use subcommand::Subcommand;
|
2015-02-26 23:00:43 -06:00
|
|
|
use error::{err, CliResult, CommandResult};
|
2014-12-02 08:20:48 -06:00
|
|
|
use term::Term;
|
|
|
|
use book;
|
2015-02-26 23:00:43 -06:00
|
|
|
|
|
|
|
use std::fs::File;
|
|
|
|
use std::env;
|
|
|
|
use std::process::Command;
|
2014-12-02 08:20:48 -06:00
|
|
|
|
|
|
|
struct Test;
|
|
|
|
|
|
|
|
pub fn parse_cmd(name: &str) -> Option<Box<Subcommand>> {
|
|
|
|
if name == "test" {
|
2015-02-26 23:00:43 -06:00
|
|
|
Some(Box::new(Test))
|
2014-12-02 08:20:48 -06:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Subcommand for Test {
|
|
|
|
fn parse_args(&mut self, _: &[String]) -> CliResult<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
fn usage(&self) {}
|
|
|
|
fn execute(&mut self, term: &mut Term) -> CommandResult<()> {
|
2015-02-26 23:00:43 -06:00
|
|
|
let cwd = env::current_dir().unwrap();
|
2014-12-02 08:20:48 -06:00
|
|
|
let src = cwd.clone();
|
|
|
|
|
2015-02-26 23:00:43 -06:00
|
|
|
let mut summary = try!(File::open(&src.join("SUMMARY.md")));
|
|
|
|
match book::parse_summary(&mut summary, &src) {
|
2014-12-02 08:20:48 -06:00
|
|
|
Ok(book) => {
|
|
|
|
for (_, item) in book.iter() {
|
|
|
|
let output_result = Command::new("rustdoc")
|
|
|
|
.arg(&item.path)
|
|
|
|
.arg("--test")
|
|
|
|
.output();
|
|
|
|
match output_result {
|
|
|
|
Ok(output) => {
|
|
|
|
if !output.status.success() {
|
|
|
|
term.err(&format!("{}\n{}",
|
2015-02-26 23:00:43 -06:00
|
|
|
String::from_utf8_lossy(&output.stdout),
|
|
|
|
String::from_utf8_lossy(&output.stderr)));
|
|
|
|
return Err(err("some tests failed"));
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Err(e) => {
|
2015-02-26 23:00:43 -06:00
|
|
|
let message = format!("could not execute `rustdoc`: {}", e);
|
|
|
|
return Err(err(&message))
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(errors) => {
|
2015-01-31 19:03:04 -06:00
|
|
|
for err in errors {
|
2015-02-18 13:48:57 -06:00
|
|
|
term.err(&err[..]);
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|
2015-02-26 23:00:43 -06:00
|
|
|
return Err(err("there was an error"))
|
2014-12-02 08:20:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(()) // lol
|
|
|
|
}
|
|
|
|
}
|