2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2013-05-17 15:28:44 -07:00
|
|
|
use core::prelude::*;
|
2013-01-08 19:37:25 -08:00
|
|
|
|
2013-02-25 13:23:16 -08:00
|
|
|
use core::cell::Cell;
|
2012-12-23 17:41:37 -05:00
|
|
|
use core::run;
|
2013-02-07 18:23:47 -08:00
|
|
|
use core::run::ProgramOutput;
|
2012-12-23 17:41:37 -05:00
|
|
|
use core::result::Result;
|
2013-05-19 11:17:49 -07:00
|
|
|
use extra::getopts;
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
/// The type of document to output
|
2013-03-26 08:04:54 -04:00
|
|
|
#[deriving(Eq)]
|
2012-11-19 18:00:12 -08:00
|
|
|
pub enum OutputFormat {
|
2012-07-04 22:53:12 +01:00
|
|
|
/// Markdown
|
2012-11-19 18:00:12 -08:00
|
|
|
pub Markdown,
|
2012-07-04 22:53:12 +01:00
|
|
|
/// HTML, via markdown and pandoc
|
2012-11-19 18:00:12 -08:00
|
|
|
pub PandocHtml
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
/// How to organize the output
|
2013-03-26 08:04:54 -04:00
|
|
|
#[deriving(Eq)]
|
2012-11-19 18:00:12 -08:00
|
|
|
pub enum OutputStyle {
|
2012-07-04 22:53:12 +01:00
|
|
|
/// All in a single document
|
2012-11-19 18:00:12 -08:00
|
|
|
pub DocPerCrate,
|
2012-07-04 22:53:12 +01:00
|
|
|
/// Each module in its own document
|
2012-11-19 18:00:12 -08:00
|
|
|
pub DocPerMod
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
/// The configuration for a rustdoc session
|
2013-01-25 16:57:39 -08:00
|
|
|
pub struct Config {
|
2012-08-24 15:28:43 -07:00
|
|
|
input_crate: Path,
|
|
|
|
output_dir: Path,
|
2012-09-18 16:48:40 -07:00
|
|
|
output_format: OutputFormat,
|
|
|
|
output_style: OutputStyle,
|
2012-08-20 12:23:37 -07:00
|
|
|
pandoc_cmd: Option<~str>
|
2013-01-25 16:57:39 -08:00
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-02-26 17:12:00 -08:00
|
|
|
impl Clone for Config {
|
2012-11-26 18:03:36 -08:00
|
|
|
fn clone(&self) -> Config { copy *self }
|
|
|
|
}
|
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
fn opt_output_dir() -> ~str { ~"output-dir" }
|
|
|
|
fn opt_output_format() -> ~str { ~"output-format" }
|
|
|
|
fn opt_output_style() -> ~str { ~"output-style" }
|
|
|
|
fn opt_pandoc_cmd() -> ~str { ~"pandoc-cmd" }
|
|
|
|
fn opt_help() -> ~str { ~"h" }
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2012-08-11 10:08:42 -04:00
|
|
|
fn opts() -> ~[(getopts::Opt, ~str)] {
|
2012-06-29 16:26:56 -07:00
|
|
|
~[
|
2012-02-26 16:32:57 -08:00
|
|
|
(getopts::optopt(opt_output_dir()),
|
2012-07-13 22:57:48 -07:00
|
|
|
~"--output-dir <val> put documents here"),
|
2012-02-26 16:32:57 -08:00
|
|
|
(getopts::optopt(opt_output_format()),
|
2012-07-13 22:57:48 -07:00
|
|
|
~"--output-format <val> either 'markdown' or 'html'"),
|
2012-02-26 16:32:57 -08:00
|
|
|
(getopts::optopt(opt_output_style()),
|
2012-07-13 22:57:48 -07:00
|
|
|
~"--output-style <val> either 'doc-per-crate' or 'doc-per-mod'"),
|
2012-02-26 16:32:57 -08:00
|
|
|
(getopts::optopt(opt_pandoc_cmd()),
|
2012-07-13 22:57:48 -07:00
|
|
|
~"--pandoc-cmd <val> the command for running pandoc"),
|
2012-02-28 21:27:38 -08:00
|
|
|
(getopts::optflag(opt_help()),
|
2012-07-13 22:57:48 -07:00
|
|
|
~"-h print help")
|
2012-06-29 16:26:56 -07:00
|
|
|
]
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:00:12 -08:00
|
|
|
pub fn usage() {
|
2013-03-01 10:44:43 -08:00
|
|
|
use core::io::println;
|
2012-02-28 21:27:38 -08:00
|
|
|
|
2013-05-21 22:55:07 +09:00
|
|
|
println("Usage: rustdoc [options] <cratefile>\n");
|
|
|
|
println("Options:\n");
|
2012-06-30 16:19:07 -07:00
|
|
|
for opts().each |opt| {
|
2012-08-22 17:24:52 -07:00
|
|
|
println(fmt!(" %s", opt.second()));
|
2012-02-28 21:27:38 -08:00
|
|
|
}
|
2013-05-21 22:55:07 +09:00
|
|
|
println("");
|
2012-02-28 21:27:38 -08:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:00:12 -08:00
|
|
|
pub fn default_config(input_crate: &Path) -> Config {
|
2013-01-25 16:57:39 -08:00
|
|
|
Config {
|
2013-01-30 13:14:35 -08:00
|
|
|
input_crate: copy *input_crate,
|
2012-08-24 15:28:43 -07:00
|
|
|
output_dir: Path("."),
|
2012-09-18 16:48:40 -07:00
|
|
|
output_format: PandocHtml,
|
|
|
|
output_style: DocPerMod,
|
2012-08-20 12:23:37 -07:00
|
|
|
pandoc_cmd: None
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 16:02:22 -08:00
|
|
|
type Process = ~fn((&str), (&[~str])) -> ProgramOutput;
|
2012-03-06 14:46:10 -08:00
|
|
|
|
2013-02-07 18:23:47 -08:00
|
|
|
pub fn mock_program_output(_prog: &str, _args: &[~str]) -> ProgramOutput {
|
|
|
|
ProgramOutput {
|
2012-03-06 14:46:10 -08:00
|
|
|
status: 0,
|
2012-07-13 22:57:48 -07:00
|
|
|
out: ~"",
|
|
|
|
err: ~""
|
2012-03-06 14:46:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-07 18:23:47 -08:00
|
|
|
pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput {
|
|
|
|
run::program_output(prog, args)
|
2013-01-30 19:45:39 -08:00
|
|
|
}
|
|
|
|
|
2012-11-21 11:25:01 -08:00
|
|
|
pub fn parse_config(args: &[~str]) -> Result<Config, ~str> {
|
2013-01-30 19:45:39 -08:00
|
|
|
parse_config_(args, program_output)
|
2012-03-06 14:46:10 -08:00
|
|
|
}
|
|
|
|
|
2013-01-08 19:37:25 -08:00
|
|
|
pub fn parse_config_(
|
2012-11-19 18:48:46 -08:00
|
|
|
args: &[~str],
|
2013-02-07 18:23:47 -08:00
|
|
|
program_output: Process
|
2012-09-18 16:48:40 -07:00
|
|
|
) -> Result<Config, ~str> {
|
2012-11-24 12:49:31 -08:00
|
|
|
let args = args.tail();
|
2012-07-16 22:32:59 +01:00
|
|
|
let opts = vec::unzip(opts()).first();
|
2012-08-06 12:34:08 -07:00
|
|
|
match getopts::getopts(args, opts) {
|
2013-03-03 11:44:11 -08:00
|
|
|
Ok(matches) => {
|
2012-11-24 12:49:31 -08:00
|
|
|
if matches.free.len() == 1 {
|
2013-03-03 11:44:11 -08:00
|
|
|
let input_crate = Path(*matches.free.head());
|
2013-02-15 00:37:08 -08:00
|
|
|
config_from_opts(&input_crate, &matches, program_output)
|
2012-11-24 12:49:31 -08:00
|
|
|
} else if matches.free.is_empty() {
|
2013-03-03 11:44:11 -08:00
|
|
|
Err(~"no crates specified")
|
2012-02-26 16:32:57 -08:00
|
|
|
} else {
|
2013-03-03 11:44:11 -08:00
|
|
|
Err(~"multiple crates specified")
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
}
|
2013-03-03 11:44:11 -08:00
|
|
|
Err(f) => {
|
|
|
|
Err(getopts::fail_str(f))
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn config_from_opts(
|
2012-08-24 15:28:43 -07:00
|
|
|
input_crate: &Path,
|
2012-11-24 12:49:31 -08:00
|
|
|
matches: &getopts::Matches,
|
2013-02-07 18:23:47 -08:00
|
|
|
program_output: Process
|
2012-09-18 16:48:40 -07:00
|
|
|
) -> Result<Config, ~str> {
|
2012-02-26 16:32:57 -08:00
|
|
|
|
|
|
|
let config = default_config(input_crate);
|
2012-08-26 16:54:31 -07:00
|
|
|
let result = result::Ok(config);
|
2012-06-30 16:19:07 -07:00
|
|
|
let result = do result::chain(result) |config| {
|
2012-07-31 16:38:41 -07:00
|
|
|
let output_dir = getopts::opt_maybe_str(matches, opt_output_dir());
|
2012-09-26 16:27:12 -07:00
|
|
|
let output_dir = output_dir.map(|s| Path(*s));
|
2013-01-25 16:57:39 -08:00
|
|
|
result::Ok(Config {
|
2013-01-30 13:14:35 -08:00
|
|
|
output_dir: output_dir.get_or_default(copy config.output_dir),
|
2012-09-04 13:29:32 -07:00
|
|
|
.. config
|
2012-02-26 16:32:57 -08:00
|
|
|
})
|
|
|
|
};
|
2012-06-30 16:19:07 -07:00
|
|
|
let result = do result::chain(result) |config| {
|
2012-02-26 16:32:57 -08:00
|
|
|
let output_format = getopts::opt_maybe_str(
|
2012-07-31 16:38:41 -07:00
|
|
|
matches, opt_output_format());
|
2013-01-30 13:14:35 -08:00
|
|
|
do output_format.map_default(result::Ok(copy config))
|
2012-06-30 16:19:07 -07:00
|
|
|
|output_format| {
|
2012-09-26 16:27:12 -07:00
|
|
|
do result::chain(parse_output_format(*output_format))
|
2012-06-30 16:19:07 -07:00
|
|
|
|output_format| {
|
2012-06-26 13:55:56 -07:00
|
|
|
|
2013-01-25 16:57:39 -08:00
|
|
|
result::Ok(Config {
|
2012-09-04 13:29:32 -07:00
|
|
|
output_format: output_format,
|
2013-01-30 13:14:35 -08:00
|
|
|
.. copy config
|
2012-02-26 16:32:57 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2012-06-30 16:19:07 -07:00
|
|
|
let result = do result::chain(result) |config| {
|
2012-07-31 16:38:41 -07:00
|
|
|
let output_style =
|
|
|
|
getopts::opt_maybe_str(matches, opt_output_style());
|
2013-01-30 13:14:35 -08:00
|
|
|
do output_style.map_default(result::Ok(copy config))
|
2012-06-30 16:19:07 -07:00
|
|
|
|output_style| {
|
2012-09-26 16:27:12 -07:00
|
|
|
do result::chain(parse_output_style(*output_style))
|
2012-06-30 16:19:07 -07:00
|
|
|
|output_style| {
|
2013-01-25 16:57:39 -08:00
|
|
|
result::Ok(Config {
|
2012-09-04 13:29:32 -07:00
|
|
|
output_style: output_style,
|
2013-01-30 13:14:35 -08:00
|
|
|
.. copy config
|
2012-02-26 16:32:57 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2013-02-15 00:37:08 -08:00
|
|
|
let program_output = Cell(program_output);
|
2012-06-30 16:19:07 -07:00
|
|
|
let result = do result::chain(result) |config| {
|
2012-07-31 16:38:41 -07:00
|
|
|
let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd());
|
2012-03-06 14:46:10 -08:00
|
|
|
let pandoc_cmd = maybe_find_pandoc(
|
2013-02-15 00:37:08 -08:00
|
|
|
&config, pandoc_cmd, program_output.take());
|
2012-06-30 16:19:07 -07:00
|
|
|
do result::chain(pandoc_cmd) |pandoc_cmd| {
|
2013-01-25 16:57:39 -08:00
|
|
|
result::Ok(Config {
|
2012-09-04 13:29:32 -07:00
|
|
|
pandoc_cmd: pandoc_cmd,
|
2013-01-30 13:14:35 -08:00
|
|
|
.. copy config
|
2012-02-26 16:32:57 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
2012-08-01 17:30:05 -07:00
|
|
|
return result;
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:48:46 -08:00
|
|
|
fn parse_output_format(output_format: &str) -> Result<OutputFormat, ~str> {
|
|
|
|
match output_format.to_str() {
|
2012-09-18 16:48:40 -07:00
|
|
|
~"markdown" => result::Ok(Markdown),
|
|
|
|
~"html" => result::Ok(PandocHtml),
|
2012-08-26 16:54:31 -07:00
|
|
|
_ => result::Err(fmt!("unknown output format '%s'", output_format))
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:48:46 -08:00
|
|
|
fn parse_output_style(output_style: &str) -> Result<OutputStyle, ~str> {
|
|
|
|
match output_style.to_str() {
|
2012-09-18 16:48:40 -07:00
|
|
|
~"doc-per-crate" => result::Ok(DocPerCrate),
|
|
|
|
~"doc-per-mod" => result::Ok(DocPerMod),
|
2012-08-26 16:54:31 -07:00
|
|
|
_ => result::Err(fmt!("unknown output style '%s'", output_style))
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
pub fn maybe_find_pandoc(
|
2012-11-19 18:48:46 -08:00
|
|
|
config: &Config,
|
2013-01-30 19:32:36 -08:00
|
|
|
maybe_pandoc_cmd: Option<~str>,
|
2013-02-07 18:23:47 -08:00
|
|
|
program_output: Process
|
2012-08-26 16:54:31 -07:00
|
|
|
) -> Result<Option<~str>, ~str> {
|
2012-09-18 16:48:40 -07:00
|
|
|
if config.output_format != PandocHtml {
|
2012-08-26 16:54:31 -07:00
|
|
|
return result::Ok(maybe_pandoc_cmd);
|
2012-03-06 14:46:10 -08:00
|
|
|
}
|
|
|
|
|
2012-08-06 12:34:08 -07:00
|
|
|
let possible_pandocs = match maybe_pandoc_cmd {
|
2012-08-20 12:23:37 -07:00
|
|
|
Some(pandoc_cmd) => ~[pandoc_cmd],
|
|
|
|
None => {
|
2012-08-06 12:34:08 -07:00
|
|
|
~[~"pandoc"] + match os::homedir() {
|
2012-08-20 12:23:37 -07:00
|
|
|
Some(dir) => {
|
2012-08-24 15:28:43 -07:00
|
|
|
~[dir.push_rel(&Path(".cabal/bin/pandoc")).to_str()]
|
2012-03-07 19:22:02 -08:00
|
|
|
}
|
2012-08-20 12:23:37 -07:00
|
|
|
None => ~[]
|
2012-03-07 19:22:02 -08:00
|
|
|
}
|
2012-03-06 14:46:10 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-30 16:19:07 -07:00
|
|
|
let pandoc = do vec::find(possible_pandocs) |pandoc| {
|
2013-05-21 22:55:07 +09:00
|
|
|
let output = program_output(*pandoc, [~"--version"]);
|
2012-09-27 22:20:47 -07:00
|
|
|
debug!("testing pandoc cmd %s: %?", *pandoc, output);
|
2012-03-06 14:46:10 -08:00
|
|
|
output.status == 0
|
|
|
|
};
|
|
|
|
|
2012-09-21 19:37:57 -07:00
|
|
|
if pandoc.is_some() {
|
2012-08-26 16:54:31 -07:00
|
|
|
result::Ok(pandoc)
|
2012-03-06 14:46:10 -08:00
|
|
|
} else {
|
2012-08-26 16:54:31 -07:00
|
|
|
result::Err(~"couldn't find pandoc")
|
2012-03-06 14:46:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
2013-05-22 19:59:22 -07:00
|
|
|
use core::prelude::*;
|
2013-04-16 01:09:55 +10:00
|
|
|
use config::*;
|
|
|
|
use core::run::ProgramOutput;
|
2013-01-08 19:37:25 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
fn parse_config(args: &[~str]) -> Result<Config, ~str> {
|
2012-03-06 14:46:10 -08:00
|
|
|
parse_config_(args, mock_program_output)
|
2012-02-26 16:32:57 -08:00
|
|
|
}
|
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_find_pandoc() {
|
|
|
|
let config = Config {
|
|
|
|
output_format: PandocHtml,
|
|
|
|
.. default_config(&Path("test"))
|
|
|
|
};
|
|
|
|
let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| {
|
|
|
|
ProgramOutput { status: 0, out: ~"pandoc 1.8.2.1", err: ~"" }
|
|
|
|
};
|
|
|
|
let result = maybe_find_pandoc(&config, None, mock_program_output);
|
|
|
|
assert!(result == result::Ok(Some(~"pandoc")));
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_error_with_no_pandoc() {
|
|
|
|
let config = Config {
|
|
|
|
output_format: PandocHtml,
|
|
|
|
.. default_config(&Path("test"))
|
|
|
|
};
|
|
|
|
let mock_program_output: ~fn(&str, &[~str]) -> ProgramOutput = |_, _| {
|
|
|
|
ProgramOutput { status: 1, out: ~"", err: ~"" }
|
|
|
|
};
|
|
|
|
let result = maybe_find_pandoc(&config, None, mock_program_output);
|
|
|
|
assert!(result == result::Err(~"couldn't find pandoc"));
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_error_with_no_crates() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([~"rustdoc"]);
|
2013-04-16 01:09:55 +10:00
|
|
|
assert!(config.get_err() == ~"no crates specified");
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_error_with_multiple_crates() {
|
|
|
|
let config =
|
2013-05-23 09:39:38 -07:00
|
|
|
parse_config([~"rustdoc", ~"crate1.rc", ~"crate2.rc"]);
|
2013-04-16 01:09:55 +10:00
|
|
|
assert!(config.get_err() == ~"multiple crates specified");
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_dir_to_cwd_if_not_provided() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([~"rustdoc", ~"crate.rc"]);
|
2013-04-16 01:09:55 +10:00
|
|
|
assert!(config.get().output_dir == Path("."));
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_dir_if_provided() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-dir", ~"snuggles"
|
|
|
|
]);
|
|
|
|
assert!(config.get().output_dir == Path("snuggles"));
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_format_to_pandoc_html_if_not_provided() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([~"rustdoc", ~"crate.rc"]);
|
2013-04-16 01:09:55 +10:00
|
|
|
assert!(config.get().output_format == PandocHtml);
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_format_to_markdown_if_requested() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-format", ~"markdown"
|
|
|
|
]);
|
|
|
|
assert!(config.get().output_format == Markdown);
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_format_to_pandoc_html_if_requested() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-format", ~"html"
|
|
|
|
]);
|
|
|
|
assert!(config.get().output_format == PandocHtml);
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_error_on_bogus_format() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-format", ~"bogus"
|
|
|
|
]);
|
|
|
|
assert!(config.get_err() == ~"unknown output format 'bogus'");
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_style_to_doc_per_mod_by_default() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([~"rustdoc", ~"crate.rc"]);
|
2013-04-16 01:09:55 +10:00
|
|
|
assert!(config.get().output_style == DocPerMod);
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_style_to_one_doc_if_requested() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-crate"
|
|
|
|
]);
|
|
|
|
assert!(config.get().output_style == DocPerCrate);
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_set_output_style_to_doc_per_mod_if_requested() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-style", ~"doc-per-mod"
|
|
|
|
]);
|
|
|
|
assert!(config.get().output_style == DocPerMod);
|
|
|
|
}
|
2012-02-26 16:32:57 -08:00
|
|
|
|
2013-04-16 01:09:55 +10:00
|
|
|
#[test]
|
|
|
|
fn should_error_on_bogus_output_style() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--output-style", ~"bogus"
|
|
|
|
]);
|
|
|
|
assert!(config.get_err() == ~"unknown output style 'bogus'");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_set_pandoc_command_if_requested() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([
|
2013-04-16 01:09:55 +10:00
|
|
|
~"rustdoc", ~"crate.rc", ~"--pandoc-cmd", ~"panda-bear-doc"
|
|
|
|
]);
|
|
|
|
assert!(config.get().pandoc_cmd == Some(~"panda-bear-doc"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_set_pandoc_command_when_using_pandoc() {
|
2013-05-23 09:39:38 -07:00
|
|
|
let config = parse_config([~"rustdoc", ~"crate.rc"]);
|
2013-04-16 01:09:55 +10:00
|
|
|
assert!(config.get().pandoc_cmd == Some(~"pandoc"));
|
|
|
|
}
|
2013-04-26 12:24:15 -04:00
|
|
|
}
|