Merge branch 'master' of https://github.com/matthiasbeyer/imag into imag-task

This commit is contained in:
mario 2016-04-27 12:56:32 +02:00
commit e51ef38ad9
31 changed files with 255 additions and 142 deletions

View file

@ -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"
}

View file

@ -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());
}

View file

@ -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);
}
};

View file

@ -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();

View file

@ -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 <<EOS
---
[imag]
links = []
version = "0.1.0"
---
EOS
}
entry_linked_to() {
cat <<EOS
---
[imag]
links = [$1]
version = "0.1.0"
---
EOS
}
mktestentry() {
mkdir -p ${STORE}
default_entry > ${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

6
imag-link/tests/utils.sh Normal file
View file

@ -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 $*
}

View file

@ -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(&note.err().unwrap());
trace_error(&note.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);
}

View file

@ -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)

View file

@ -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();

View file

@ -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);
}
};

View file

@ -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());
}
}

View file

@ -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();

View file

@ -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();

View file

@ -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() {

View file

@ -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() {

View file

@ -1,5 +1,6 @@
#!/usr/bin/env bash
source $(dirname ${BASH_SOURCE[0]})/../../tests/utils.sh
source $(dirname ${BASH_SOURCE[0]})/utils.sh
create() {

View file

@ -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 $*
}

View file

@ -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();

View file

@ -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();

View file

@ -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()))));
}
}

View file

@ -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<Url> {
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<Option<Url>> {
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();

View file

@ -139,7 +139,7 @@ fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Vec<Link>> {
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();

View file

@ -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))))
})
})

View file

@ -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))))

View file

@ -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();

View file

@ -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<String> {
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<Vec<Tag>> {
self.entry.deref().get_tags()
self.entry.get_tags()
}
fn set_tags(&mut self, ts: Vec<Tag>) -> 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<bool> {
self.entry.deref().has_tag(t)
self.entry.has_tag(t)
}
fn has_tags(&self, ts: &Vec<Tag>) -> TagResult<bool> {
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,

View file

@ -17,6 +17,7 @@ use logger::ImagLogger;
use libimagstore::store::Store;
#[derive(Debug)]
pub struct Runtime<'a> {
rtp: PathBuf,
configuration: Option<Configuration>,
@ -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<Box<Error>> = Some(Box::new(e));
return Err(RuntimeError::new(RuntimeErrorKind::Instantiate, cause));

View file

@ -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<Option<Value>> {
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<Option<Value>> {
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<Option<Value>> {
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);

View file

@ -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 {

View file

@ -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());
}
}

79
tests/utils.sh Normal file
View file

@ -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
}