Migrate alternate_backend_with_arguments to BookTest

This commit is contained in:
Eric Huss 2025-04-21 19:44:23 -07:00
parent f482aeaca3
commit 82000d917f
4 changed files with 34 additions and 7 deletions

View file

@ -6,13 +6,6 @@ use std::fs;
use std::path::Path;
use tempfile::{Builder as TempFileBuilder, TempDir};
#[test]
fn alternate_backend_with_arguments() {
let (md, _temp) = dummy_book_with_backend("arguments", "echo Hello World!", false);
md.build().unwrap();
}
#[test]
fn backends_receive_render_context_via_stdin() {
use mdbook::renderer::RenderContext;

View file

@ -105,3 +105,34 @@ fn missing_optional_not_fatal() {
"#]]);
});
}
// Command can include arguments.
#[test]
fn renderer_with_arguments() {
BookTest::from_dir("renderer/renderer_with_arguments")
.rust_program(
"arguments",
r#"
fn main() {
let args: Vec<_> = std::env::args().skip(1).collect();
assert_eq!(args, &["arg1", "arg2"]);
println!("Hello World!");
use std::io::Read;
let mut s = String::new();
std::io::stdin().read_to_string(&mut s).unwrap();
}
"#,
)
.run("build", |cmd| {
cmd.expect_stdout(str![[r#"
Hello World!
"#]])
.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the arguments backend
[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "arguments" renderer
"#]]);
});
}

View file

@ -0,0 +1,3 @@
[output.arguments]
command = "./arguments arg1 arg2"