Merge pull request #2801 from HollowMan6/btreemap
Keep preprocessors/backends execution order deterministic
This commit is contained in:
commit
29ae40c3ec
2 changed files with 38 additions and 8 deletions
|
|
@ -48,7 +48,7 @@ use crate::utils::log_backtrace;
|
||||||
use anyhow::{Context, Error, Result, bail};
|
use anyhow::{Context, Error, Result, bail};
|
||||||
use log::{debug, trace};
|
use log::{debug, trace};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
@ -214,7 +214,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration for all preprocessors.
|
/// Returns the configuration for all preprocessors.
|
||||||
pub fn preprocessors<'de, T: Deserialize<'de>>(&self) -> Result<HashMap<String, T>> {
|
pub fn preprocessors<'de, T: Deserialize<'de>>(&self) -> Result<BTreeMap<String, T>> {
|
||||||
self.preprocessor
|
self.preprocessor
|
||||||
.clone()
|
.clone()
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|
@ -222,7 +222,7 @@ impl Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the configuration for all renderers.
|
/// Returns the configuration for all renderers.
|
||||||
pub fn outputs<'de, T: Deserialize<'de>>(&self) -> Result<HashMap<String, T>> {
|
pub fn outputs<'de, T: Deserialize<'de>>(&self) -> Result<BTreeMap<String, T>> {
|
||||||
self.output
|
self.output
|
||||||
.clone()
|
.clone()
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|
|
||||||
|
|
@ -47,12 +47,10 @@ fn config_defaults_to_link_and_index_preprocessor_if_not_set() {
|
||||||
// make sure we haven't got anything in the `preprocessor` table
|
// make sure we haven't got anything in the `preprocessor` table
|
||||||
assert!(cfg.preprocessors::<toml::Value>().unwrap().is_empty());
|
assert!(cfg.preprocessors::<toml::Value>().unwrap().is_empty());
|
||||||
|
|
||||||
let got = determine_preprocessors(&cfg, Path::new(""));
|
let got = determine_preprocessors(&cfg, Path::new("")).unwrap();
|
||||||
|
|
||||||
assert!(got.is_ok());
|
let names: Vec<_> = got.values().map(|p| p.name()).collect();
|
||||||
assert_eq!(got.as_ref().unwrap().len(), 2);
|
assert_eq!(names, ["index", "links"]);
|
||||||
assert_eq!(got.as_ref().unwrap()[0].name(), "index");
|
|
||||||
assert_eq!(got.as_ref().unwrap()[1].name(), "links");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -252,3 +250,35 @@ fn preprocessor_should_run_falls_back_to_supports_renderer_method() {
|
||||||
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg).unwrap();
|
let got = preprocessor_should_run(&BoolPreprocessor(should_be), &html, &cfg).unwrap();
|
||||||
assert_eq!(got, should_be);
|
assert_eq!(got, should_be);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default is to sort preprocessors alphabetically.
|
||||||
|
#[test]
|
||||||
|
fn preprocessor_sorted_by_name() {
|
||||||
|
let cfg_str = r#"
|
||||||
|
[preprocessor.xyz]
|
||||||
|
[preprocessor.abc]
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let cfg = Config::from_str(cfg_str).unwrap();
|
||||||
|
|
||||||
|
let got = determine_preprocessors(&cfg, Path::new("")).unwrap();
|
||||||
|
|
||||||
|
let names: Vec<_> = got.values().map(|p| p.name()).collect();
|
||||||
|
assert_eq!(names, ["abc", "index", "links", "xyz"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default is to sort renderers alphabetically.
|
||||||
|
#[test]
|
||||||
|
fn renderers_sorted_by_name() {
|
||||||
|
let cfg_str = r#"
|
||||||
|
[output.xyz]
|
||||||
|
[output.abc]
|
||||||
|
"#;
|
||||||
|
|
||||||
|
let cfg = Config::from_str(cfg_str).unwrap();
|
||||||
|
|
||||||
|
let got = determine_renderers(&cfg).unwrap();
|
||||||
|
|
||||||
|
let names: Vec<_> = got.values().map(|p| p.name()).collect();
|
||||||
|
assert_eq!(names, ["abc", "xyz"]);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue