Add some basic help tests
This commit is contained in:
parent
ac3e4b6c1e
commit
dd778d50f9
5 changed files with 163 additions and 12 deletions
|
|
@ -32,15 +32,3 @@ fn mdbook_cli_detects_book_with_failing_tests() {
|
||||||
.stderr(predicates::str::is_match(r##"returned an error:\n\n"##).unwrap())
|
.stderr(predicates::str::is_match(r##"returned an error:\n\n"##).unwrap())
|
||||||
.stderr(predicates::str::is_match(r##"Nested_Chapter::Rustdoc_include_works_with_anchors_too \(line \d+\) ... FAILED"##).unwrap());
|
.stderr(predicates::str::is_match(r##"Nested_Chapter::Rustdoc_include_works_with_anchors_too \(line \d+\) ... FAILED"##).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn empty_cli() {
|
|
||||||
let mut cmd = mdbook_cmd();
|
|
||||||
cmd.assert()
|
|
||||||
.failure()
|
|
||||||
.code(2)
|
|
||||||
.stdout(predicates::str::is_empty())
|
|
||||||
.stderr(predicates::str::contains(
|
|
||||||
"Creates a book from markdown files",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
|
||||||
36
tests/testsuite/cli.rs
Normal file
36
tests/testsuite/cli.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
//! Basic tests for mdbook's CLI.
|
||||||
|
|
||||||
|
use crate::prelude::*;
|
||||||
|
use snapbox::file;
|
||||||
|
|
||||||
|
// Test with no args.
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(
|
||||||
|
not(all(feature = "watch", feature = "serve")),
|
||||||
|
ignore = "needs all features"
|
||||||
|
)]
|
||||||
|
fn no_args() {
|
||||||
|
BookTest::empty().run("", |cmd| {
|
||||||
|
cmd.expect_code(2)
|
||||||
|
.expect_stdout(str![[""]])
|
||||||
|
.expect_stderr(file!["cli/no_args.term.svg"]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Help command.
|
||||||
|
#[test]
|
||||||
|
#[cfg_attr(
|
||||||
|
not(all(feature = "watch", feature = "serve")),
|
||||||
|
ignore = "needs all features"
|
||||||
|
)]
|
||||||
|
fn help() {
|
||||||
|
BookTest::empty()
|
||||||
|
.run("help", |cmd| {
|
||||||
|
cmd.expect_stdout(file!["cli/help.term.svg"])
|
||||||
|
.expect_stderr(str![[""]]);
|
||||||
|
})
|
||||||
|
.run("--help", |cmd| {
|
||||||
|
cmd.expect_stdout(file!["cli/help.term.svg"])
|
||||||
|
.expect_stderr(str![[""]]);
|
||||||
|
});
|
||||||
|
}
|
||||||
63
tests/testsuite/cli/help.term.svg
Normal file
63
tests/testsuite/cli/help.term.svg
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
<svg width="740px" height="398px" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<style>
|
||||||
|
.fg { fill: #AAAAAA }
|
||||||
|
.bg { background: #000000 }
|
||||||
|
.container {
|
||||||
|
padding: 0 10px;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
tspan {
|
||||||
|
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
|
||||||
|
white-space: pre;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
|
||||||
|
|
||||||
|
<text xml:space="preserve" class="container fg">
|
||||||
|
<tspan x="10px" y="28px"><tspan>Creates a book from markdown files</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="46px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="64px"><tspan>Usage: mdbook[EXE] [COMMAND]</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="82px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="100px"><tspan>Commands:</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="118px"><tspan> init Creates the boilerplate structure and files for a new book</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="136px"><tspan> build Builds a book from its markdown files</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="154px"><tspan> test Tests that a book's Rust code samples compile</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="172px"><tspan> clean Deletes a built book</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="190px"><tspan> completions Generate shell completions for your shell to stdout</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="208px"><tspan> watch Watches a book's files and rebuilds it on changes</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="226px"><tspan> serve Serves a book at http://localhost:3000, and rebuilds it on changes</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="244px"><tspan> help Print this message or the help of the given subcommand(s)</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="262px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="280px"><tspan>Options:</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="298px"><tspan> -h, --help Print help</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="316px"><tspan> -V, --version Print version</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="334px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="352px"><tspan>For more information about a specific command, try `mdbook <command> --help`</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="370px"><tspan>The source code for mdBook is available at: https://github.com/rust-lang/mdBook</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="388px">
|
||||||
|
</tspan>
|
||||||
|
</text>
|
||||||
|
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.3 KiB |
63
tests/testsuite/cli/no_args.term.svg
Normal file
63
tests/testsuite/cli/no_args.term.svg
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
<svg width="740px" height="398px" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<style>
|
||||||
|
.fg { fill: #AAAAAA }
|
||||||
|
.bg { background: #000000 }
|
||||||
|
.container {
|
||||||
|
padding: 0 10px;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
tspan {
|
||||||
|
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
|
||||||
|
white-space: pre;
|
||||||
|
line-height: 18px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<rect width="100%" height="100%" y="0" rx="4.5" class="bg" />
|
||||||
|
|
||||||
|
<text xml:space="preserve" class="container fg">
|
||||||
|
<tspan x="10px" y="28px"><tspan>Creates a book from markdown files</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="46px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="64px"><tspan>Usage: mdbook[EXE] [COMMAND]</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="82px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="100px"><tspan>Commands:</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="118px"><tspan> init Creates the boilerplate structure and files for a new book</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="136px"><tspan> build Builds a book from its markdown files</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="154px"><tspan> test Tests that a book's Rust code samples compile</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="172px"><tspan> clean Deletes a built book</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="190px"><tspan> completions Generate shell completions for your shell to stdout</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="208px"><tspan> watch Watches a book's files and rebuilds it on changes</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="226px"><tspan> serve Serves a book at http://localhost:3000, and rebuilds it on changes</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="244px"><tspan> help Print this message or the help of the given subcommand(s)</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="262px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="280px"><tspan>Options:</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="298px"><tspan> -h, --help Print help</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="316px"><tspan> -V, --version Print version</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="334px">
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="352px"><tspan>For more information about a specific command, try `mdbook <command> --help`</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="370px"><tspan>The source code for mdBook is available at: https://github.com/rust-lang/mdBook</tspan>
|
||||||
|
</tspan>
|
||||||
|
<tspan x="10px" y="388px">
|
||||||
|
</tspan>
|
||||||
|
</text>
|
||||||
|
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.3 KiB |
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
mod book_test;
|
mod book_test;
|
||||||
mod build;
|
mod build;
|
||||||
|
mod cli;
|
||||||
|
|
||||||
mod prelude {
|
mod prelude {
|
||||||
pub use crate::book_test::BookTest;
|
pub use crate::book_test::BookTest;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue