From 435926bdfea900f1a2f2175f082f2c5a6782529f Mon Sep 17 00:00:00 2001 From: Bastien Orivel Date: Wed, 11 Apr 2018 17:46:00 +0200 Subject: [PATCH] tests: Replace skeptic by some custom logic code and rustdoc calls Unfortunately skeptic pulls all its dependencies in projects using lettre (see https://github.com/budziq/rust-skeptic/issues/60). --- lettre/Cargo.toml | 6 +--- lettre/build.rs | 8 ------ lettre/tests/skeptic.rs | 63 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 63 insertions(+), 14 deletions(-) delete mode 100644 lettre/build.rs diff --git a/lettre/Cargo.toml b/lettre/Cargo.toml index 42bcd9de0..c80ca9bd0 100644 --- a/lettre/Cargo.toml +++ b/lettre/Cargo.toml @@ -10,7 +10,6 @@ license = "MIT" authors = ["Alexis Mousset "] categories = ["email"] keywords = ["email", "smtp", "mailer"] -build = "build.rs" [badges] travis-ci = { repository = "lettre/lettre" } @@ -30,10 +29,7 @@ serde_derive = { version = "^1.0", optional = true } [dev-dependencies] env_logger = "^0.5" -skeptic = "^0.13" - -[build-dependencies] -skeptic = "^0.13" +glob = "0.2" [features] default = ["file-transport", "crammd5-auth", "smtp-transport", "sendmail-transport"] diff --git a/lettre/build.rs b/lettre/build.rs deleted file mode 100644 index 11b048d64..000000000 --- a/lettre/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -extern crate skeptic; - -use skeptic::*; - -fn main() { - let mdbook_files = markdown_files_of_directory("../website/content/sending-messages/"); - generate_doc_tests(&mdbook_files); -} diff --git a/lettre/tests/skeptic.rs b/lettre/tests/skeptic.rs index ff46c9c01..ed6fbe85b 100644 --- a/lettre/tests/skeptic.rs +++ b/lettre/tests/skeptic.rs @@ -1 +1,62 @@ -include!(concat!(env!("OUT_DIR"), "/skeptic-tests.rs")); +extern crate glob; + +use self::glob::glob; +use std::env::consts::EXE_EXTENSION; +use std::env; +use std::path::Path; +use std::process::Command; + +#[test] +fn test_readme() { + let readme = Path::new(file!()) + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .join("README.md"); + + skeptic_test(&readme); +} + +#[test] +fn book_test() { + let mut book_path = env::current_dir().unwrap(); + book_path.push( + Path::new(file!()) + .parent() + .unwrap() + .parent() + .unwrap() + .parent() + .unwrap() + .join("../website/content/sending-messages"), + ); // For some reasons, calling .parent() once more gives us None... + + for md in glob(&format!("{}/*.md", book_path.to_str().unwrap())).unwrap() { + skeptic_test(&md.unwrap()); + } +} + +fn skeptic_test(path: &Path) { + let rustdoc = Path::new("rustdoc").with_extension(EXE_EXTENSION); + let exe = env::current_exe().unwrap(); + let depdir = exe.parent().unwrap(); + + let mut cmd = Command::new(rustdoc); + cmd.args(&["--verbose", "--test"]) + .arg("-L") + .arg(&depdir) + .arg(path); + + let result = cmd.spawn() + .expect("Failed to spawn process") + .wait() + .expect("Failed to run process"); + + assert!( + result.success(), + "Failed to run rustdoc tests on README.md!" + ); +}