mdBook/tests/config.rs

55 lines
1.9 KiB
Rust
Raw Normal View History

2017-05-20 19:00:47 +08:00
extern crate mdbook;
extern crate tempdir;
use std::fs::File;
use std::io::Write;
use mdbook::MDBook;
use tempdir::TempDir;
// Tests that config values unspecified in the configuration file do not
// overwrite
2017-05-20 19:00:47 +08:00
// values specified earlier.
#[test]
2017-07-09 03:50:11 +08:00
#[ignore]
2017-05-20 19:00:47 +08:00
fn do_not_overwrite_unspecified_config_values() {
2017-07-09 03:50:11 +08:00
// FIXME: This entire test needs to be rewritten to reflect the new builder
// semantics
// This is because the `MDBook` given to you by the builder isn't mutable
// so changing config settings after it's created may or may not be desired
2017-05-20 19:00:47 +08:00
let dir = TempDir::new("mdbook").expect("Could not create a temp dir");
let book = MDBook::init(dir.path())
.unwrap()
.with_source("bar")
.with_destination("baz")
.with_mathjax_support(true);
2017-05-20 19:00:47 +08:00
assert_eq!(book.get_root(), dir.path());
assert_eq!(book.get_source(), dir.path().join("bar"));
assert_eq!(book.get_destination(), dir.path().join("baz"));
2017-05-20 19:00:47 +08:00
2017-07-09 03:50:11 +08:00
// // Test when trying to read a config file that does not exist
// let book = book.expect("Error reading the config file");
2017-05-20 19:00:47 +08:00
2017-07-09 03:50:11 +08:00
// assert_eq!(book.get_root(), dir.path());
// assert_eq!(book.get_source(), dir.path().join("bar"));
// assert_eq!(book.get_destination(), dir.path().join("baz"));
// assert_eq!(book.get_mathjax_support(), true);
2017-05-20 19:00:47 +08:00
2017-07-09 03:50:11 +08:00
// // Try with a partial config file
// let file_path = dir.path().join("book.toml");
// let mut f = File::create(file_path).expect("Could not create config file");
// f.write_all(br#"source = "barbaz""#).expect(
// "Could not write to config file",
// );
// f.sync_all().expect("Could not sync the file");
2017-05-20 19:00:47 +08:00
2017-07-09 03:50:11 +08:00
// let book = book.read_config().expect("Error reading the config file");
2017-05-20 19:00:47 +08:00
2017-07-09 03:50:11 +08:00
// assert_eq!(book.get_root(), dir.path());
// assert_eq!(book.get_source(), dir.path().join("barbaz"));
// assert_eq!(book.get_destination(), dir.path().join("baz"));
// assert_eq!(book.get_mathjax_support(), true);
2017-05-20 19:00:47 +08:00
}