From e17ce64f2bea394dfc834b2476b9f0b3d7383d9e Mon Sep 17 00:00:00 2001 From: Ruin0x11 Date: Fri, 28 Aug 2020 02:29:07 -0700 Subject: [PATCH] Fix test using create_missing --- src/book/book.rs | 10 ++++++++-- src/cmd/serve.rs | 4 +++- src/config.rs | 10 +++++----- tests/testing.rs | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/book/book.rs b/src/book/book.rs index 7998b704..af23e785 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -404,7 +404,10 @@ fn load_chapter>( if !location.exists() && !link_location.is_absolute() { src_dir = src_dir_fallback; location = src_dir.join(link_location); - debug!("Falling back to {}", location.display()); + debug!( + "Falling back to default translation in path \"{}\"", + location.display() + ); } if !location.exists() && cfg.build.create_missing { create_missing(&location, &link) @@ -586,7 +589,10 @@ more text. fn cant_load_a_nonexistent_chapter() { let link = Link::new("Chapter 1", "/foo/bar/baz.md"); - let got = load_chapter(&link, "", "", Vec::new(), &Config::default()); + let mut cfg = Config::default(); + cfg.build.create_missing = false; + + let got = load_chapter(&link, "", "", Vec::new(), &cfg); assert!(got.is_err()); } diff --git a/src/cmd/serve.rs b/src/cmd/serve.rs index f1a09f74..d18d3388 100644 --- a/src/cmd/serve.rs +++ b/src/cmd/serve.rs @@ -188,7 +188,8 @@ async fn serve( // Redirect root to the default translation directory, if serving a localized book. // NOTE: This can't be `/{lang_ident}`, or the static assets won't get loaded. // BUG: Redirects get cached if you change the --language parameter, - // meaning you'll get a 404 unless you disable cache in the developer tools. + // meaning you'll get a 404 unless you disable the cache in Developer + // Tools. let index_for_language = format!("/{}/index.html", lang_ident) .parse::() .unwrap(); @@ -211,6 +212,7 @@ async fn serve( // The fallback route for 404 errors let fallback_route = warp::fs::file(build_dir.join(file_404)) .map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND)); + let routes = livereload.or(book_route).or(fallback_route); warp::serve(routes).run(address).await; }; diff --git a/src/config.rs b/src/config.rs index 68875c1d..fa49677c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -297,9 +297,9 @@ impl Config { } } - /// Get the fallback source directory of a book. For example, if chapters - /// are missing in a localization, the links will gracefully degrade to the - /// files that exist in this directory. + /// Get the fallback source directory of a book. If chapters/sections are + /// missing in a localization, any links to them will gracefully degrade to + /// the files that exist in this directory. pub fn get_fallback_src_path(&self) -> PathBuf { match self.language.default_language() { // Languages have been specified, assume directory structure with @@ -417,7 +417,7 @@ impl<'de> Deserialize<'de> for Config { if default_languages != 1 { return Err(D::Error::custom( - "If languages are specified, exactly one must be set as 'default'", + "If [languages] table is specified, exactly one entry must be set as 'default'", )); } } @@ -784,7 +784,7 @@ pub struct LanguageConfig(pub HashMap); pub struct Language { /// Human-readable name of the language. pub name: String, - /// If true, this language is the default. There can only be one default + /// If true, this language is the default. There must be exactly one default /// language in the config. pub default: bool, } diff --git a/tests/testing.rs b/tests/testing.rs index 2b2c0fd0..51e23d82 100644 --- a/tests/testing.rs +++ b/tests/testing.rs @@ -7,7 +7,7 @@ use mdbook::MDBook; #[test] fn mdbook_can_correctly_test_a_passing_book() { let temp = DummyBook::new().with_passing_test(true).build().unwrap(); - let mut md = MDBook::load(temp.path()).unwrap(); + let md = MDBook::load(temp.path()).unwrap(); let result = md.test(vec![]); assert!( @@ -20,7 +20,7 @@ fn mdbook_can_correctly_test_a_passing_book() { #[test] fn mdbook_detects_book_with_failing_tests() { let temp = DummyBook::new().with_passing_test(false).build().unwrap(); - let mut md = MDBook::load(temp.path()).unwrap(); + let md = MDBook::load(temp.path()).unwrap(); assert!(md.test(vec![]).is_err()); }