diff --git a/src/lib.rs b/src/lib.rs index 1088d1c..b7b92cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,9 @@ extern crate url; extern crate walkdir; use filetime::set_file_times; -use walkdir::{WalkDir}; +use walkdir::WalkDir; +use std::cell::RefCell; use std::convert; use std::env; use std::error::Error as ErrorTrait; @@ -18,7 +19,6 @@ use std::fs::{self, File}; use std::io::{self, Read, Write}; use std::ops; use std::path::{Path, PathBuf}; -use std::cell::RefCell; use self::timestamp::{Timestamp, Timestamped}; @@ -37,15 +37,11 @@ thread_local! { } fn set_lit_dir(directory: String) { - LIT_DIR.with(|lit_dir| { - *lit_dir.borrow_mut() = directory - }); + LIT_DIR.with(|lit_dir| *lit_dir.borrow_mut() = directory); } fn set_src_dir(directory: String) { - SRC_DIR.with(|src_dir| { - *src_dir.borrow_mut() = directory - }); + SRC_DIR.with(|src_dir| *src_dir.borrow_mut() = directory); } /// Returns the current directory for storing the literate .md files @@ -84,31 +80,39 @@ impl Config { self.rerun_if = true; self } - } - #[derive(Debug)] pub enum Error { IoError(io::Error), - CheckInputError { error: check::Error }, + CheckInputError { + error: check::Error, + }, MtimeError(PathBuf), - ConcurrentUpdate { path_buf: PathBuf, old_time: mtime, new_time: mtime }, + ConcurrentUpdate { + path_buf: PathBuf, + old_time: mtime, + new_time: mtime, + }, Warnings(Vec), } #[derive(Debug)] pub enum Warning { - EncodedUrlMismatch { actual: String, expect: String } + EncodedUrlMismatch { actual: String, expect: String }, } impl fmt::Display for Warning { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { match *self { - Warning::EncodedUrlMismatch { ref actual, ref expect } => { - write!(w, "mismatch between encoded url, expect: {} actual: {}", - expect, actual) - } + Warning::EncodedUrlMismatch { + ref actual, + ref expect, + } => write!( + w, + "mismatch between encoded url, expect: {} actual: {}", + expect, actual + ), } } } @@ -125,16 +129,18 @@ impl From for Error { impl fmt::Display for Error { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { match *self { - Error::IoError(_) => - write!(w, "IO error running `tango`"), - Error::CheckInputError { .. } => - write!(w, "input check errors running `tango`"), - Error::MtimeError(ref p) => - write!(w, "modification time error from `tango` checking {}", - p.to_string_lossy()), - Error::ConcurrentUpdate { ref path_buf, .. } => - write!(w, "concurrent update during `tango` to source file {}", - path_buf.to_string_lossy()), + Error::IoError(_) => write!(w, "IO error running `tango`"), + Error::CheckInputError { .. } => write!(w, "input check errors running `tango`"), + Error::MtimeError(ref p) => write!( + w, + "modification time error from `tango` checking {}", + p.to_string_lossy() + ), + Error::ConcurrentUpdate { ref path_buf, .. } => write!( + w, + "concurrent update during `tango` to source file {}", + path_buf.to_string_lossy() + ), Error::Warnings(ref warnings) => { for warn in warnings { try!(write!(w, "WARNING: {}", warn)); @@ -149,9 +155,7 @@ impl ErrorTrait for Error { fn description(&self) -> &str { match *self { Error::IoError(ref e) => e.description(), - Error::CheckInputError { ref error } => { - error.description() - } + Error::CheckInputError { ref error } => error.description(), Error::MtimeError(_) => "Modification time check error", Error::ConcurrentUpdate { .. } => "concurrent update", Error::Warnings(_) => "warnings", @@ -160,12 +164,8 @@ impl ErrorTrait for Error { fn cause(&self) -> Option<&ErrorTrait> { match *self { Error::IoError(ref e) => Some(e), - Error::CheckInputError { ref error, .. } => { - Some(error) - } - Error::Warnings(_) | - Error::MtimeError(_) | - Error::ConcurrentUpdate { .. } => None, + Error::CheckInputError { ref error, .. } => Some(error), + Error::Warnings(_) | Error::MtimeError(_) | Error::ConcurrentUpdate { .. } => None, } } } @@ -193,7 +193,9 @@ enum MtimeResult { Modified(mtime), } -trait Mtime { fn modified(&self) -> Result; } +trait Mtime { + fn modified(&self) -> Result; +} impl Mtime for File { fn modified(&self) -> Result { // #![allow(deprecated)] @@ -249,7 +251,6 @@ pub fn process_root_with_config(config: Config) -> Result<()> { } } - pub fn process_root() -> Result<()> { //let _root = try!(env::current_dir()); // println!("Tango is running from: {:?}", _root); @@ -289,10 +290,15 @@ pub fn process_root() -> Result<()> { fn process_with_stamp(stamp: File, emit_rerun_if: bool) -> Result<()> { println!("\n\nemit rerun if: {:?}\n\n", emit_rerun_if); if let Ok(MtimeResult::Modified(ts)) = stamp.modified() { - println!("Rerunning tango; last recorded run was stamped: {}", - ts.date_fulltime_badly()); + println!( + "Rerunning tango; last recorded run was stamped: {}", + ts.date_fulltime_badly() + ); } else { - panic!("why are we trying to process_with_stamp when given: {:?}", stamp); + panic!( + "why are we trying to process_with_stamp when given: {:?}", + stamp + ); } let mut c = try!(Context::new(Some(stamp))); c.emit_rerun_if = emit_rerun_if; @@ -323,7 +329,6 @@ struct RsPath(PathBuf); #[derive(Debug)] struct MdPath(PathBuf); - struct Context { orig_stamp: Option<(File, mtime)>, src_inputs: Vec>, @@ -344,22 +349,47 @@ trait Extensions { impl Extensions for Path { fn extension(&self) -> Option<&str> { - Path::extension(self).and_then(|s|s.to_str()) + Path::extension(self).and_then(|s| s.to_str()) } } impl ops::Deref for RsPath { - type Target = Path; fn deref(&self) -> &Path { &self.0 } + type Target = Path; + fn deref(&self) -> &Path { + &self.0 + } } impl ops::Deref for MdPath { - type Target = Path; fn deref(&self) -> &Path { &self.0 } + type Target = Path; + fn deref(&self) -> &Path { + &self.0 + } } fn check_path(typename: &str, p: &Path, ext: &str, root: &str) { - println!("\n in check_path, the root is: {r:?} , path is: {p:?}, ext is {e:?}", r=root, p=p, e=ext); - if Extensions::extension(p) != Some(ext) { panic!("{t} requires `.{ext}` extension; path: {p:?}", t=typename, ext=ext, p=p); } - if !p.starts_with(root) { panic!("{t} must be rooted at `{root}/`; path: {p:?}", t=typename, root=root, p=p); } + println!( + "\n in check_path, the root is: {r:?} , path is: {p:?}, ext is {e:?}", + r = root, + p = p, + e = ext + ); + if Extensions::extension(p) != Some(ext) { + panic!( + "{t} requires `.{ext}` extension; path: {p:?}", + t = typename, + ext = ext, + p = p + ); + } + if !p.starts_with(root) { + panic!( + "{t} must be rooted at `{root}/`; path: {p:?}", + t = typename, + root = root, + p = p + ); + } } impl RsPath { @@ -423,22 +453,27 @@ trait Transforms: Sized + Mtime + fmt::Debug { return Err(e); } }; - Ok(Transform { source_time: source_time, - target_time: target_time, - original: self, - generate: target, + Ok(Transform { + source_time: source_time, + target_time: target_time, + original: self, + generate: target, }) } } impl Transforms for RsPath { type Target = MdPath; - fn target(&self) -> MdPath { self.to_md() } + fn target(&self) -> MdPath { + self.to_md() + } } impl Transforms for MdPath { type Target = RsPath; - fn target(&self) -> RsPath { self.to_rs() } + fn target(&self) -> RsPath { + self.to_rs() + } } #[derive(Debug)] @@ -450,12 +485,12 @@ pub struct Transform { } pub mod check { + use super::Transform; use std::error::Error as ErrorTrait; use std::fmt; use std::ops; use std::path::{Path, PathBuf}; use std::result; - use super::Transform; pub type PathTransform = Transform; #[derive(Debug)] pub enum ErrorKind { @@ -469,20 +504,23 @@ pub mod check { impl fmt::Display for Error { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { match self.0 { - ErrorKind::TargetYoungerThanOriginal { ref tgt, ref src } => { - write!(w, "target `{}` is younger than source `{}`; \ - therefore we assume target has modifications that need to be preserved.", - tgt, src) - } - ErrorKind::NoTangoStampExists { ref src, ref tgt } => { - write!(w, "both source `{}` and target `{}` exist but no `tango.stamp` is present", - src, tgt) - } - ErrorKind::TangoStampOlderThanTarget { ref tgt } => { - write!(w, "`tango.stamp` is older than target `{}`; \ - therefore we assume source and target have diverged since last tango run.", - tgt) - } + ErrorKind::TargetYoungerThanOriginal { ref tgt, ref src } => write!( + w, + "target `{}` is younger than source `{}`; \ + therefore we assume target has modifications that need to be preserved.", + tgt, src + ), + ErrorKind::NoTangoStampExists { ref src, ref tgt } => write!( + w, + "both source `{}` and target `{}` exist but no `tango.stamp` is present", + src, tgt + ), + ErrorKind::TangoStampOlderThanTarget { ref tgt } => write!( + w, + "`tango.stamp` is older than target `{}`; \ + therefore we assume source and target have diverged since last tango run.", + tgt + ), } } } @@ -490,7 +528,7 @@ pub mod check { impl ErrorTrait for Error { fn description(&self) -> &str { match self.0 { - ErrorKind::TargetYoungerThanOriginal { .. }=> { + ErrorKind::TargetYoungerThanOriginal { .. } => { "target is younger than source; \ therefore we assume target has modifications that need to be preserved." } @@ -507,21 +545,27 @@ pub mod check { pub type Result = result::Result; - impl Transform - where X: ops::Deref, Y: ops::Deref + impl Transform + where + X: ops::Deref, + Y: ops::Deref, { pub fn error(&self, kind: ErrorKind) -> Error { - let t = Transform { original: self.original.to_path_buf(), - generate: self.generate.to_path_buf(), - source_time: self.source_time, - target_time: self.target_time, + let t = Transform { + original: self.original.to_path_buf(), + generate: self.generate.to_path_buf(), + source_time: self.source_time, + target_time: self.target_time, }; Error(kind, t) } } } -enum TransformNeed { Needed, Unneeded, } +enum TransformNeed { + Needed, + Unneeded, +} impl Context { fn new(opt_stamp: Option) -> Result { @@ -547,13 +591,12 @@ impl Context { } fn check_transform(&self, t: &Transform) -> check::Result - where X: ops::Deref + Mtime, - Y: ops::Deref + Mtime, + where + X: ops::Deref + Mtime, + Y: ops::Deref + Mtime, { - use self::check::ErrorKind::*; - let t_mod = match t.target_time { MtimeResult::Modified(t) => t, MtimeResult::NonExistant => { @@ -593,10 +636,12 @@ impl Context { // to millisecond precision. match self.orig_stamp { - None => return Err(t.error(NoTangoStampExists { - src: t.original.display().to_string(), - tgt: t.generate.display().to_string(), - })), + None => { + return Err(t.error(NoTangoStampExists { + src: t.original.display().to_string(), + tgt: t.generate.display().to_string(), + })) + } Some((_, stamp_time)) => { let older_at_high_precision = stamp_time < t_mod; let older_at_low_precision = stamp_time.to_ms() < t_mod.to_ms(); @@ -679,17 +724,14 @@ impl Context { let lit_path = Path::new(&lit_dir); fn keep_file_name(p: &Path) -> std::result::Result<(), &'static str> { - match p.file_name().and_then(|x|x.to_str()) { - None => - Err("file name is not valid unicode"), - Some(s) if s.starts_with('.') => - Err("file name has leading period"), - Some(..) => - Ok(()), + match p.file_name().and_then(|x| x.to_str()) { + None => Err("file name is not valid unicode"), + Some(s) if s.starts_with('.') => Err("file name has leading period"), + Some(..) => Ok(()), } } - fn warn_if_nonexistant(m: &M) -> Result<()> { + fn warn_if_nonexistant(m: &M) -> Result<()> { match m.modified() { Err(e) => Err(e), Ok(MtimeResult::Modified(..)) => Ok(()), @@ -707,7 +749,6 @@ impl Context { Ok(()) } } - } // This loop gathers all of the .rs files that currently @@ -739,9 +780,7 @@ impl Context { Ok(TransformNeed::Unneeded) => {} Err(e) => { println!("gather_inputs err: {}", e.description()); - return Err(Error::CheckInputError { - error: e, - }) + return Err(Error::CheckInputError { error: e }); } } } @@ -781,9 +820,7 @@ impl Context { } Err(e) => { println!("gather_inputs err: {}", e.description()); - return Err(Error::CheckInputError { - error: e, - }) + return Err(Error::CheckInputError { error: e }); } } } @@ -797,33 +834,55 @@ impl Context { Ok(()) } fn generate_content(&mut self) -> Result<()> { - for &Transform { ref original, ref generate, source_time, .. } in &self.src_inputs { + for &Transform { + ref original, + ref generate, + source_time, + .. + } in &self.src_inputs + { let source = try!(File::open(&original.0)); let target = try!(File::create(&generate.0)); assert!(source_time > 0); println!("generating lit {:?}", &generate.0); try!(rs2md(source, target)); let timestamp = source_time.to_filetime(); - println!("backdating lit {:?} to {}", &generate.0, source_time.date_fulltime_badly()); + println!( + "backdating lit {:?} to {}", + &generate.0, + source_time.date_fulltime_badly() + ); try!(set_file_times(&generate.0, timestamp, timestamp)); } - for &mut Transform { ref original, ref generate, ref mut source_time, .. } in &mut self.lit_inputs { + for &mut Transform { + ref original, + ref generate, + ref mut source_time, + .. + } in &mut self.lit_inputs + { let source = try!(File::open(&original.0)); let target = try!(File::create(&generate.0)); assert!(*source_time > 0); println!("generating src {:?}", &generate.0); try!(md2rs(source, target)); - println!("backdating src {:?} to {}", &generate.0, source_time.date_fulltime_badly()); - try!(set_file_times(&generate.0, - source_time.to_filetime(), - source_time.to_filetime())); + println!( + "backdating src {:?} to {}", + &generate.0, + source_time.date_fulltime_badly() + ); + try!(set_file_times( + &generate.0, + source_time.to_filetime(), + source_time.to_filetime() + )); let source = try!(File::open(&original.0)); let target = try!(File::open(&generate.0)); match (source.modified(), target.modified()) { - (Ok(MtimeResult::Modified(src_time)), - Ok(MtimeResult::Modified(tgt_time))) => { + (Ok(MtimeResult::Modified(src_time)), Ok(MtimeResult::Modified(tgt_time))) => { // At this point, we would *like* to assert this: - #[cfg(not_possible_right_now)] assert_eq!(src_time, tgt_time); + #[cfg(not_possible_right_now)] + assert_eq!(src_time, tgt_time); // but it does not work, due to this bug: // https://github.com/alexcrichton/filetime/issues/9 @@ -839,25 +898,35 @@ impl Context { Ok(()) } fn check_input_timestamps(&mut self) -> Result<()> { - for &Transform { ref original, source_time, .. } in &self.src_inputs { + for &Transform { + ref original, + source_time, + .. + } in &self.src_inputs + { if let MtimeResult::Modified(new_time) = try!(original.modified()) { if new_time != source_time { return Err(Error::ConcurrentUpdate { path_buf: original.to_path_buf(), old_time: source_time, new_time: new_time, - }) + }); } } } - for &Transform { ref original, source_time, .. } in &self.lit_inputs { + for &Transform { + ref original, + source_time, + .. + } in &self.lit_inputs + { if let MtimeResult::Modified(new_time) = try!(original.modified()) { if new_time != source_time { return Err(Error::ConcurrentUpdate { path_buf: original.to_path_buf(), old_time: source_time, new_time: new_time, - }) + }); } } } @@ -882,12 +951,12 @@ impl Context { } } -fn rs2md(source: R, target: W) -> Result<()> { +fn rs2md(source: R, target: W) -> Result<()> { let mut converter = rs2md::Converter::new(); converter.convert(source, target).map_err(Error::IoError) } -fn md2rs(source: R, target: W) -> Result<()> { +fn md2rs(source: R, target: W) -> Result<()> { let converter = md2rs::Converter::new(); converter.convert(source, target).map_err(From::from) } @@ -899,8 +968,12 @@ mod rs2md; fn encode_to_url(code: &str) -> String { use url::percent_encoding as enc; // let new_code: String = enc::utf8_percent_encode(code.trim(), enc::QUERY_ENCODE_SET); - let new_code: String = enc::utf8_percent_encode(code.trim(), enc::USERINFO_ENCODE_SET).collect(); - format!("https://play.rust-lang.org/?code={}&version=nightly", new_code) + let new_code: String = + enc::utf8_percent_encode(code.trim(), enc::USERINFO_ENCODE_SET).collect(); + format!( + "https://play.rust-lang.org/?code={}&version=nightly", + new_code + ) } #[cfg(test)] diff --git a/src/md2rs.rs b/src/md2rs.rs index 22c50c9..05ae5f8 100644 --- a/src/md2rs.rs +++ b/src/md2rs.rs @@ -10,7 +10,12 @@ pub struct Converter { use super::Warning; #[derive(Copy, Clone, PartialEq, Eq, Debug)] -enum State { MarkdownBlank, MarkdownText, MarkdownMeta, Rust, } +enum State { + MarkdownBlank, + MarkdownText, + MarkdownMeta, + Rust, +} impl Converter { pub fn new() -> Converter { Converter { @@ -34,7 +39,7 @@ impl From for Exception { } impl Converter { - pub fn convert(mut self, r:R, mut w:W) -> Result<(), Exception> { + pub fn convert(mut self, r: R, mut w: W) -> Result<(), Exception> { let source = io::BufReader::new(r); for line in source.lines() { let line = try!(line); @@ -51,37 +56,31 @@ impl Converter { let str9 = line.chars().take(9).collect::(); let str7 = line.chars().take(7).collect::(); match (self.state, &str7[..], &str9[..]) { - (State::MarkdownBlank, "```rust", _) | - (State::MarkdownText, "```rust", _) => { + (State::MarkdownBlank, "```rust", _) | (State::MarkdownText, "```rust", _) => { self.buffered_lines = String::new(); - let rest = &line.chars().skip(7).collect::(); + let rest = &line.chars().skip(7).collect::(); if rest != "" { try!(self.transition(w, State::MarkdownMeta)); try!(self.meta_note(&rest, w)); } self.transition(w, State::Rust) } - (State::MarkdownBlank, _, "```{.rust") | - (State::MarkdownText, _, "```{.rust") => { + (State::MarkdownBlank, _, "```{.rust") | (State::MarkdownText, _, "```{.rust") => { self.buffered_lines = String::new(); - let rest = &line.chars().skip(9).collect::(); + let rest = &line.chars().skip(9).collect::(); if rest != "" { try!(self.transition(w, State::MarkdownMeta)); try!(self.meta_note(&format!(" {{{}", rest), w)); } self.transition(w, State::Rust) } - (State::Rust, "```", _) => { - self.transition(w, State::MarkdownBlank) - } + (State::Rust, "```", _) => self.transition(w, State::MarkdownBlank), // FIXME: accum blank lines and only emit them with // prefix if there's no state transition; otherwise // emit them with no prefix. (This is in part the // motivation for the `fn finish_section` design.) - (_, "", _) => { - self.blank_line(w) - } + (_, "", _) => self.blank_line(w), _ => { // HACK: if we find anything that looks like a markdown-named playpen link ... @@ -96,14 +95,14 @@ impl Converter { // the user, and suggest they re-run `tango` after // touching the file to generate matching url. let expect = super::encode_to_url(&self.buffered_lines); - let actual = &line[(close+3)..]; + let actual = &line[(close + 3)..]; if expect != actual { self.warnings.push(Warning::EncodedUrlMismatch { actual: actual.to_string(), - expect: expect + expect: expect, }) } - self.name_block(line, &line[open+1..close], w) + self.name_block(line, &line[open + 1..close], w) } else { self.nonblank_line(line, w) } @@ -130,15 +129,12 @@ impl Converter { }; for _ in 0..self.blank_line_count { try!(writeln!(w, "{}", blank_prefix)); - } self.blank_line_count = 0; match self.state { - State::MarkdownBlank => - try!(self.transition(w, State::MarkdownText)), - State::MarkdownMeta | - State::MarkdownText => {} + State::MarkdownBlank => try!(self.transition(w, State::MarkdownText)), + State::MarkdownMeta | State::MarkdownText => {} State::Rust => { self.buffered_lines.push_str("\n"); self.buffered_lines.push_str(line); @@ -153,9 +149,7 @@ impl Converter { State::Rust => { self.buffered_lines.push_str("\n"); } - State::MarkdownBlank | - State::MarkdownMeta | - State::MarkdownText => {} + State::MarkdownBlank | State::MarkdownMeta | State::MarkdownText => {} } self.blank_line_count += 1; Ok(()) diff --git a/src/rs2md.rs b/src/rs2md.rs index cdba8fd..db742ec 100644 --- a/src/rs2md.rs +++ b/src/rs2md.rs @@ -1,5 +1,5 @@ -use std::io::{self, BufRead, Write}; use super::encode_to_url; +use std::io::{self, BufRead, Write}; #[derive(Debug)] pub struct Converter { @@ -9,13 +9,19 @@ pub struct Converter { meta_note: Option, } #[derive(Copy, Clone, PartialEq, Eq, Debug)] -enum State { MarkdownFirstLine, MarkdownLines, Rust, } +enum State { + MarkdownFirstLine, + MarkdownLines, + Rust, +} impl Converter { pub fn new() -> Converter { - Converter { output_state: State::MarkdownFirstLine, - blank_line_count: 0, - buffered_code: String::new(), - meta_note: None, } + Converter { + output_state: State::MarkdownFirstLine, + blank_line_count: 0, + buffered_code: String::new(), + meta_note: None, + } } } @@ -36,7 +42,7 @@ enum EffectContext<'a> { } impl Converter { - pub fn convert(&mut self, r:R, mut w:W) -> io::Result<()> { + pub fn convert(&mut self, r: R, mut w: W) -> io::Result<()> { let source = io::BufReader::new(r); for line in source.lines() { let line = try!(line); @@ -47,11 +53,8 @@ impl Converter { pub fn finalize(&mut self, w: &mut Write) -> io::Result<()> { match self.output_state { - State::Rust => - self.effect(EffectContext::Finalize, Effect::FinisCodeBlock, w), - State::MarkdownFirstLine | - State::MarkdownLines => - Ok(()) + State::Rust => self.effect(EffectContext::Finalize, Effect::FinisCodeBlock, w), + State::MarkdownFirstLine | State::MarkdownLines => Ok(()), } } @@ -65,12 +68,9 @@ impl Converter { try!(self.blank_line(w)) } match self.output_state { - State::Rust => - try!(self.transition(w, State::MarkdownFirstLine)), - State::MarkdownFirstLine => - try!(self.transition(w, State::MarkdownLines)), - State::MarkdownLines => - {} + State::Rust => try!(self.transition(w, State::MarkdownFirstLine)), + State::MarkdownFirstLine => try!(self.transition(w, State::MarkdownLines)), + State::MarkdownLines => {} } if line.trim().is_empty() { Ok(()) @@ -104,12 +104,9 @@ impl Converter { } else if line_right.starts_with("//@") { let line = &line_right[3..]; match self.output_state { - State::Rust => - try!(self.transition(w, State::MarkdownFirstLine)), - State::MarkdownFirstLine => - try!(self.transition(w, State::MarkdownLines)), - State::MarkdownLines => - {} + State::Rust => try!(self.transition(w, State::MarkdownFirstLine)), + State::MarkdownFirstLine => try!(self.transition(w, State::MarkdownLines)), + State::MarkdownLines => {} } if line.trim().is_empty() { self.blank_line(w) @@ -118,9 +115,9 @@ impl Converter { } } else { match self.output_state { - State::MarkdownFirstLine | - State::MarkdownLines => - try!(self.transition(w, State::Rust)), + State::MarkdownFirstLine | State::MarkdownLines => { + try!(self.transition(w, State::Rust)) + } _ => {} } self.nonblank_line(line, w) diff --git a/src/testing/mod.rs b/src/testing/mod.rs index 824361e..8de58ad 100644 --- a/src/testing/mod.rs +++ b/src/testing/mod.rs @@ -37,14 +37,14 @@ fn compare_lines<'a>(a: &'a str, b: &'a str) -> ComparisonResult<'a> { right: b[j], }); - for j_ in (j+1)..b.len() { + for j_ in (j + 1)..b.len() { if a[i] == b[j_] { j = j_; continue; } } - for i_ in (i+1)..a.len() { + for i_ in (i + 1)..a.len() { if a[i_] == b[j] { i = i_; continue; @@ -78,13 +78,15 @@ fn panic_if_different<'a>(name_a: &str, a: &'a str, name_b: &str, b: &'a str) { match compare_lines(a, b) { ComparisonResult::LineDifferences(differences) => { for difference in differences { - println!("lines {lnum} and {rnum} differ:\n{nl:>8}: {l}\n{nr:>8}: {r}", - lnum=difference.left_line_num+1, - rnum=difference.right_line_num+1, - nl=name_a, - l=difference.left, - nr=name_b, - r=difference.right); + println!( + "lines {lnum} and {rnum} differ:\n{nl:>8}: {l}\n{nr:>8}: {r}", + lnum = difference.left_line_num + 1, + rnum = difference.right_line_num + 1, + nl = name_a, + l = difference.left, + nr = name_b, + r = difference.right + ); } panic!("saw differences"); } @@ -92,11 +94,13 @@ fn panic_if_different<'a>(name_a: &str, a: &'a str, name_b: &str, b: &'a str) { for line in v { println!("excess line: {}", line); } - panic!("Content differs:\n{nl:>8}: {l} lines\n{nr:>8}: {r} lines", - nl=name_a, - l=a, - nr=name_b, - r=b); + panic!( + "Content differs:\n{nl:>8}: {l} lines\n{nr:>8}: {r} lines", + nl = name_a, + l = a, + nr = name_b, + r = b + ); } ComparisonResult::Ok => {} } @@ -132,26 +136,34 @@ fn core_test_rs2md(rs: &str, md: &str) { #[test] fn test_onetext_md2rs() { - core_test_md2rs(test_snippets::ONE_TEXT_LINE_MD, - test_snippets::ONE_TEXT_LINE_RS); + core_test_md2rs( + test_snippets::ONE_TEXT_LINE_MD, + test_snippets::ONE_TEXT_LINE_RS, + ); } #[test] fn test_onetext_rs2md() { - core_test_rs2md(test_snippets::ONE_TEXT_LINE_RS, - test_snippets::ONE_TEXT_LINE_MD); + core_test_rs2md( + test_snippets::ONE_TEXT_LINE_RS, + test_snippets::ONE_TEXT_LINE_MD, + ); } #[test] fn test_onerust_md2rs() { - core_test_md2rs(test_snippets::ONE_RUST_LINE_MD, - test_snippets::ONE_RUST_LINE_RS); + core_test_md2rs( + test_snippets::ONE_RUST_LINE_MD, + test_snippets::ONE_RUST_LINE_RS, + ); } #[test] fn test_onerust_rs2md() { - core_test_rs2md(test_snippets::ONE_RUST_LINE_RS, - test_snippets::ONE_RUST_LINE_MD); + core_test_rs2md( + test_snippets::ONE_RUST_LINE_RS, + test_snippets::ONE_RUST_LINE_MD, + ); } #[test] @@ -196,88 +208,114 @@ fn test_hello4_rs2md() { #[test] fn test_prodigal5_md2rs() { - core_test_md2rs(test_snippets::PRODIGAL5_MD, test_snippets::HARVEST5_RS); + core_test_md2rs(test_snippets::PRODIGAL5_MD, test_snippets::HARVEST5_RS); } #[test] fn test_prodigal5return_md2rs() { - core_test_rs2md(test_snippets::HARVEST5_RS, test_snippets::RETURN5_MD); + core_test_rs2md(test_snippets::HARVEST5_RS, test_snippets::RETURN5_MD); } #[test] fn test_hello6_metadata_md2rs() { - core_test_md2rs(test_snippets::HELLO6_METADATA_MD, - test_snippets::HELLO6_METADATA_RS); + core_test_md2rs( + test_snippets::HELLO6_METADATA_MD, + test_snippets::HELLO6_METADATA_RS, + ); } #[test] fn test_hello6_metadata_rs2md() { - core_test_rs2md(test_snippets::HELLO6_METADATA_RS, - test_snippets::HELLO6_METADATA_MD); + core_test_rs2md( + test_snippets::HELLO6_METADATA_RS, + test_snippets::HELLO6_METADATA_MD, + ); } #[test] fn test_hello7_link_to_play_md2rs() { - core_test_md2rs(test_snippets::HELLO7_LINK_TO_PLAY_MD, - test_snippets::HELLO7_LINK_TO_PLAY_RS); + core_test_md2rs( + test_snippets::HELLO7_LINK_TO_PLAY_MD, + test_snippets::HELLO7_LINK_TO_PLAY_RS, + ); } #[test] fn test_hello7_link_to_play_rs2md() { - core_test_rs2md(test_snippets::HELLO7_LINK_TO_PLAY_RS, - test_snippets::HELLO7_LINK_TO_PLAY_MD); + core_test_rs2md( + test_snippets::HELLO7_LINK_TO_PLAY_RS, + test_snippets::HELLO7_LINK_TO_PLAY_MD, + ); } #[test] fn test_hello8_link_to_play_md2rs() { - core_test_md2rs(test_snippets::HELLO8_LINK_TO_PLAY_MD, - test_snippets::HELLO8_LINK_TO_PLAY_RS); + core_test_md2rs( + test_snippets::HELLO8_LINK_TO_PLAY_MD, + test_snippets::HELLO8_LINK_TO_PLAY_RS, + ); } #[test] fn test_hello8_link_to_play_rs2md() { - core_test_rs2md(test_snippets::HELLO8_LINK_TO_PLAY_RS, - test_snippets::HELLO8_LINK_TO_PLAY_MD); + core_test_rs2md( + test_snippets::HELLO8_LINK_TO_PLAY_RS, + test_snippets::HELLO8_LINK_TO_PLAY_MD, + ); } #[test] fn test_hello9_link_to_play_md2rs_warn() { - warn_test_md2rs(test_snippets::HELLO9_LINK_TO_PLAY_MD_WARN, - test_snippets::HELLO9_LINK_TO_PLAY_RS); + warn_test_md2rs( + test_snippets::HELLO9_LINK_TO_PLAY_MD_WARN, + test_snippets::HELLO9_LINK_TO_PLAY_RS, + ); } #[test] fn test_hello10_link_to_play_eq_md2rs() { - core_test_md2rs(test_snippets::HELLO10_LINK_TO_PLAY_EQ_MD, - test_snippets::HELLO10_LINK_TO_PLAY_EQ_RS); + core_test_md2rs( + test_snippets::HELLO10_LINK_TO_PLAY_EQ_MD, + test_snippets::HELLO10_LINK_TO_PLAY_EQ_RS, + ); } #[test] fn test_hello10_link_to_play_eq_rs2md() { - core_test_rs2md(test_snippets::HELLO10_LINK_TO_PLAY_EQ_RS, - test_snippets::HELLO10_LINK_TO_PLAY_EQ_MD); + core_test_rs2md( + test_snippets::HELLO10_LINK_TO_PLAY_EQ_RS, + test_snippets::HELLO10_LINK_TO_PLAY_EQ_MD, + ); } #[test] fn test_hello11_link_to_play_md2rs() { - core_test_md2rs(test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_MD, - test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_RS); + core_test_md2rs( + test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_MD, + test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_RS, + ); } #[test] fn test_hello11_link_to_play_rs2md() { - core_test_rs2md(test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_RS, - test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_MD); + core_test_rs2md( + test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_RS, + test_snippets::HELLO11_LINK_TO_PLAY_HTML_SEP_MD, + ); } #[test] fn test_hello12_link_to_play_md2rs() { - core_test_md2rs(test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_MD, - test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_RS); + core_test_md2rs( + test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_MD, + test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_RS, + ); } #[test] fn test_hello12_link_to_play_rs2md() { - core_test_rs2md(test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_RS, - test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_MD); + core_test_rs2md( + test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_RS, + test_snippets::HELLO12_LINK_TO_PLAY_MARKDOWN_FOLLOW_MD, + ); } diff --git a/src/timestamp.rs b/src/timestamp.rs index 9a0642c..3935a2a 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -10,16 +10,22 @@ pub trait Timestamped { } #[derive(Copy, Clone, PartialEq, Eq, Ord, Debug)] -pub struct Timestamp { pub secs: u64, pub nsecs: u64 } +pub struct Timestamp { + pub secs: u64, + pub nsecs: u64, +} #[allow(non_snake_case)] -pub fn Timestamp(ms: u64) -> Timestamp { +pub fn Timestamp(ms: u64) -> Timestamp { Timestamp::new(ms / 1_000, (ms % 1_000) * 1_000_000) } impl Timestamp { pub fn new(secs: u64, ns: u64) -> Timestamp { - Timestamp { secs: secs, nsecs: ns } + Timestamp { + secs: secs, + nsecs: ns, + } } pub fn to_filetime(&self) -> FileTime { assert!(self.nsecs < ::std::u32::MAX as u64); @@ -61,7 +67,7 @@ impl Timestamp { if remain > secs_per_month { remain -= secs_per_month; } else { - month = Some(i+1); // We count months starting from 1 ... + month = Some(i + 1); // We count months starting from 1 ... break; } } @@ -79,8 +85,16 @@ impl Timestamp { let sec = remain; // ... and likewise count seconds from zero let nsec = self.nsecs; // ... et cetera. - format!("{YEAR:04}-{MONTH:02}-{DAY:02} {HOUR:02}:{MIN:02}:{SEC:02}.{NSEC} (GMT)", - YEAR=year, MONTH=month, DAY=day, HOUR=hour, MIN=min, SEC=sec, NSEC=nsec) + format!( + "{YEAR:04}-{MONTH:02}-{DAY:02} {HOUR:02}:{MIN:02}:{SEC:02}.{NSEC} (GMT)", + YEAR = year, + MONTH = month, + DAY = day, + HOUR = hour, + MIN = min, + SEC = sec, + NSEC = nsec + ) } } @@ -147,7 +161,7 @@ impl PartialOrd for Timestamp { impl Timestamped for fs::Metadata { fn timestamp(&self) -> Timestamp { - let ft = FileTime::from_last_modification_time( self ); + let ft = FileTime::from_last_modification_time(self); let s = ft.seconds_relative_to_1970(); let ns = ft.nanoseconds(); // println!("metadata mtime: {} ns: {}", s, ns); diff --git a/tests/runner.rs b/tests/runner.rs index d7d4e3b..818b189 100644 --- a/tests/runner.rs +++ b/tests/runner.rs @@ -9,7 +9,7 @@ extern crate walkdir; use tango::timestamp::{Timestamp, Timestamped}; use tempdir::TempDir; -use walkdir::{WalkDir}; +use walkdir::WalkDir; use std::cell::RefCell; use std::convert; @@ -18,8 +18,8 @@ use std::error::Error; use std::fmt; use std::fs::{self, File}; use std::io::{self, Read, Write}; -use std::path::{PathBuf}; -use std::process::{Command}; +use std::path::PathBuf; +use std::process::Command; const BINARY_FILENAME: &'static str = "tango"; const PRESERVE_TEMP_DIRS: bool = false; @@ -29,8 +29,10 @@ const REJECT_IF_TANGO_AFFECTS_STD_PORTS: bool = false; fn out_path() -> PathBuf { let out_dir = env::var("OUT_DIR").unwrap_or_else(|_| { - panic!("tango tests expect `cargo` to set OUT_DIR; \ - now it does not? Fix me."); + panic!( + "tango tests expect `cargo` to set OUT_DIR; \ + now it does not? Fix me." + ); }); PathBuf::from(&out_dir) } @@ -60,7 +62,10 @@ fn infer_target_binary() -> PathBuf { thread_local!(static CURRENT_DIR_PREFIX: RefCell = RefCell::new(PathBuf::new())); -fn within_temp_dir(name: &str, f: F) -> X where F: FnOnce() -> X { +fn within_temp_dir(name: &str, f: F) -> X +where + F: FnOnce() -> X, +{ let out_path = out_path(); let mut errors = vec![]; @@ -70,8 +75,10 @@ fn within_temp_dir(name: &str, f: F) -> X where F: FnOnce() -> X { while let Err(e) = fs::create_dir_all(&out_path) { fail_count += 1; if fail_count > 100 { - panic!("failure to create output directory at {:?} due to {}", - &out_path, e); + panic!( + "failure to create output directory at {:?} due to {}", + &out_path, e + ); } else { errors.push((e, &out_path)); } @@ -79,15 +86,15 @@ fn within_temp_dir(name: &str, f: F) -> X where F: FnOnce() -> X { } if errors.len() > 0 { - println!("FYI encountered transient errors {:?} during out_path creation.", - errors); + println!( + "FYI encountered transient errors {:?} during out_path creation.", + errors + ); } - - let temp_dir = TempDir::new_in(&out_path, name) - .unwrap_or_else(|e| { - panic!("failure to create temp dir in {:?}: {}", out_path, e); - }); + let temp_dir = TempDir::new_in(&out_path, name).unwrap_or_else(|e| { + panic!("failure to create temp dir in {:?}: {}", out_path, e); + }); let result = CURRENT_DIR_PREFIX.with(|prefix| { *prefix.borrow_mut() = temp_dir.path().to_path_buf(); @@ -119,8 +126,11 @@ fn indent_at_newline(s: &str) -> String { r } -trait UnwrapOrPanic { type X; fn unwrap_or_panic(self, msg: &str) -> Self::X; } -impl UnwrapOrPanic for Result { +trait UnwrapOrPanic { + type X; + fn unwrap_or_panic(self, msg: &str) -> Self::X; +} +impl UnwrapOrPanic for Result { type X = X; fn unwrap_or_panic(self, s: &str) -> X { self.unwrap_or_else(|e| { @@ -133,18 +143,24 @@ fn setup_src_and_lit_dirs() { CURRENT_DIR_PREFIX.with(|p| { let p = p.borrow_mut(); let mut p_src = p.clone(); - let src_dir = &tango::get_src_dir(); - let lit_dir = &tango::get_lit_dir(); + let src_dir = &tango::get_src_dir(); + let lit_dir = &tango::get_lit_dir(); p_src.push(src_dir); fs::create_dir(p_src).unwrap_or_panic(&format!("failed to create {}", src_dir)); - if lit_dir == src_dir { return; } + if lit_dir == src_dir { + return; + } let mut p_lit = p.clone(); p_lit.push(lit_dir); fs::create_dir(p_lit).unwrap_or_panic(&format!("failed to create {}", lit_dir)); }) } -enum Target { Root, Src, Lit } +enum Target { + Root, + Src, + Lit, +} impl Target { fn path_buf(&self, filename: &str) -> PathBuf { @@ -187,8 +203,12 @@ fn touch_file(t: Target, filename: &str, timestamp: Timestamp) -> Result<(), Tan #[cfg(unix)] () => { use std::os::unix::fs::MetadataExt; - println!("touch path {} t {:?} pre: {} ", p.display(), timestamp, - try!(p.metadata()).mtime()); + println!( + "touch path {} t {:?} pre: {} ", + p.display(), + timestamp, + try!(p.metadata()).mtime() + ); } } assert!(timestamp > 0); @@ -203,8 +223,12 @@ fn touch_file(t: Target, filename: &str, timestamp: Timestamp) -> Result<(), Tan #[cfg(unix)] () => { use std::os::unix::fs::MetadataExt; - println!("touch path {} t {:?} post: {} ", p.display(), timestamp, - try!(p.metadata()).mtime()); + println!( + "touch path {} t {:?} post: {} ", + p.display(), + timestamp, + try!(p.metadata()).mtime() + ); } } ret @@ -233,35 +257,49 @@ fn main() { println!(\"Hello World 2\"); } // work-around for lack of stable const fn. macro_rules! timestamp { ($ms:expr) => { - Timestamp { secs: $ms / 1_000, - nsecs: ($ms % 1_000) * 1_000_000 } - } + Timestamp { + secs: $ms / 1_000, + nsecs: ($ms % 1_000) * 1_000_000, + } + }; } -#[allow(dead_code)] const TIME_A1: Timestamp = timestamp!(1000_000_000); -#[allow(dead_code)] const TIME_A2: Timestamp = timestamp!(1000_100_000); -#[allow(dead_code)] const TIME_A3: Timestamp = timestamp!(1000_200_000); -#[allow(dead_code)] const TIME_B1: Timestamp = timestamp!(2000_000_000); -#[allow(dead_code)] const TIME_B2: Timestamp = timestamp!(2000_100_000); -#[allow(dead_code)] const TIME_B3: Timestamp = timestamp!(2000_200_000); -#[allow(dead_code)] const TIME_C1: Timestamp = timestamp!(3000_000_000); -#[allow(dead_code)] const TIME_C2: Timestamp = timestamp!(3000_100_000); -#[allow(dead_code)] const TIME_C3: Timestamp = timestamp!(3000_200_000); +#[allow(dead_code)] +const TIME_A1: Timestamp = timestamp!(1000_000_000); +#[allow(dead_code)] +const TIME_A2: Timestamp = timestamp!(1000_100_000); +#[allow(dead_code)] +const TIME_A3: Timestamp = timestamp!(1000_200_000); +#[allow(dead_code)] +const TIME_B1: Timestamp = timestamp!(2000_000_000); +#[allow(dead_code)] +const TIME_B2: Timestamp = timestamp!(2000_100_000); +#[allow(dead_code)] +const TIME_B3: Timestamp = timestamp!(2000_200_000); +#[allow(dead_code)] +const TIME_C1: Timestamp = timestamp!(3000_000_000); +#[allow(dead_code)] +const TIME_C2: Timestamp = timestamp!(3000_100_000); +#[allow(dead_code)] +const TIME_C3: Timestamp = timestamp!(3000_200_000); #[derive(Debug)] enum TangoRunError { IoError(io::Error), - SawOutput { stdout_len: usize, stderr_len: usize, - stdout: String, stderr: String, combined: String }, + SawOutput { + stdout_len: usize, + stderr_len: usize, + stdout: String, + stderr: String, + combined: String, + }, } impl fmt::Display for TangoRunError { fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result { match *self { - TangoRunError::IoError(_) => - write!(w, "IO error running `tango`"), - TangoRunError::SawOutput { .. } => - write!(w, "`tango` should not produce output"), + TangoRunError::IoError(_) => write!(w, "IO error running `tango`"), + TangoRunError::SawOutput { .. } => write!(w, "`tango` should not produce output"), } } } @@ -271,15 +309,17 @@ impl Error for TangoRunError { match *self { TangoRunError::IoError(ref e) => e.description(), TangoRunError::SawOutput { - stdout_len, stderr_len, stdout: ref o, stderr: ref e, combined: ref c - } => { - match (stdout_len > 0, stderr_len > 0) { - (true, true) => c, - (true, false) => o, - (false, true) => e, - (false, false) => panic!("did not SawOutput"), - } - } + stdout_len, + stderr_len, + stdout: ref o, + stderr: ref e, + combined: ref c, + } => match (stdout_len > 0, stderr_len > 0) { + (true, true) => c, + (true, false) => o, + (false, true) => e, + (false, false) => panic!("did not SawOutput"), + }, } } } @@ -295,24 +335,23 @@ fn run_tango() -> Result<(), TangoRunError> { let p = p.borrow_mut(); let result = infer_target_binary(); // println!("result {:?}", result); - let output = match Command::new(result) - .current_dir(&*p) - .output() { - Ok(o) => o, - Err(e) => return Err(TangoRunError::IoError(e)), - }; + let output = match Command::new(result).current_dir(&*p).output() { + Ok(o) => o, + Err(e) => return Err(TangoRunError::IoError(e)), + }; let stdout = String::from_utf8_lossy(&output.stdout); let stderr = String::from_utf8_lossy(&output.stderr); - if REJECT_IF_TANGO_AFFECTS_STD_PORTS && - stdout.len() > 0 || stderr.len() > 0 - { + if REJECT_IF_TANGO_AFFECTS_STD_PORTS && stdout.len() > 0 || stderr.len() > 0 { return Err(TangoRunError::SawOutput { stdout_len: stdout.len(), stderr_len: stderr.len(), stdout: format!("output on stdout: `{}`", stdout), stderr: format!("output on stderr: `{}`", stderr), - combined: format!("output on stderr: `{err}`, stdout: `{out}`", - err=stderr, out=stdout), + combined: format!( + "output on stderr: `{err}`, stdout: `{out}`", + err = stderr, + out = stdout + ), }); } else { for line in stdout.lines() { @@ -327,33 +366,44 @@ fn run_tango() -> Result<(), TangoRunError> { } fn report_dir_contents(prefix: &str) { - if !REPORT_DIR_CONTENTS { return; } + if !REPORT_DIR_CONTENTS { + return; + } CURRENT_DIR_PREFIX.with(|p| { let p = p.borrow_mut(); - for (i, ent) in WalkDir::new(&*p).into_iter() - .enumerate() - { + for (i, ent) in WalkDir::new(&*p).into_iter().enumerate() { match ent { Ok(ent) => { // println!("entry[{}]: {:?}", i, ent.file_name()); - println!("{} entry[{}]: {:?}", - prefix, i, ent.path()); + println!("{} entry[{}]: {:?}", prefix, i, ent.path()); match ent.metadata() { Err(e) => { - println!("{} failed to extract metadata for {:?} due to {:?}", - prefix, ent.file_name(), e.description()); + println!( + "{} failed to extract metadata for {:?} due to {:?}", + prefix, + ent.file_name(), + e.description() + ); } Ok(m) => { // println!("{} entry[{}] metadata accessed: {:?}", // prefix, i, m.accessed()); - println!("{} entry[{}] metadata modified: {:?}", - prefix, i, m.modified().unwrap()); + println!( + "{} entry[{}] metadata modified: {:?}", + prefix, + i, + m.modified().unwrap() + ); } } } Err(e) => { - println!("{} entry[{}]: error due to {:?}", - prefix, i, e.description()); + println!( + "{} entry[{}]: error due to {:?}", + prefix, + i, + e.description() + ); } } } @@ -368,14 +418,21 @@ struct Test { post: POST, } -fn framework(test: Test) -> Result<(), TangoRunError> where +fn framework(test: Test) -> Result<(), TangoRunError> +where S: FnOnce() -> Result<(), TangoRunError>, - PR: FnOnce() -> Result<(), TangoRunError>, - RUN: FnOnce() -> Result<(), TangoRunError>, - PO: FnOnce() -> Result<(), TangoRunError>, + PR: FnOnce() -> Result<(), TangoRunError>, + RUN: FnOnce() -> Result<(), TangoRunError>, + PO: FnOnce() -> Result<(), TangoRunError>, { within_temp_dir(test.name, move || -> Result<(), TangoRunError> { - let Test { name: _, setup, pre, run, post } = test; + let Test { + name: _, + setup, + pre, + run, + post, + } = test; println!("Setup test"); setup_src_and_lit_dirs(); try!(setup()); @@ -450,7 +507,8 @@ fn unstamped_and_src_without_lit() { // TODO: check timestamps Ok(()) }, - }).unwrap_or_panic("test error") + }) + .unwrap_or_panic("test error") } #[test] @@ -474,7 +532,8 @@ fn unstamped_and_lit_without_src() { // TODO: check timestamps Ok(()) }, - }).unwrap_or_panic("test error") + }) + .unwrap_or_panic("test error") } #[test] @@ -499,7 +558,8 @@ fn stamp_and_src_without_lit() { // TODO: check timestamps Ok(()) }, - }).unwrap_or_panic("test error") + }) + .unwrap_or_panic("test error") } #[test] @@ -523,7 +583,8 @@ fn stamp_and_lit_without_src() { // TODO: check timestamps Ok(()) }, - }).unwrap_or_panic("test error") + }) + .unwrap_or_panic("test error") } #[test] @@ -556,8 +617,9 @@ fn stamped_then_touch_lit() { assert!(TIME_B2 == md_t, "md_t: {:?} TIME_B2: {:?}", md_t, TIME_B2); // TODO: check contents Ok(()) - } - }).unwrap_or_panic("test error") + }, + }) + .unwrap_or_panic("test error") } #[test] @@ -592,8 +654,9 @@ fn stamped_then_touch_src() { assert!(TIME_B2 == md_t, "md_t: {:?} TIME_B2: {:?}", md_t, TIME_B2); // TODO: check contents Ok(()) - } - }).unwrap_or_panic("test error") + }, + }) + .unwrap_or_panic("test error") } #[test] @@ -641,6 +704,7 @@ fn stamped_then_update_src() { try!(f.read_to_string(&mut s)); assert!(s == HELLO_WORLD2_MD); Ok(()) - } - }).unwrap_or_panic("test error") + }, + }) + .unwrap_or_panic("test error") }