File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,13 @@ impl<'a> FakeRelease<'a> {
231231 self
232232 }
233233
234+ pub ( crate ) fn target_source ( mut self , path : & ' a str ) -> Self {
235+ if let Some ( target) = self . package . targets . first_mut ( ) {
236+ target. src_path = Some ( path. into ( ) ) ;
237+ }
238+ self
239+ }
240+
234241 pub ( crate ) fn no_cargo_toml ( mut self ) -> Self {
235242 self . no_cargo_toml = true ;
236243 self
@@ -503,6 +510,7 @@ impl<'a> FakeRelease<'a> {
503510 if let Some ( markdown) = self . readme {
504511 fs:: write ( crate_dir. join ( "README.md" ) , markdown) ?;
505512 }
513+ store_files_into ( & self . source_files , crate_dir) ?;
506514
507515 // Many tests rely on the default-target being linux, so it should not
508516 // be set to docsrs_metadata::HOST_TARGET, because then tests fail on all
Original file line number Diff line number Diff line change @@ -2187,6 +2187,61 @@ mod tests {
21872187 } ) ;
21882188 }
21892189
2190+ #[ test]
2191+ fn no_readme ( ) {
2192+ async_wrapper ( |env| async move {
2193+ env. fake_release ( )
2194+ . await
2195+ . name ( "dummy" )
2196+ . version ( "0.2.0" )
2197+ . source_file (
2198+ "Cargo.toml" ,
2199+ br#"[package]
2200+ name = "dummy"
2201+ version = "0.2.0"
2202+
2203+ [lib]
2204+ name = "dummy"
2205+ path = "src/lib.rs"
2206+ "# ,
2207+ )
2208+ . source_file (
2209+ "src/lib.rs" ,
2210+ b"//! # Crate-level docs
2211+ //!
2212+ //! ```
2213+ //! let x = 21;
2214+ //! ```
2215+ " ,
2216+ )
2217+ . target_source ( "src/lib.rs" )
2218+ . create ( )
2219+ . await ?;
2220+
2221+ let web = env. web_app ( ) . await ;
2222+ let response = web. get ( "/crate/dummy/0.2.0" ) . await ?;
2223+ assert ! ( response. status( ) . is_success( ) ) ;
2224+
2225+ let dom = kuchikiki:: parse_html ( ) . one ( response. text ( ) . await ?) ;
2226+ dom. select_first ( "#main" ) . expect ( "not main crate docs" ) ;
2227+ // First we check that the crate-level docs have been rendered as expected.
2228+ assert_eq ! (
2229+ dom. select_first( "#main h1" )
2230+ . expect( "no h1 found" )
2231+ . text_contents( ) ,
2232+ "Crate-level docs"
2233+ ) ;
2234+ // Then we check that by default, the language used for highlighting is rust.
2235+ assert_eq ! (
2236+ dom. select_first( "#main pre .syntax-source.syntax-rust" )
2237+ . expect( "no rust code block found" )
2238+ . text_contents( ) ,
2239+ "let x = 21;\n "
2240+ ) ;
2241+ Ok ( ( ) )
2242+ } ) ;
2243+ }
2244+
21902245 #[ test]
21912246 fn test_crate_name_with_other_uri_chars ( ) {
21922247 async_wrapper ( |env| async move {
You can’t perform that action at this time.
0 commit comments