Skip to content

Commit 0ecba25

Browse files
Add test to check that renderer utilizes PATH
1 parent 74544f0 commit 0ecba25

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/testsuite/renderer.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::prelude::*;
44
use mdbook::errors::Result;
55
use mdbook::renderer::{RenderContext, Renderer};
66
use snapbox::IntoData;
7+
use std::env;
78
use std::fs::File;
89
use std::sync::{Arc, Mutex};
910

@@ -75,6 +76,49 @@ fn failing_command() {
7576
});
7677
}
7778

79+
// Test that renderer utilizes PATH to find mdbook-FOO executables.
80+
#[test]
81+
fn renderer_utilizes_path() {
82+
let mut test = BookTest::init(|_| {});
83+
test.rust_program(
84+
"custom_directory/mdbook-in_path",
85+
r#"
86+
fn main() {
87+
// Read from stdin to avoid random pipe failures on Linux.
88+
use std::io::Read;
89+
let mut s = String::new();
90+
std::io::stdin().read_to_string(&mut s).unwrap();
91+
println!("Hello World!");
92+
}
93+
"#,
94+
)
95+
.change_file(
96+
"book.toml",
97+
"[output.in_path]\n\
98+
",
99+
);
100+
let custom_directory_location = test.dir.join("custom_directory");
101+
102+
test.run("build", |cmd| {
103+
let current_path = env::var("PATH").unwrap_or_default();
104+
let mut paths = env::split_paths(&current_path).collect::<Vec<_>>();
105+
paths.insert(0, custom_directory_location.clone());
106+
let new_path = env::join_paths(paths).unwrap();
107+
cmd.env("PATH", new_path.into_string().unwrap());
108+
109+
cmd.expect_stdout(str![[r#"
110+
Hello World!
111+
112+
"#]])
113+
.expect_stderr(str![[r#"
114+
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
115+
[TIMESTAMP] [INFO] (mdbook::book): Running the in_path backend
116+
[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "in_path" renderer
117+
118+
"#]]);
119+
});
120+
}
121+
78122
// Renderer command is missing.
79123
#[test]
80124
fn missing_renderer() {

0 commit comments

Comments
 (0)