1 //! Integration tests to make sure alternative backends work.
3 use mdbook
::config
::Config
;
7 use tempfile
::{Builder as TempFileBuilder, TempDir}
;
10 fn passing_alternate_backend() {
11 let (md
, _temp
) = dummy_book_with_backend("passing", success_cmd(), false);
17 fn failing_alternate_backend() {
18 let (md
, _temp
) = dummy_book_with_backend("failing", fail_cmd(), false);
20 md
.build().unwrap_err();
24 fn missing_backends_are_fatal() {
25 let (md
, _temp
) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn", false);
26 assert
!(md
.build().is_err());
30 fn missing_optional_backends_are_not_fatal() {
31 let (md
, _temp
) = dummy_book_with_backend("missing", "trduyvbhijnorgevfuhn", true);
32 assert
!(md
.build().is_ok());
36 fn alternate_backend_with_arguments() {
37 let (md
, _temp
) = dummy_book_with_backend("arguments", "echo Hello World!", false);
42 /// Get a command which will pipe `stdin` to the provided file.
44 fn tee_command
<P
: AsRef
<Path
>>(out_file
: P
) -> String
{
45 let out_file
= out_file
.as_ref();
48 format
!("cmd.exe /c \"type > {}\"", out_file
.display())
50 format
!("tee {}", out_file
.display())
56 fn backends_receive_render_context_via_stdin() {
57 use mdbook
::renderer
::RenderContext
;
60 let temp
= TempFileBuilder
::new().prefix("output").tempdir().unwrap();
61 let out_file
= temp
.path().join("out.txt");
62 let cmd
= tee_command(&out_file
);
64 let (md
, _temp
) = dummy_book_with_backend("cat-to-file", &cmd
, false);
66 assert
!(!out_file
.exists());
68 assert
!(out_file
.exists());
70 let got
= RenderContext
::from_json(File
::open(&out_file
).unwrap());
74 fn dummy_book_with_backend(
77 backend_is_optional
: bool
,
78 ) -> (MDBook
, TempDir
) {
79 let temp
= TempFileBuilder
::new().prefix("mdbook").tempdir().unwrap();
81 let mut config
= Config
::default();
83 .set(format
!("output.{}.command", name
), command
)
86 if backend_is_optional
{
88 .set(format
!("output.{}.optional", name
), true)
92 let md
= MDBook
::init(temp
.path())
100 fn fail_cmd() -> &'
static str {
102 r
#"cmd.exe /c "exit 1""#
108 fn success_cmd() -> &'
static str {
110 r
#"cmd.exe /c "exit 0""#