2017-03-24 14:21:17 +00:00
|
|
|
#[macro_use]
|
2015-11-06 20:22:45 +00:00
|
|
|
extern crate difference;
|
|
|
|
extern crate cobalt;
|
2016-10-30 22:25:40 +00:00
|
|
|
extern crate tempdir;
|
2015-11-06 20:22:45 +00:00
|
|
|
extern crate walkdir;
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::Read;
|
2016-10-30 22:25:40 +00:00
|
|
|
use tempdir::TempDir;
|
2015-11-06 20:22:45 +00:00
|
|
|
use walkdir::WalkDir;
|
2015-11-24 18:00:06 +00:00
|
|
|
use std::error::Error;
|
2016-02-17 20:39:44 +00:00
|
|
|
use cobalt::Config;
|
2015-11-06 20:22:45 +00:00
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
fn run_test(name: &str) -> Result<(), cobalt::Error> {
|
2015-11-06 20:22:45 +00:00
|
|
|
let target = format!("tests/target/{}/", name);
|
2016-05-21 17:34:55 +00:00
|
|
|
let mut config = Config::from_file(format!("tests/fixtures/{}/.cobalt.yml", name))
|
2017-01-03 08:44:53 +00:00
|
|
|
.unwrap_or(Default::default());
|
2016-10-30 22:25:40 +00:00
|
|
|
let destdir = TempDir::new(name).expect("Tempdir not created");
|
2015-11-06 20:22:45 +00:00
|
|
|
|
2016-02-17 20:39:44 +00:00
|
|
|
config.source = format!("tests/fixtures/{}/", name);
|
2017-01-03 08:44:53 +00:00
|
|
|
config.dest = destdir.path()
|
|
|
|
.to_str()
|
2016-10-30 22:25:40 +00:00
|
|
|
.expect("Can't convert destdir to str")
|
|
|
|
.to_owned();
|
2016-02-17 20:39:44 +00:00
|
|
|
|
2016-02-18 07:13:59 +00:00
|
|
|
// try to create the target directory, ignore errors
|
2016-05-21 17:34:55 +00:00
|
|
|
fs::create_dir_all(&config.dest).is_ok();
|
2016-02-17 20:39:44 +00:00
|
|
|
|
|
|
|
let result = cobalt::build(&config);
|
2015-11-24 18:00:06 +00:00
|
|
|
|
|
|
|
if result.is_ok() {
|
2016-07-03 08:37:07 +00:00
|
|
|
let walker = WalkDir::new(&target)
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|e| e.ok())
|
|
|
|
.filter(|e| e.file_type().is_file());
|
2015-11-06 20:22:45 +00:00
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
// walk through fixture and created tmp directory and compare files
|
2016-07-03 08:37:07 +00:00
|
|
|
for entry in walker {
|
2016-05-21 17:34:55 +00:00
|
|
|
let relative = entry.path()
|
2017-01-03 08:44:53 +00:00
|
|
|
.strip_prefix(&target)
|
|
|
|
.expect("Comparison error");
|
2015-11-06 20:22:45 +00:00
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
let mut original = String::new();
|
2016-05-21 17:34:55 +00:00
|
|
|
File::open(entry.path())
|
|
|
|
.expect("Comparison error")
|
|
|
|
.read_to_string(&mut original)
|
|
|
|
.expect("Could not read to string");
|
2015-11-06 20:22:45 +00:00
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
let mut created = String::new();
|
2016-02-17 20:39:44 +00:00
|
|
|
File::open(&Path::new(&config.dest).join(&relative))
|
|
|
|
.expect("Comparison error")
|
2015-11-24 18:00:06 +00:00
|
|
|
.read_to_string(&mut created)
|
2016-05-21 17:34:55 +00:00
|
|
|
.expect("Could not read to string");
|
2015-11-06 20:22:45 +00:00
|
|
|
|
2017-03-24 14:21:17 +00:00
|
|
|
assert_diff!(&original, &created, " ", 0);
|
2015-11-24 18:00:06 +00:00
|
|
|
}
|
2016-07-03 08:37:07 +00:00
|
|
|
|
|
|
|
// ensure no unnecessary files were created
|
|
|
|
let walker = WalkDir::new(&config.dest)
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(|e| e.ok())
|
|
|
|
.filter(|e| e.file_type().is_file());
|
|
|
|
|
|
|
|
for entry in walker {
|
|
|
|
let relative = entry.path()
|
2017-01-03 08:44:53 +00:00
|
|
|
.strip_prefix(&config.dest)
|
|
|
|
.expect("Comparison error");
|
2016-07-03 08:37:07 +00:00
|
|
|
let relative = Path::new(&target).join(&relative);
|
|
|
|
|
2017-01-03 08:44:53 +00:00
|
|
|
File::open(&relative).expect(&format!("File {:?} does not exist in reference ({:?}).",
|
|
|
|
entry.path(),
|
|
|
|
relative));
|
2016-07-03 08:37:07 +00:00
|
|
|
}
|
2015-11-06 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 20:39:44 +00:00
|
|
|
// clean up
|
2016-10-30 22:25:40 +00:00
|
|
|
try!(destdir.close());
|
2016-02-17 20:39:44 +00:00
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
result
|
2015-11-06 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-21 17:34:55 +00:00
|
|
|
#[test]
|
|
|
|
pub fn copy_files() {
|
|
|
|
run_test("copy_files").expect("Build error");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn custom_paths() {
|
|
|
|
run_test("custom_paths").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2016-07-03 08:37:07 +00:00
|
|
|
#[test]
|
|
|
|
pub fn custom_posts_folder() {
|
|
|
|
run_test("custom_posts_folder").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2016-07-03 17:33:08 +00:00
|
|
|
#[test]
|
|
|
|
pub fn custom_post_path() {
|
|
|
|
run_test("custom_post_path").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2015-11-06 20:22:45 +00:00
|
|
|
#[test]
|
2016-02-17 20:39:44 +00:00
|
|
|
pub fn dotfiles() {
|
|
|
|
run_test("dotfiles").expect("Build error");
|
2015-11-06 20:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-09 21:04:24 +00:00
|
|
|
#[test]
|
|
|
|
pub fn drafts() {
|
|
|
|
run_test("drafts").expect("Build error");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn drafts_not_shown_by_default() {
|
|
|
|
run_test("drafts_not_shown_by_default").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2015-12-01 01:56:02 +00:00
|
|
|
#[test]
|
2016-02-17 20:39:44 +00:00
|
|
|
pub fn example() {
|
|
|
|
run_test("example").expect("Build error");
|
2015-12-01 01:56:02 +00:00
|
|
|
}
|
|
|
|
|
2016-07-03 08:37:07 +00:00
|
|
|
#[test]
|
|
|
|
pub fn hidden_posts_folder() {
|
|
|
|
run_test("hidden_posts_folder").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2016-03-03 07:45:04 +00:00
|
|
|
#[test]
|
|
|
|
pub fn custom_template_extensions() {
|
|
|
|
run_test("custom_template_extensions").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2017-01-03 08:44:53 +00:00
|
|
|
#[cfg(feature = "syntax-highlight")]
|
|
|
|
#[test]
|
|
|
|
pub fn syntax_highlight() {
|
|
|
|
run_test("syntax_highlight").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2016-01-15 23:41:23 +00:00
|
|
|
#[test]
|
2016-02-17 20:39:44 +00:00
|
|
|
pub fn incomplete_rss() {
|
|
|
|
let err = run_test("incomplete_rss");
|
|
|
|
assert!(err.is_err());
|
2016-11-19 14:56:17 +00:00
|
|
|
|
|
|
|
let err = err.unwrap_err();
|
2017-01-03 08:44:53 +00:00
|
|
|
assert_eq!(format!("{}", err),
|
2016-05-21 17:34:55 +00:00
|
|
|
"name, description and link need to be defined in the config file to generate RSS");
|
2017-01-03 08:44:53 +00:00
|
|
|
assert_eq!(err.description(), "missing fields in config file");
|
2016-01-15 23:41:23 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
#[test]
|
|
|
|
pub fn liquid_error() {
|
|
|
|
let err = run_test("liquid_error");
|
|
|
|
assert!(err.is_err());
|
2016-05-21 17:34:55 +00:00
|
|
|
assert_eq!(err.unwrap_err().description(),
|
|
|
|
"{{{ is not a valid identifier");
|
2015-11-24 18:00:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-04 20:44:03 +00:00
|
|
|
#[test]
|
|
|
|
pub fn liquid_raw() {
|
|
|
|
run_test("liquid_escaped").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2016-01-16 22:10:12 +00:00
|
|
|
#[test]
|
2016-02-17 20:39:44 +00:00
|
|
|
pub fn no_extends_error() {
|
|
|
|
let err = run_test("no_extends_error");
|
2016-01-16 22:10:12 +00:00
|
|
|
assert!(err.is_err());
|
2017-01-03 08:44:53 +00:00
|
|
|
assert!(err.unwrap_err()
|
|
|
|
.description()
|
|
|
|
.contains("Layout default_nonexistent.liquid can not be read (defined in \
|
|
|
|
tests/fixtures/no_extends_error/index.liquid)"));
|
2016-01-16 22:10:12 +00:00
|
|
|
}
|
|
|
|
|
2015-11-24 18:00:06 +00:00
|
|
|
#[test]
|
2016-02-17 20:39:44 +00:00
|
|
|
pub fn sort_posts() {
|
|
|
|
run_test("sort_posts").expect("Build error");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn rss() {
|
|
|
|
run_test("rss").expect("Build error");
|
|
|
|
}
|
|
|
|
|
2016-05-07 15:09:16 +00:00
|
|
|
#[test]
|
|
|
|
pub fn ignore_files() {
|
|
|
|
run_test("ignore_files").unwrap();
|
|
|
|
}
|
|
|
|
|
2016-02-17 20:39:44 +00:00
|
|
|
#[test]
|
|
|
|
pub fn yaml_error() {
|
|
|
|
let err = run_test("yaml_error");
|
2015-11-24 18:00:06 +00:00
|
|
|
assert!(err.is_err());
|
2016-02-17 20:39:44 +00:00
|
|
|
assert_eq!(err.unwrap_err().description(), "unexpected character: `@'");
|
2015-11-24 18:00:06 +00:00
|
|
|
}
|
2016-11-04 20:44:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn excerpts() {
|
|
|
|
run_test("excerpts").unwrap();
|
|
|
|
}
|
2017-02-09 22:50:09 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
pub fn posts_in_subfolder() {
|
|
|
|
run_test("posts_in_subfolder").unwrap();
|
|
|
|
}
|