From 7317c2425e3fd07efdc92eee9f7557c48a6ec7d1 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 25 Oct 2020 15:04:04 -0400 Subject: [PATCH] a few fixes for readablilty --- src/cmd/cut.rs | 2 +- src/version/cargo.rs | 9 +++++++++ src/version/mod.rs | 10 +++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/cmd/cut.rs b/src/cmd/cut.rs index 2b21f8c..26e9967 100644 --- a/src/cmd/cut.rs +++ b/src/cmd/cut.rs @@ -9,7 +9,7 @@ pub async fn run( rm: ReleaseMeta, ) -> Result<()> { let repo = git2::Repository::open(".")?; - let tag = tag.unwrap_or(version::read_version("VERSION".into())?); + let tag = tag.unwrap_or(version::read("VERSION".into())?); let vtag = format!("v{}", tag); if git::has_tag(&repo, vtag.clone())? { diff --git a/src/version/cargo.rs b/src/version/cargo.rs index 24a7a2b..6f16407 100644 --- a/src/version/cargo.rs +++ b/src/version/cargo.rs @@ -27,3 +27,12 @@ pub fn read() -> Result> { None => Ok(None) } } + +#[cfg(test)] +mod tests { + #[test] + fn read() { + use super::read; + read().unwrap().unwrap(); + } +} diff --git a/src/version/mod.rs b/src/version/mod.rs index ad5c36e..65deeec 100644 --- a/src/version/mod.rs +++ b/src/version/mod.rs @@ -3,18 +3,22 @@ use std::{fs, path::PathBuf}; mod cargo; -pub(crate) fn read_version(fname: PathBuf) -> Result { +pub(crate) fn read(fname: PathBuf) -> Result { let version = cargo::read() .unwrap() - .unwrap_or(fs::read_to_string(fname)?.trim().into()); + .unwrap_or(read_fs(fname)?); Ok(version) } +fn read_fs(fname: PathBuf) -> Result { + Ok(fs::read_to_string(fname)?.trim().into()) +} + #[cfg(test)] mod tests { #[test] fn read_version() { - let version = super::read_version("./testdata/VERSION".into()).unwrap(); + let version = super::read_fs("./testdata/VERSION".into()).unwrap(); assert_eq!(version, "0.1.0"); } }