@@ -7,7 +7,6 @@ use rustc_span::edition::Edition;
77use rustc_span:: source_map:: DUMMY_SP ;
88
99use crate :: config:: { Options , RenderOptions } ;
10- use crate :: externalfiles:: { load_string, LoadStringError } ;
1110use crate :: html:: escape:: Escape ;
1211use crate :: html:: markdown;
1312use crate :: html:: markdown:: { find_testable_code, ErrorCodes , IdMap , Markdown , MarkdownWithToc } ;
@@ -116,13 +115,9 @@ pub fn render<P: AsRef<Path>>(
116115}
117116
118117/// Runs any tests/code examples in the markdown file `input`.
119- pub fn test ( mut options : Options , diag : & rustc_errors:: Handler ) -> i32 {
120- let input_str = match load_string ( & options. input , diag) {
121- Ok ( s) => s,
122- Err ( LoadStringError :: ReadFail ) => return 1 ,
123- Err ( LoadStringError :: BadUtf8 ) => return 2 ,
124- } ;
125-
118+ pub fn test ( mut options : Options ) -> Result < ( ) , String > {
119+ let input_str = read_to_string ( & options. input )
120+ . map_err ( |err| format ! ( "{}: {}" , options. input. display( ) , err) ) ?;
126121 let mut opts = TestOptions :: default ( ) ;
127122 opts. no_crate_inject = true ;
128123 opts. display_warnings = options. display_warnings ;
@@ -146,5 +141,5 @@ pub fn test(mut options: Options, diag: &rustc_errors::Handler) -> i32 {
146141 collector. tests ,
147142 Some ( testing:: Options :: new ( ) . display_output ( options. display_warnings ) ) ,
148143 ) ;
149- 0
144+ Ok ( ( ) )
150145}
0 commit comments