Fix test using create_missing
This commit is contained in:
parent
282fdaa3ac
commit
e17ce64f2b
@ -404,7 +404,10 @@ fn load_chapter<P: AsRef<Path>>(
|
|||||||
if !location.exists() && !link_location.is_absolute() {
|
if !location.exists() && !link_location.is_absolute() {
|
||||||
src_dir = src_dir_fallback;
|
src_dir = src_dir_fallback;
|
||||||
location = src_dir.join(link_location);
|
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 {
|
if !location.exists() && cfg.build.create_missing {
|
||||||
create_missing(&location, &link)
|
create_missing(&location, &link)
|
||||||
@ -586,7 +589,10 @@ more text.
|
|||||||
fn cant_load_a_nonexistent_chapter() {
|
fn cant_load_a_nonexistent_chapter() {
|
||||||
let link = Link::new("Chapter 1", "/foo/bar/baz.md");
|
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());
|
assert!(got.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +188,8 @@ async fn serve(
|
|||||||
// Redirect root to the default translation directory, if serving a localized book.
|
// 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.
|
// 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,
|
// 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)
|
let index_for_language = format!("/{}/index.html", lang_ident)
|
||||||
.parse::<Uri>()
|
.parse::<Uri>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -211,6 +212,7 @@ async fn serve(
|
|||||||
// The fallback route for 404 errors
|
// The fallback route for 404 errors
|
||||||
let fallback_route = warp::fs::file(build_dir.join(file_404))
|
let fallback_route = warp::fs::file(build_dir.join(file_404))
|
||||||
.map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND));
|
.map(|reply| warp::reply::with_status(reply, warp::http::StatusCode::NOT_FOUND));
|
||||||
|
|
||||||
let routes = livereload.or(book_route).or(fallback_route);
|
let routes = livereload.or(book_route).or(fallback_route);
|
||||||
warp::serve(routes).run(address).await;
|
warp::serve(routes).run(address).await;
|
||||||
};
|
};
|
||||||
|
@ -297,9 +297,9 @@ impl Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the fallback source directory of a book. For example, if chapters
|
/// Get the fallback source directory of a book. If chapters/sections are
|
||||||
/// are missing in a localization, the links will gracefully degrade to the
|
/// missing in a localization, any links to them will gracefully degrade to
|
||||||
/// files that exist in this directory.
|
/// the files that exist in this directory.
|
||||||
pub fn get_fallback_src_path(&self) -> PathBuf {
|
pub fn get_fallback_src_path(&self) -> PathBuf {
|
||||||
match self.language.default_language() {
|
match self.language.default_language() {
|
||||||
// Languages have been specified, assume directory structure with
|
// Languages have been specified, assume directory structure with
|
||||||
@ -417,7 +417,7 @@ impl<'de> Deserialize<'de> for Config {
|
|||||||
|
|
||||||
if default_languages != 1 {
|
if default_languages != 1 {
|
||||||
return Err(D::Error::custom(
|
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<String, Language>);
|
|||||||
pub struct Language {
|
pub struct Language {
|
||||||
/// Human-readable name of the language.
|
/// Human-readable name of the language.
|
||||||
pub name: String,
|
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.
|
/// language in the config.
|
||||||
pub default: bool,
|
pub default: bool,
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use mdbook::MDBook;
|
|||||||
#[test]
|
#[test]
|
||||||
fn mdbook_can_correctly_test_a_passing_book() {
|
fn mdbook_can_correctly_test_a_passing_book() {
|
||||||
let temp = DummyBook::new().with_passing_test(true).build().unwrap();
|
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![]);
|
let result = md.test(vec![]);
|
||||||
assert!(
|
assert!(
|
||||||
@ -20,7 +20,7 @@ fn mdbook_can_correctly_test_a_passing_book() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn mdbook_detects_book_with_failing_tests() {
|
fn mdbook_detects_book_with_failing_tests() {
|
||||||
let temp = DummyBook::new().with_passing_test(false).build().unwrap();
|
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());
|
assert!(md.test(vec![]).is_err());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user