@@ -4,6 +4,7 @@ use crate::prelude::*;
44use mdbook:: errors:: Result ;
55use mdbook:: renderer:: { RenderContext , Renderer } ;
66use snapbox:: IntoData ;
7+ use std:: env;
78use std:: fs:: File ;
89use 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]
80124fn missing_renderer ( ) {
0 commit comments