a few fixes for readablilty

This commit is contained in:
Cadey Ratio 2020-10-25 15:04:04 -04:00
parent 26894c7fad
commit 7317c2425e
3 changed files with 17 additions and 4 deletions

View File

@ -9,7 +9,7 @@ pub async fn run(
rm: ReleaseMeta, rm: ReleaseMeta,
) -> Result<()> { ) -> Result<()> {
let repo = git2::Repository::open(".")?; 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); let vtag = format!("v{}", tag);
if git::has_tag(&repo, vtag.clone())? { if git::has_tag(&repo, vtag.clone())? {

View File

@ -27,3 +27,12 @@ pub fn read() -> Result<Option<String>> {
None => Ok(None) None => Ok(None)
} }
} }
#[cfg(test)]
mod tests {
#[test]
fn read() {
use super::read;
read().unwrap().unwrap();
}
}

View File

@ -3,18 +3,22 @@ use std::{fs, path::PathBuf};
mod cargo; mod cargo;
pub(crate) fn read_version(fname: PathBuf) -> Result<String> { pub(crate) fn read(fname: PathBuf) -> Result<String> {
let version = cargo::read() let version = cargo::read()
.unwrap() .unwrap()
.unwrap_or(fs::read_to_string(fname)?.trim().into()); .unwrap_or(read_fs(fname)?);
Ok(version) Ok(version)
} }
fn read_fs(fname: PathBuf) -> Result<String> {
Ok(fs::read_to_string(fname)?.trim().into())
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[test] #[test]
fn read_version() { 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"); assert_eq!(version, "0.1.0");
} }
} }