From dd778d50f94a1bb7a0ea20b496faab2ac98b7bca Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Apr 2025 18:39:25 -0700 Subject: [PATCH] Add some basic help tests --- tests/cli/test.rs | 12 ------ tests/testsuite/cli.rs | 36 ++++++++++++++++ tests/testsuite/cli/help.term.svg | 63 ++++++++++++++++++++++++++++ tests/testsuite/cli/no_args.term.svg | 63 ++++++++++++++++++++++++++++ tests/testsuite/main.rs | 1 + 5 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 tests/testsuite/cli.rs create mode 100644 tests/testsuite/cli/help.term.svg create mode 100644 tests/testsuite/cli/no_args.term.svg diff --git a/tests/cli/test.rs b/tests/cli/test.rs index 56e0f159..63114d3a 100644 --- a/tests/cli/test.rs +++ b/tests/cli/test.rs @@ -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##"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", - )); -} diff --git a/tests/testsuite/cli.rs b/tests/testsuite/cli.rs new file mode 100644 index 00000000..caa59752 --- /dev/null +++ b/tests/testsuite/cli.rs @@ -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![[""]]); + }); +} diff --git a/tests/testsuite/cli/help.term.svg b/tests/testsuite/cli/help.term.svg new file mode 100644 index 00000000..e27fa313 --- /dev/null +++ b/tests/testsuite/cli/help.term.svg @@ -0,0 +1,63 @@ + + + + + + + Creates a book from markdown files + + + + Usage: mdbook[EXE] [COMMAND] + + + + Commands: + + init Creates the boilerplate structure and files for a new book + + build Builds a book from its markdown files + + test Tests that a book's Rust code samples compile + + clean Deletes a built book + + completions Generate shell completions for your shell to stdout + + watch Watches a book's files and rebuilds it on changes + + serve Serves a book at http://localhost:3000, and rebuilds it on changes + + help Print this message or the help of the given subcommand(s) + + + + Options: + + -h, --help Print help + + -V, --version Print version + + + + For more information about a specific command, try `mdbook <command> --help` + + The source code for mdBook is available at: https://github.com/rust-lang/mdBook + + + + + + diff --git a/tests/testsuite/cli/no_args.term.svg b/tests/testsuite/cli/no_args.term.svg new file mode 100644 index 00000000..e27fa313 --- /dev/null +++ b/tests/testsuite/cli/no_args.term.svg @@ -0,0 +1,63 @@ + + + + + + + Creates a book from markdown files + + + + Usage: mdbook[EXE] [COMMAND] + + + + Commands: + + init Creates the boilerplate structure and files for a new book + + build Builds a book from its markdown files + + test Tests that a book's Rust code samples compile + + clean Deletes a built book + + completions Generate shell completions for your shell to stdout + + watch Watches a book's files and rebuilds it on changes + + serve Serves a book at http://localhost:3000, and rebuilds it on changes + + help Print this message or the help of the given subcommand(s) + + + + Options: + + -h, --help Print help + + -V, --version Print version + + + + For more information about a specific command, try `mdbook <command> --help` + + The source code for mdBook is available at: https://github.com/rust-lang/mdBook + + + + + + diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index 11cd9a81..c8630267 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -4,6 +4,7 @@ mod book_test; mod build; +mod cli; mod prelude { pub use crate::book_test::BookTest;