Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/skeptic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ bytecount = "0.5"
[dev-dependencies]
unindent = "0.1"

[dependencies.error-chain]
version = "0.12"
default-features = false

[dependencies.pulldown-cmark]
version = "0.2"
default-features = false
Expand Down
68 changes: 45 additions & 23 deletions src/skeptic/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[macro_use]
extern crate error_chain;
extern crate pulldown_cmark as cmark;
extern crate tempdir;
extern crate glob;
Expand Down Expand Up @@ -417,11 +415,17 @@ fn emit_tests(config: &Config, suite: DocTestSuite) -> Result<(), IoError> {
/// documentation but include it for the purpose of playground links or skeptic
/// testing.
fn clean_omitted_line(line: &str) -> &str {
let trimmed = line.trim_left();
// XXX To silence depreciation warning of trim_left and not bump rustc
// requirement upto 1.30 (for trim_start) we roll our own trim_left :(
let trimmed = if let Some(pos) = line.find(|c: char| !c.is_whitespace()) {
&line[pos..]
} else {
line
};

if trimmed.starts_with("# ") {
&trimmed[2..]
} else if trimmed.trim_right() == "#" {
} else if line.trim() == "#" {
// line consists of single "#" which might not be followed by newline on windows
&trimmed[1..]
} else {
Expand Down Expand Up @@ -528,12 +532,30 @@ pub mod rt {
use self::walkdir::WalkDir;
use self::serde_json::Value;

error_chain! {
errors { Fingerprint }
foreign_links {
Io(std::io::Error);
Metadata(cargo_metadata::Error);
Json(serde_json::Error);
#[derive(Debug)]
enum SkepticError {
Io(std::io::Error),
Metadata(cargo_metadata::Error),
Json(serde_json::Error),
Fingerprint,
MissingDependencyMeta,
}

impl From<std::io::Error> for SkepticError {
fn from(err: std::io::Error) -> SkepticError {
SkepticError::Io(err)
}
}

impl From<cargo_metadata::Error> for SkepticError {
fn from(err: cargo_metadata::Error) -> SkepticError {
SkepticError::Metadata(err)
}
}

impl From<serde_json::Error> for SkepticError {
fn from(err: serde_json::Error) -> SkepticError {
SkepticError::Json(err)
}
}

Expand All @@ -549,16 +571,16 @@ pub mod rt {
dependencies: Vec<String>,
}

fn get_cargo_meta<P: AsRef<Path>>(pth: P) -> Result<cargo_metadata::Metadata> {
fn get_cargo_meta<P: AsRef<Path>>(pth: P) -> Result<cargo_metadata::Metadata, SkepticError> {
Ok(cargo_metadata::MetadataCommand::new().manifest_path(&pth).exec()?)
}

impl LockedDeps {
fn from_path<P: AsRef<Path>>(pth: P) -> Result<LockedDeps> {
fn from_path<P: AsRef<Path>>(pth: P) -> Result<LockedDeps, SkepticError> {
let pth = pth.as_ref().join("Cargo.toml");
let metadata = get_cargo_meta(&pth)?;
let workspace_members = metadata.workspace_members;
let deps = metadata.resolve.ok_or("Missing dependency metadata")?
let deps = metadata.resolve.ok_or(SkepticError::MissingDependencyMeta)?
.nodes
.into_iter()
.filter(|node| workspace_members.contains(&node.id))
Expand Down Expand Up @@ -594,32 +616,32 @@ pub mod rt {
mtime: SystemTime,
}

fn guess_ext(mut pth: PathBuf, exts: &[&str]) -> Result<PathBuf> {
fn guess_ext(mut pth: PathBuf, exts: &[&str]) -> Result<PathBuf, SkepticError> {
for ext in exts {
pth.set_extension(ext);
if pth.exists() {
return Ok(pth);
}
}
Err(ErrorKind::Fingerprint.into())
Err(SkepticError::Fingerprint.into())
}

impl Fingerprint {
fn from_path<P: AsRef<Path>>(pth: P) -> Result<Fingerprint> {
fn from_path<P: AsRef<Path>>(pth: P) -> Result<Fingerprint, SkepticError> {
let pth = pth.as_ref();

let fname = pth.file_stem().and_then(OsStr::to_str).ok_or(
ErrorKind::Fingerprint,
SkepticError::Fingerprint,
)?;

pth.extension()
.and_then(|e| if e == "json" { Some(e) } else { None })
.ok_or(ErrorKind::Fingerprint)?;
.ok_or(SkepticError::Fingerprint)?;

let mut captures = fname.splitn(3, '-');
captures.next();
let libname = captures.next().ok_or(ErrorKind::Fingerprint)?;
let hash = captures.next().ok_or(ErrorKind::Fingerprint)?;
let libname = captures.next().ok_or(SkepticError::Fingerprint)?;
let hash = captures.next().ok_or(SkepticError::Fingerprint)?;

let mut rlib = PathBuf::from(pth);
rlib.pop();
Expand Down Expand Up @@ -654,7 +676,7 @@ pub mod rt {
}
}

fn get_edition<P: AsRef<Path>>(path: P) -> Result<String> {
fn get_edition<P: AsRef<Path>>(path: P) -> Result<String, SkepticError> {
let path = path.as_ref().join("Cargo.toml");
let metadata = get_cargo_meta(&path)?;
let edition = metadata.packages.iter()
Expand All @@ -670,7 +692,7 @@ pub mod rt {
fn get_rlib_dependencies<P: AsRef<Path>>(
root_dir: P,
target_dir: P,
) -> Result<Vec<Fingerprint>> {
) -> Result<Vec<Fingerprint>, SkepticError> {
let root_dir = root_dir.as_ref();
let target_dir = target_dir.as_ref();
let lock = LockedDeps::from_path(root_dir).or_else(
Expand Down Expand Up @@ -800,7 +822,7 @@ pub mod rt {
if edition != "2015" {
cmd.arg(format!("--edition={}", edition));
}

cmd.arg("-L")
.arg(&target_dir)
.arg("-L")
Expand Down