Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement doc tests #302

Merged
merged 2 commits into from
Aug 7, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor cargo_test into an ops module
The logic for doc tests will get a little complex, so this is moved to aseparate
module instead of inside the executable.
  • Loading branch information
alexcrichton committed Aug 5, 2014
commit 48bfdaadcefffcce60bd49f5cb50e101a53aeb9f
29 changes: 11 additions & 18 deletions src/bin/cargo-test.rs
Original file line number Diff line number Diff line change
@@ -8,9 +8,8 @@ extern crate docopt;
use std::io::process::ExitStatus;

use cargo::ops;
use cargo::{execute_main_without_stdin};
use cargo::core::{MultiShell};
use cargo::util;
use cargo::execute_main_without_stdin;
use cargo::core::MultiShell;
use cargo::util::{CliResult, CliError, CargoError};
use cargo::util::important_paths::{find_root_manifest_for_cwd};

@@ -48,24 +47,18 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
target: None,
};

let test_executables = try!(ops::compile(&root,
&mut compile_opts).map_err(|err| {
let err = try!(ops::run_tests(&root, &mut compile_opts,
options.arg_args.as_slice()).map_err(|err| {
CliError::from_boxed(err, 101)
}));

let test_dir = root.dir_path().join("target").join("test");

for file in test_executables.iter() {
try!(util::process(test_dir.join(file.as_slice()))
.args(options.arg_args.as_slice())
.exec().map_err(|e| {
let exit_status = match e.exit {
match err {
None => Ok(None),
Some(err) => {
let status = match err.exit {
Some(ExitStatus(i)) => i as uint,
_ => 1,
_ => 101,
};
CliError::from_boxed(e.mark_human(), exit_status)
}));
Err(CliError::from_boxed(err.mark_human(), status))
}
}

Ok(None)
}
15 changes: 2 additions & 13 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ pub struct CompileOptions<'a> {
}

pub fn compile(manifest_path: &Path,
options: &mut CompileOptions) -> CargoResult<Vec<String>> {
options: &mut CompileOptions) -> CargoResult<()> {
let CompileOptions { update, env, ref mut shell, jobs, target } = *options;
let target = target.map(|s| s.to_string());

@@ -127,18 +127,7 @@ pub fn compile(manifest_path: &Path,

try!(ops::write_resolve(&package, &resolve));

let test_executables: Vec<String> = targets.iter()
.filter_map(|target| {
if target.get_profile().is_test() {
debug!("Run Target: {}", target.get_name());
Some(target.file_stem())
} else {
debug!("Skip Target: {}", target.get_name());
None
}
}).collect();

Ok(test_executables)
Ok(())
}

fn source_ids_from_config(configs: &HashMap<String, config::ConfigValue>,
33 changes: 33 additions & 0 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use core::Source;
use sources::PathSource;
use ops;
use util::{process, CargoResult, ProcessError};

pub fn run_tests(manifest_path: &Path,
options: &mut ops::CompileOptions,
args: &[String]) -> CargoResult<Option<ProcessError>> {
let mut source = PathSource::for_path(&manifest_path.dir_path());
try!(source.update());
let package = try!(source.get_root_package());

try!(ops::compile(manifest_path, options));

let mut exes = package.get_targets().iter().filter_map(|target| {
if !target.get_profile().is_test() { return None }
let root = package.get_root().join("target");
let root = match target.get_profile().get_dest() {
Some(dest) => root.join(dest),
None => root,
};
Some(root.join(target.file_stem()))
});

for exe in exes {
match process(exe).args(args).exec() {
Ok(()) => {}
Err(e) => return Ok(Some(e))
}
}

Ok(None)
}
2 changes: 2 additions & 0 deletions src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ pub use self::cargo_new::{new, NewOptions};
pub use self::cargo_doc::{doc, DocOptions};
pub use self::cargo_generate_lockfile::{generate_lockfile, write_resolve};
pub use self::cargo_generate_lockfile::{update_lockfile, load_lockfile};
pub use self::cargo_test::run_tests;

mod cargo_clean;
mod cargo_compile;
@@ -16,3 +17,4 @@ mod cargo_run;
mod cargo_new;
mod cargo_doc;
mod cargo_generate_lockfile;
mod cargo_test;