diff --git a/.travis.yml b/.travis.yml index d8b05f08..89211edd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ script: } run_sh_test() { - echo "--- Running test script: $1" + echo "--- Running test script: '$1'" bash $1 || { echo "--- Test failed. Exiting"; exit 1; } echo "--- Test script $1 executed successfully" } diff --git a/imag-counter/src/list.rs b/imag-counter/src/list.rs index 2d1c80bb..b7276957 100644 --- a/imag-counter/src/list.rs +++ b/imag-counter/src/list.rs @@ -15,11 +15,11 @@ pub fn list(rt: &Runtime) { let value = c.value(); if name.is_err() { - trace_error(&name.err().unwrap()); + trace_error(&name.unwrap_err()); } else { if value.is_err() { - trace_error(&value.err().unwrap()); + trace_error(&value.unwrap_err()); } else { println!("{} - {}", name.unwrap(), value.unwrap()); } diff --git a/imag-counter/src/main.rs b/imag-counter/src/main.rs index 964556e3..538149dc 100644 --- a/imag-counter/src/main.rs +++ b/imag-counter/src/main.rs @@ -59,7 +59,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; diff --git a/imag-link/src/main.rs b/imag-link/src/main.rs index d20bbac3..70f1d019 100644 --- a/imag-link/src/main.rs +++ b/imag-link/src/main.rs @@ -53,7 +53,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; @@ -200,7 +200,7 @@ fn handle_external_linking(rt: &Runtime) { let entry_name = scmd.value_of("id").unwrap(); // enforced by clap let entry = get_entry_by_name(rt, entry_name); if entry.is_err() { - trace_error(&entry.err().unwrap()); + trace_error(&entry.unwrap_err()); exit(1); } let mut entry = entry.unwrap(); @@ -238,7 +238,7 @@ fn add_link_to_entry(store: &Store, matches: &ArgMatches, entry: &mut FileLockEn let link = Url::parse(link); if link.is_err() { debug!("URL parsing error..."); - trace_error(&link.err().unwrap()); + trace_error(&link.unwrap_err()); debug!("Exiting"); exit(1); } @@ -258,7 +258,7 @@ fn remove_link_from_entry(store: &Store, matches: &ArgMatches, entry: &mut FileL let link = Url::parse(link); if link.is_err() { - trace_error(&link.err().unwrap()); + trace_error(&link.unwrap_err()); exit(1); } let link = link.unwrap(); diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh new file mode 100644 index 00000000..2caf8e99 --- /dev/null +++ b/imag-link/tests/link-test.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh +source $(dirname ${BASH_SOURCE[0]})/utils.sh + +default_entry() { + cat < ${STORE}/$1 +} + +test_link_modificates() { + mktestentry "test~0.1.0" + mktestentry "test2~0.1.0" + + imag-link internal add --from "test~0.1.0" --to "test2~0.1.0" + + if [[ "$(default_entry)" -eq "$(cat_entry 'test~0.1.0')" ]] || + [[ "$(default_entry)" -eq "$(cat_entry 'test2~0.1.0')" ]] + then + err "Entry was unmodified after linking" + return 1; + fi +} + +test_linking_links() { + mktestentry "test~0.1.0" + mktestentry "test2~0.1.0" + + imag-link internal add --from "test~0.1.0" --to "test2~0.1.0" + + if [[ "$(entry_linked_to '/test~0.1.0')" == "$(cat_entry 'test2~0.1.0')" ]]; + then + err "Linking to 'test~0.1.0' didn't succeed for 'test2~0.1.0'" + err $(cat_entry 'test2~0.1.0') + fi + + if [[ "$(entry_linked_to '/test2~0.1.0')" == "$(cat_entry 'test~0.1.0')" ]]; + then + err "Linking to 'test2~0.1.0' didn't succeed for 'test~0.1.0'" + err $(cat_entry 'test~0.1.0') + fi +} + +invoke_tests \ + test_link_modificates \ + test_linking_links + diff --git a/imag-link/tests/utils.sh b/imag-link/tests/utils.sh new file mode 100644 index 00000000..ff9e9975 --- /dev/null +++ b/imag-link/tests/utils.sh @@ -0,0 +1,6 @@ +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh + +imag-link() { + imag-call-binary "$(dirname ${BASH_SOURCE[0]})/../target/debug/" imag-link $* +} + diff --git a/imag-notes/src/main.rs b/imag-notes/src/main.rs index 1c6dedfb..bea757fa 100644 --- a/imag-notes/src/main.rs +++ b/imag-notes/src/main.rs @@ -29,7 +29,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; @@ -81,7 +81,7 @@ fn edit(rt: &Runtime) { fn edit_entry(rt: &Runtime, name: String) -> bool { let note = Note::retrieve(rt.store(), name); if note.is_err() { - trace_error(¬e.err().unwrap()); + trace_error(¬e.unwrap_err()); warn!("Cannot edit nonexistent Note"); return false } @@ -100,7 +100,7 @@ fn list(rt: &Runtime) { let iter = Note::all_notes(rt.store()); if iter.is_err() { - trace_error(&iter.err().unwrap()); + trace_error(&iter.unwrap_err()); exit(1); } diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs index 9d90f642..a8b85ad3 100644 --- a/imag-store/src/create.rs +++ b/imag-store/src/create.rs @@ -32,13 +32,13 @@ pub fn create(rt: &Runtime) { let path = scmd.value_of("path").or_else(|| scmd.value_of("id")); if path.is_none() { warn!("No ID / Path provided. Exiting now"); - write!(stderr(), "No ID / Path provided. Exiting now"); + write!(stderr(), "No ID / Path provided. Exiting now").ok(); exit(1); } let path = build_entry_path(rt.store(), path.unwrap()); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); @@ -101,14 +101,15 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &PathBuf) -> Res debug!("Content with len = {}", content.len()); Entry::from_str(path.clone(), &content[..]) - .map(|mut new_e| { - rt.store() + .and_then(|new_e| { + let r = rt.store() .create(path.clone()) .map(|mut old_e| { *old_e.deref_mut() = new_e; }); debug!("Entry build"); + r }) .map_err(|serr| StoreError::new(StoreErrorKind::BackendError, Some(Box::new(serr)))) } @@ -144,7 +145,7 @@ fn string_from_raw_src(raw_src: &str) -> String { debug!("Read {:?} bytes", res); } else { debug!("Reading entry from file at {:?}", raw_src); - OpenOptions::new() + let _ = OpenOptions::new() .read(true) .write(false) .create(false) diff --git a/imag-store/src/delete.rs b/imag-store/src/delete.rs index 71bf0f91..0c59fc37 100644 --- a/imag-store/src/delete.rs +++ b/imag-store/src/delete.rs @@ -1,5 +1,3 @@ -use std::path::PathBuf; - use libimagstore::storeid::build_entry_path; use libimagrt::runtime::Runtime; use libimagutil::trace::trace_error; @@ -14,7 +12,7 @@ pub fn delete(rt: &Runtime) { .map(|id| { let path = build_entry_path(rt.store(), id); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); diff --git a/imag-store/src/main.rs b/imag-store/src/main.rs index 4b5968d7..a1e9e09a 100644 --- a/imag-store/src/main.rs +++ b/imag-store/src/main.rs @@ -1,3 +1,18 @@ +#![deny( + non_camel_case_types, + non_snake_case, + path_statements, + trivial_numeric_casts, + unstable_features, + unused_allocation, + unused_import_braces, + unused_imports, + unused_must_use, + unused_mut, + unused_qualifications, + while_true, +)] + extern crate clap; #[macro_use] extern crate log; extern crate semver; @@ -36,7 +51,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs index cc43ece2..c6b6adc8 100644 --- a/imag-store/src/retrieve.rs +++ b/imag-store/src/retrieve.rs @@ -1,6 +1,3 @@ -use std::path::PathBuf; -use std::ops::Deref; -use std::fmt::Display; use std::process::exit; use clap::ArgMatches; @@ -19,7 +16,7 @@ pub fn retrieve(rt: &Runtime) { .map(|id| { let path = build_entry_path(rt.store(), id); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); @@ -41,7 +38,7 @@ pub fn retrieve(rt: &Runtime) { fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { if do_print_raw(scmd) { debug!("Printing raw content..."); - println!("{}", e.deref().to_str()); + println!("{}", e.to_str()); } else if do_filter(scmd) { debug!("Filtering..."); warn!("Filtering via header specs is currently now supported."); @@ -49,7 +46,6 @@ fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { unimplemented!() } else { debug!("Printing structured..."); - let entry = e.deref(); if do_print_header(scmd) { debug!("Printing header..."); if do_print_header_as_json(rt.cli()) { @@ -60,13 +56,13 @@ fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) { } else { debug!("Printing header as TOML..."); // We have to Value::Table() for Display - println!("{}", Value::Table(entry.get_header().clone().into())) + println!("{}", Value::Table(e.get_header().clone().into())) } } if do_print_content(scmd) { debug!("Printing content..."); - println!("{}", entry.get_content()); + println!("{}", e.get_content()); } } diff --git a/imag-store/src/update.rs b/imag-store/src/update.rs index d37da1c2..311ce138 100644 --- a/imag-store/src/update.rs +++ b/imag-store/src/update.rs @@ -1,4 +1,3 @@ -use std::path::PathBuf; use std::ops::DerefMut; use std::process::exit; @@ -16,7 +15,7 @@ pub fn update(rt: &Runtime) { .map(|id| { let path = build_entry_path(rt.store(), id); if path.is_err() { - trace_error(&path.err().unwrap()); + trace_error(&path.unwrap_err()); exit(1); } let path = path.unwrap(); diff --git a/imag-store/src/util.rs b/imag-store/src/util.rs index 61832e3a..f14d462b 100644 --- a/imag-store/src/util.rs +++ b/imag-store/src/util.rs @@ -1,16 +1,13 @@ use std::collections::BTreeMap; -use std::path::PathBuf; use std::str::Split; use clap::ArgMatches; -use semver::Version; use toml::Value; use libimagstore::store::EntryHeader; -use libimagrt::runtime::Runtime; use libimagutil::key_value_split::IntoKeyValue; -pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> EntryHeader { +pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHeader { debug!("Building header from cli spec"); if let Some(headerspecs) = matches.values_of("header") { let mut main = header.into(); diff --git a/imag-store/tests/001-create_test.sh b/imag-store/tests/001-create_test.sh index 91720c9f..823d8488 100644 --- a/imag-store/tests/001-create_test.sh +++ b/imag-store/tests/001-create_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh test_call() { diff --git a/imag-store/tests/002-retrieve_test.sh b/imag-store/tests/002-retrieve_test.sh index 33b96780..4e2c7d7c 100644 --- a/imag-store/tests/002-retrieve_test.sh +++ b/imag-store/tests/002-retrieve_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh std_header() { diff --git a/imag-store/tests/003-delete_test.sh b/imag-store/tests/003-delete_test.sh index 794f1ad8..9beaba82 100644 --- a/imag-store/tests/003-delete_test.sh +++ b/imag-store/tests/003-delete_test.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash +source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh source $(dirname ${BASH_SOURCE[0]})/utils.sh create() { diff --git a/imag-store/tests/utils.sh b/imag-store/tests/utils.sh index 148eaf87..adf6cd88 100644 --- a/imag-store/tests/utils.sh +++ b/imag-store/tests/utils.sh @@ -1,65 +1,6 @@ -#!/usr/bin/env bash - -COLOR_OFF='\e[0m' # Text Reset -RED='\e[0;31m' # Red -YELLOW='\e[0;33m' # Yellow -GREEN='\e[0;32m' # Green - -RUNTIME="/tmp" -STORE="${RUNTIME}/store" - -out() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}" -} - -success() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}" -} - -err() { - [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}" -} - -silent() { - DEBUG_OUTPUT_OFF=1 $* -} +source $(dirname ${BASH_SOURCE[0]})/../tests/utils.sh imag-store() { - local searchdir=$(dirname ${BASH_SOURCE[0]})/../target/debug/ - [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } - local bin=$(find $searchdir -iname imag-store -type f -executable) - local flags="--debug --rtp $RUNTIME" - out "Calling '$bin $flags $*'" - $bin $flags $* -} - -reset_store() { - rm -r "${STORE}" -} - -call_test() { - out "-- TESTING: '$1' --" - $1 - result=$? - if [[ -z "$DONT_RESET_STORE" ]]; then - out "Reseting store" - reset_store - out "Store reset done" - fi - [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } - success "-- SUCCESS: '$1' --" -} - -invoke_tests() { - out "Invoking tests." - if [[ ! -z "$INVOKE_TEST" ]]; then - out "Invoking only $INVOKE_TEST" - call_test "$INVOKE_TEST" - else - out "Invoking $*" - for t in $*; do - call_test "$t" - done - fi + imag-call-binary "$(dirname ${BASH_SOURCE[0]})/../target/debug/" imag-store $* } diff --git a/imag-tag/src/main.rs b/imag-tag/src/main.rs index 2b6201dc..e1a35a34 100644 --- a/imag-tag/src/main.rs +++ b/imag-tag/src/main.rs @@ -32,7 +32,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); } }; @@ -127,7 +127,7 @@ fn list(id: &str, rt: &Runtime) { if entry.is_err() { debug!("Could not retrieve '{:?}' => {:?}", id, path); warn!("Could not retrieve entry '{}'", id); - trace_error(&entry.err().unwrap()); + trace_error(&entry.unwrap_err()); exit(1); } let entry = entry.unwrap(); @@ -146,7 +146,7 @@ fn list(id: &str, rt: &Runtime) { let tags = entry.get_tags(); if tags.is_err() { - trace_error(&tags.err().unwrap()); + trace_error(&tags.unwrap_err()); exit(1); } let tags = tags.unwrap(); diff --git a/imag-view/src/main.rs b/imag-view/src/main.rs index 1f18ca17..f12e639d 100644 --- a/imag-view/src/main.rs +++ b/imag-view/src/main.rs @@ -54,7 +54,7 @@ fn main() { rt.unwrap() } else { println!("Could not set up Runtime"); - println!("{:?}", rt.err().unwrap()); + println!("{:?}", rt.unwrap_err()); exit(1); // we can afford not-executing destructors here } }; @@ -102,7 +102,7 @@ fn main() { let entry = load_entry(entry_id, entry_version, &rt); if entry.is_err() { - trace_error(&entry.err().unwrap()); + trace_error(&entry.unwrap_err()); exit(1); // we can afford not-executing destructors here } let entry = entry.unwrap(); diff --git a/libimagcounter/src/counter.rs b/libimagcounter/src/counter.rs index bea7537e..2285071f 100644 --- a/libimagcounter/src/counter.rs +++ b/libimagcounter/src/counter.rs @@ -39,17 +39,17 @@ impl<'a> Counter<'a> { let mut header = entry.get_header_mut(); let setres = header.set("counter", Value::Table(BTreeMap::new())); if setres.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.unwrap_err())))); } let setres = header.set("counter.name", Value::String(name)); if setres.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.unwrap_err())))); } let setres = header.set("counter.value", Value::Integer(init)); if setres.is_err() { - return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.err().unwrap())))); + return Err(CE::new(CEK::StoreWriteError, Some(Box::new(setres.unwrap_err())))); } } diff --git a/libimagentrylink/src/external.rs b/libimagentrylink/src/external.rs index 9df53cca..e99abf42 100644 --- a/libimagentrylink/src/external.rs +++ b/libimagentrylink/src/external.rs @@ -11,7 +11,6 @@ /// This helps us greatly with deduplication of URLs. /// -use std::ops::Deref; use std::ops::DerefMut; use std::collections::BTreeMap; @@ -60,8 +59,7 @@ impl<'a> Link<'a> { /// Get a link Url object from a FileLockEntry, ignore errors. fn get_link_uri_from_filelockentry(file: &FileLockEntry<'a>) -> Option { - file.deref() - .get_header() + file.get_header() .read("imag.content.uri") .ok() .and_then(|opt| { @@ -74,7 +72,6 @@ impl<'a> Link<'a> { pub fn get_url(&self) -> Result> { let opt = self.link - .deref() .get_header() .read("imag.content.uri"); @@ -173,7 +170,7 @@ impl ExternalLinker for Entry { let file = store.retrieve(file_id.clone()); if file.is_err() { debug!("Failed to create or retrieve an file for this link '{:?}'", link); - return Err(LE::new(LEK::StoreWriteError, Some(Box::new(file.err().unwrap())))); + return Err(LE::new(LEK::StoreWriteError, Some(Box::new(file.unwrap_err())))); } let mut file = file.unwrap(); diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs index e22214d1..a410349a 100644 --- a/libimagentrylink/src/internal.rs +++ b/libimagentrylink/src/internal.rs @@ -139,7 +139,7 @@ fn process_rw_result(links: StoreResult>) -> Result> { if links.is_err() { debug!("RW action on store failed. Generating LinkError"); let lerr = LinkError::new(LinkErrorKind::EntryHeaderReadError, - Some(Box::new(links.err().unwrap()))); + Some(Box::new(links.unwrap_err()))); return Err(lerr); } let links = links.unwrap(); diff --git a/libimagentrylist/src/listers/core.rs b/libimagentrylist/src/listers/core.rs index e7c5bb84..8c7ccf72 100644 --- a/libimagentrylist/src/listers/core.rs +++ b/libimagentrylist/src/listers/core.rs @@ -1,6 +1,5 @@ use std::io::stdout; use std::io::Write; -use std::ops::Deref; use lister::Lister; use result::Result; @@ -30,7 +29,7 @@ impl<'a> Lister for CoreLister<'a> { entries.fold(Ok(()), |accu, entry| { accu.and_then(|_| { - write!(stdout(), "{:?}\n", (self.lister)(entry.deref())) + write!(stdout(), "{:?}\n", (self.lister)(&entry)) .map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e)))) }) }) diff --git a/libimagentrylist/src/listers/path.rs b/libimagentrylist/src/listers/path.rs index 285802e2..0f1deac5 100644 --- a/libimagentrylist/src/listers/path.rs +++ b/libimagentrylist/src/listers/path.rs @@ -1,6 +1,5 @@ use std::io::stdout; use std::io::Write; -use std::ops::Deref; use lister::Lister; use result::Result; @@ -28,7 +27,7 @@ impl Lister for PathLister { use error::ListErrorKind as LEK; entries.fold(Ok(()), |accu, entry| { - accu.and_then(|_| Ok(entry.deref().get_location().clone())) + accu.and_then(|_| Ok(entry.get_location().clone())) .and_then(|pb| { if self.absolute { pb.canonicalize().map_err(|e| LE::new(LEK::FormatError, Some(Box::new(e)))) diff --git a/libimagentrytag/src/tagable.rs b/libimagentrytag/src/tagable.rs index bd478a97..4dbe4efb 100644 --- a/libimagentrytag/src/tagable.rs +++ b/libimagentrytag/src/tagable.rs @@ -31,7 +31,7 @@ impl Tagable for EntryHeader { let tags = self.read("imag.tags"); if tags.is_err() { let kind = TagErrorKind::HeaderReadError; - return Err(TagError::new(kind, Some(Box::new(tags.err().unwrap())))); + return Err(TagError::new(kind, Some(Box::new(tags.unwrap_err())))); } let tags = tags.unwrap(); @@ -106,7 +106,7 @@ impl Tagable for EntryHeader { let tags = self.read("imag.tags"); if tags.is_err() { let kind = TagErrorKind::HeaderReadError; - return Err(TagError::new(kind, Some(Box::new(tags.err().unwrap())))); + return Err(TagError::new(kind, Some(Box::new(tags.unwrap_err())))); } let tags = tags.unwrap(); @@ -129,7 +129,7 @@ impl Tagable for EntryHeader { for tag in tags { let check = self.has_tag(tag); if check.is_err() { - return Err(check.err().unwrap()); + return Err(check.unwrap_err()); } let check = check.unwrap(); diff --git a/libimagnotes/src/note.rs b/libimagnotes/src/note.rs index 4f30b3c6..2728b768 100644 --- a/libimagnotes/src/note.rs +++ b/libimagnotes/src/note.rs @@ -19,6 +19,7 @@ use result::Result; use error::NoteError as NE; use error::NoteErrorKind as NEK; +#[derive(Debug)] pub struct Note<'a> { entry: FileLockEntry<'a>, } @@ -32,7 +33,7 @@ impl<'a> Note<'a> { let fle = { let lockentry = store.create(ModuleEntryPath::new(name.clone()).into_storeid()); if lockentry.is_err() { - return Err(NE::new(NEK::StoreWriteError, Some(Box::new(lockentry.err().unwrap())))); + return Err(NE::new(NEK::StoreWriteError, Some(Box::new(lockentry.unwrap_err())))); } let mut lockentry = lockentry.unwrap(); @@ -44,13 +45,13 @@ impl<'a> Note<'a> { let setres = header.set("note", Value::Table(BTreeMap::new())); if setres.is_err() { let kind = NEK::StoreWriteError; - return Err(NE::new(kind, Some(Box::new(setres.err().unwrap())))); + return Err(NE::new(kind, Some(Box::new(setres.unwrap_err())))); } let setres = header.set("note.name", Value::String(name)); if setres.is_err() { let kind = NEK::StoreWriteError; - return Err(NE::new(kind, Some(Box::new(setres.err().unwrap())))); + return Err(NE::new(kind, Some(Box::new(setres.unwrap_err())))); } } @@ -64,14 +65,14 @@ impl<'a> Note<'a> { } pub fn set_name(&mut self, n: String) -> Result<()> { - let mut header = self.entry.deref_mut().get_header_mut(); + let mut header = self.entry.get_header_mut(); header.set("note.name", Value::String(n)) .map_err(|e| NE::new(NEK::StoreWriteError, Some(Box::new(e)))) .map(|_| ()) } pub fn get_name(&self) -> Result { - let header = self.entry.deref().get_header(); + let header = self.entry.get_header(); match header.read("note.name") { Ok(Some(Value::String(s))) => Ok(String::from(s)), Ok(_) => { @@ -83,11 +84,11 @@ impl<'a> Note<'a> { } pub fn set_text(&mut self, n: String) { - *self.entry.deref_mut().get_content_mut() = n + *self.entry.get_content_mut() = n } pub fn get_text(&self) -> &String { - self.entry.deref().get_content() + self.entry.get_content() } pub fn delete(store: &Store, name: String) -> Result<()> { @@ -120,27 +121,27 @@ impl<'a> Edit for Note<'a> { impl<'a> Tagable for Note<'a> { fn get_tags(&self) -> TagResult> { - self.entry.deref().get_tags() + self.entry.get_tags() } fn set_tags(&mut self, ts: Vec) -> TagResult<()> { - self.entry.deref_mut().set_tags(ts) + self.entry.set_tags(ts) } fn add_tag(&mut self, t: Tag) -> TagResult<()> { - self.entry.deref_mut().add_tag(t) + self.entry.add_tag(t) } fn remove_tag(&mut self, t: Tag) -> TagResult<()> { - self.entry.deref_mut().remove_tag(t) + self.entry.remove_tag(t) } fn has_tag(&self, t: &Tag) -> TagResult { - self.entry.deref().has_tag(t) + self.entry.has_tag(t) } fn has_tags(&self, ts: &Vec) -> TagResult { - self.entry.deref().has_tags(ts) + self.entry.has_tags(ts) } } @@ -171,6 +172,7 @@ impl<'a> Deref for Note<'a> { } +#[derive(Debug)] pub struct NoteIterator<'a> { store: &'a Store, iditer: StoreIdIterator, diff --git a/libimagrt/src/runtime.rs b/libimagrt/src/runtime.rs index b89bf5b4..7319958f 100644 --- a/libimagrt/src/runtime.rs +++ b/libimagrt/src/runtime.rs @@ -17,6 +17,7 @@ use logger::ImagLogger; use libimagstore::store::Store; +#[derive(Debug)] pub struct Runtime<'a> { rtp: PathBuf, configuration: Option, @@ -73,7 +74,7 @@ impl<'a> Runtime<'a> { let cfg = Configuration::new(&rtp); let cfg = if cfg.is_err() { - let e = cfg.err().unwrap(); + let e = cfg.unwrap_err(); if e.err_type() != ConfigErrorKind::NoConfigFileFound { let cause : Option> = Some(Box::new(e)); return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause)); diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index fe38518c..9d174e24 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -156,7 +156,7 @@ impl Store { if c.is_err() { debug!("Failed"); return Err(StoreError::new(StoreErrorKind::StorePathCreate, - Some(Box::new(c.err().unwrap())))); + Some(Box::new(c.unwrap_err())))); } } else { if location.is_file() { @@ -537,6 +537,7 @@ impl Drop for Store { } /// A struct that allows you to borrow an Entry +#[derive(Debug)] pub struct FileLockEntry<'a> { store: &'a Store, entry: Entry, @@ -553,7 +554,7 @@ impl<'a> FileLockEntry<'a, > { } } -impl<'a> ::std::ops::Deref for FileLockEntry<'a> { +impl<'a> Deref for FileLockEntry<'a> { type Target = Entry; fn deref(&self) -> &Self::Target { @@ -561,7 +562,7 @@ impl<'a> ::std::ops::Deref for FileLockEntry<'a> { } } -impl<'a> ::std::ops::DerefMut for FileLockEntry<'a> { +impl<'a> DerefMut for FileLockEntry<'a> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.entry } @@ -764,7 +765,7 @@ impl EntryHeader { pub fn set_with_sep(&mut self, spec: &str, sep: char, v: Value) -> Result> { let tokens = EntryHeader::tokenize(spec, sep); if tokens.is_err() { // return parser error if any - return Err(tokens.err().unwrap()); + return Err(tokens.unwrap_err()); } let tokens = tokens.unwrap(); debug!("tokens = {:?}", tokens); @@ -779,7 +780,7 @@ impl EntryHeader { let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { - return Err(value.err().unwrap()); + return Err(value.unwrap_err()); } let mut value = value.unwrap(); debug!("walked value = {:?}", value); @@ -871,14 +872,14 @@ impl EntryHeader { pub fn read_with_sep(&self, spec: &str, splitchr: char) -> Result> { let tokens = EntryHeader::tokenize(spec, splitchr); if tokens.is_err() { // return parser error if any - return Err(tokens.err().unwrap()); + return Err(tokens.unwrap_err()); } let tokens = tokens.unwrap(); let mut header_clone = self.header.clone(); // we clone as READing is simpler this way let value = EntryHeader::walk_header(&mut header_clone, tokens); // walk N-1 tokens if value.is_err() { - let e = value.err().unwrap(); + let e = value.unwrap_err(); return match e.err_type() { // We cannot find the header key, as there is no path to it StoreErrorKind::HeaderKeyNotFound => Ok(None), @@ -891,7 +892,7 @@ impl EntryHeader { pub fn delete(&mut self, spec: &str) -> Result> { let tokens = EntryHeader::tokenize(spec, '.'); if tokens.is_err() { // return parser error if any - return Err(tokens.err().unwrap()); + return Err(tokens.unwrap_err()); } let tokens = tokens.unwrap(); @@ -905,7 +906,7 @@ impl EntryHeader { let path_to_dest = tokens[..(tokens.len() - 1)].into(); // N - 1 tokens let value = EntryHeader::walk_header(&mut self.header, path_to_dest); // walk N-1 tokens if value.is_err() { - return Err(value.err().unwrap()); + return Err(value.unwrap_err()); } let mut value = value.unwrap(); debug!("walked value = {:?}", value); diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 35c3c0f8..7c5940c1 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -1,6 +1,9 @@ use std::path::PathBuf; use glob::Paths; use semver::Version; +use std::fmt::{Debug, Formatter}; +use std::fmt::Error as FmtError; +use std::result::Result as RResult; use error::{StoreError, StoreErrorKind}; use store::Result; @@ -94,6 +97,14 @@ pub struct StoreIdIterator { paths: Paths, } +impl Debug for StoreIdIterator { + + fn fmt(&self, fmt: &mut Formatter) -> RResult<(), FmtError> { + write!(fmt, "StoreIdIterator") + } + +} + impl StoreIdIterator { pub fn new(paths: Paths) -> StoreIdIterator { diff --git a/libimagutil/src/trace.rs b/libimagutil/src/trace.rs index f075f037..5b22c84c 100644 --- a/libimagutil/src/trace.rs +++ b/libimagutil/src/trace.rs @@ -55,7 +55,7 @@ fn print_trace_maxdepth(idx: u64, e: &Error, max: u64) -> Option<&Error> { } else { write!(stderr(), "\n").ok(); } - write!(stderr(), "Error {:>4} : {}", idx, e.description()).ok(); + write!(stderr(), "ERROR[{:>4}]: {}", idx, e.description()).ok(); e.cause() } @@ -65,9 +65,8 @@ fn count_error_causes(e: &Error) -> u64 { } fn print_trace_dbg(idx: u64, e: &Error) { - debug!("Error {:>4} : {}", idx, e.description()); + debug!("ERROR[{:>4}]: {}", idx, e.description()); if e.cause().is_some() { - debug!(" -- caused by:"); print_trace_dbg(idx + 1, e.cause().unwrap()); } } diff --git a/tests/utils.sh b/tests/utils.sh new file mode 100644 index 00000000..6fc23ad8 --- /dev/null +++ b/tests/utils.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +# +# +# This file contains test utility functions which are used by the test scripts +# for each binary. +# +# + + +COLOR_OFF='\e[0m' # Text Reset +RED='\e[0;31m' # Red +YELLOW='\e[0;33m' # Yellow +GREEN='\e[0;32m' # Green + +RUNTIME="/tmp" +STORE="${RUNTIME}/store" + +out() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${YELLOW}:: $*${COLOR_OFF}" +} + +success() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${GREEN}>> $*${COLOR_OFF}" +} + +err() { + [[ -z "$DEBUG_OUTPUT_OFF" ]] && echo -e "${RED}!! $*${COLOR_OFF}" +} + +silent() { + DEBUG_OUTPUT_OFF=1 $* +} + +imag-call-binary() { + local searchdir=$1; shift + local binary=$1; shift + [[ -d $searchdir ]] || { err "FATAL: No directory $searchdir"; exit 1; } + local bin=$(find $searchdir -iname $binary -type f -executable) + local flags="--debug --rtp $RUNTIME" + out "Calling '$bin $flags $*'" + $bin $flags $* +} + +cat_entry() { + cat ${STORE}/$1 +} + +reset_store() { + rm -r "${STORE}" +} + +call_test() { + out "-- TESTING: '$1' --" + $1 + result=$? + if [[ -z "$DONT_RESET_STORE" ]]; then + out "Reseting store" + reset_store + out "Store reset done" + fi + [[ $result -eq 0 ]] || { err "-- FAILED: '$1'. Exiting."; exit 1; } + success "-- SUCCESS: '$1' --" +} + +invoke_tests() { + out "Invoking tests." + if [[ ! -z "$INVOKE_TEST" ]]; then + out "Invoking only $INVOKE_TEST" + call_test "$INVOKE_TEST" + else + out "Invoking $*" + for t in $*; do + call_test "$t" + done + fi +} + +