@@ -95,3 +95,56 @@ fn example_doesnt_support_not_supported() {
9595
9696 assert_eq ! ( got, false ) ;
9797}
98+
99+ // Checks the behavior of a relative path to a preprocessor.
100+ #[ test]
101+ fn relative_command_path ( ) {
102+ let mut test = BookTest :: init ( |_| { } ) ;
103+ test. rust_program (
104+ "preprocessors/my-preprocessor" ,
105+ r#"
106+ fn main() {
107+ let mut args = std::env::args().skip(1);
108+ if args.next().as_deref() == Some("supports") {
109+ std::fs::write("support-check", args.next().unwrap()).unwrap();
110+ return;
111+ }
112+ use std::io::Read;
113+ let mut s = String::new();
114+ std::io::stdin().read_to_string(&mut s).unwrap();
115+ std::fs::write("preprocessor-ran", "test").unwrap();
116+ println!("{{\"sections\": []}}");
117+ }
118+ "# ,
119+ )
120+ . change_file (
121+ "book.toml" ,
122+ "[preprocessor.my-preprocessor]\n \
123+ command = 'preprocessors/my-preprocessor'\n ",
124+ )
125+ . run ( "build" , |cmd| {
126+ cmd. expect_stdout ( str![ "" ] ) . expect_stderr ( str![ [ r#"
127+ [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
128+ [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend
129+ [TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
130+
131+ "# ] ] ) ;
132+ } )
133+ . check_file ( "support-check" , "html" )
134+ . check_file ( "preprocessor-ran" , "test" )
135+ // Try again, but outside of the book root to check relative path behavior.
136+ . rm_r ( "support-check" )
137+ . rm_r ( "preprocessor-ran" )
138+ . run ( "build .." , |cmd| {
139+ cmd. current_dir ( cmd. dir . join ( "src" ) )
140+ . expect_stdout ( str![ "" ] )
141+ . expect_stderr ( str![ [ r#"
142+ [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
143+ [TIMESTAMP] [WARN] (mdbook_driver::builtin_preprocessors::cmd): The command wasn't found, is the "my-preprocessor" preprocessor installed?
144+ [TIMESTAMP] [WARN] (mdbook_driver::builtin_preprocessors::cmd): [TAB]Command: preprocessors/my-preprocessor
145+ [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend
146+ [TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/src/../book`
147+
148+ "# ] ] ) ;
149+ } ) ;
150+ }
0 commit comments