summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-11-03 11:57:15 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-11-03 11:57:15 +0100
commit7b6e5eafbaadd1cd898cd3cf78b7559b98d7af81 (patch)
treecd974ebeaaeee887918884557edfcc46312a9567
parentd51c1e99b982ea7dc884d8e4cc6f7780911266fd (diff)
parentd68797a1156c5ad228b6b4e30e89ef82d15b167a (diff)
downloadimag-7b6e5eafbaadd1cd898cd3cf78b7559b98d7af81.tar.gz
imag-7b6e5eafbaadd1cd898cd3cf78b7559b98d7af81.tar.xz
-rw-r--r--Cargo.toml2
-rw-r--r--tests/ui/Cargo.toml22
-rw-r--r--tests/ui/README.md13
-rw-r--r--tests/ui/src/imag.rs86
-rw-r--r--tests/ui/src/imag_annotate.rs19
-rw-r--r--tests/ui/src/imag_bookmark.rs19
-rw-r--r--tests/ui/src/imag_calendar.rs19
-rw-r--r--tests/ui/src/imag_category.rs70
-rw-r--r--tests/ui/src/imag_contact.rs19
-rw-r--r--tests/ui/src/imag_create.rs76
-rw-r--r--tests/ui/src/imag_diagnostics.rs19
-rw-r--r--tests/ui/src/imag_diary.rs19
-rw-r--r--tests/ui/src/imag_edit.rs19
-rw-r--r--tests/ui/src/imag_git.rs19
-rw-r--r--tests/ui/src/imag_gps.rs19
-rw-r--r--tests/ui/src/imag_grep.rs119
-rw-r--r--tests/ui/src/imag_habit.rs19
-rw-r--r--tests/ui/src/imag_header.rs76
-rw-r--r--tests/ui/src/imag_id_in_collection.rs19
-rw-r--r--tests/ui/src/imag_ids.rs62
-rw-r--r--tests/ui/src/imag_init.rs110
-rw-r--r--tests/ui/src/imag_link.rs19
-rw-r--r--tests/ui/src/imag_log.rs19
-rw-r--r--tests/ui/src/imag_mail.rs19
-rw-r--r--tests/ui/src/imag_markdown.rs19
-rw-r--r--tests/ui/src/imag_mv.rs60
-rw-r--r--tests/ui/src/imag_notes.rs19
-rw-r--r--tests/ui/src/imag_ref.rs19
-rw-r--r--tests/ui/src/imag_store.rs19
-rw-r--r--tests/ui/src/imag_tag.rs96
-rw-r--r--tests/ui/src/imag_timetrack.rs19
-rw-r--r--tests/ui/src/imag_todo.rs19
-rw-r--r--tests/ui/src/imag_view.rs19
-rw-r--r--tests/ui/src/imag_wiki.rs19
-rw-r--r--tests/ui/src/lib.rs65
35 files changed, 1275 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 1e52bdaf..c0d00e03 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -61,4 +61,6 @@ members = [
"lib/etc/libimaginteraction",
"lib/etc/libimagtimeui",
"lib/etc/libimagutil",
+
+ "tests/ui",
]
diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml
new file mode 100644
index 00000000..3d601d03
--- /dev/null
+++ b/tests/ui/Cargo.toml
@@ -0,0 +1,22 @@
+[package]
+name = "tests-ui"
+version = "0.10.0"
+authors = ["Matthias Beyer <mail@beyermatthias.de>"]
+edition = "2018"
+
+# We do not publish this crate because it contains tests which should only be
+# available during development and CI runs, but there's nothing that a user of
+# any imag command might need, ever.
+publish = false
+
+[dependencies]
+assert_cmd = "0.11"
+assert_fs = "0.11"
+duct = "0.13"
+env_logger = "0.7"
+log = "0.4"
+predicates = "1"
+pretty_assertions = "0.6"
+semver = "0.9"
+version = "3"
+
diff --git a/tests/ui/README.md b/tests/ui/README.md
new file mode 100644
index 00000000..4cbe40ac
--- /dev/null
+++ b/tests/ui/README.md
@@ -0,0 +1,13 @@
+# UI testing
+
+This crate is just a helper crate for CI runs and development. It contains
+test code which tests the actual imag binaries and their user interfaces and
+behaviour.
+
+Tests are automatically done in temporary directories.
+The test setup removes these testing directories after tests have run.
+To prevent this, set `IMAG_UI_TEST_PERSIST`.
+
+Use the normal `RUST_LOG` functionality for logging (or see the documentation
+for the `env_logger` crate).
+
diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs
new file mode 100644
index 00000000..fb413ab3
--- /dev/null
+++ b/tests/ui/src/imag.rs
@@ -0,0 +1,86 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+use std::path::PathBuf;
+
+use assert_fs::fixture::TempDir;
+use assert_cmd::prelude::*;
+use assert_cmd::assert::Assert;
+
+pub fn make_temphome() -> TempDir {
+ TempDir::new().unwrap().persist_if(std::env::var("IMAG_UI_TEST_PERSIST").is_ok())
+}
+
+pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command {
+ let path = tempdir.path()
+ .to_str()
+ .map(String::from)
+ .unwrap_or_else(|| panic!("Cannot create imag home path string"));
+
+ let mut cmd = Command::cargo_bin(binary_name).unwrap();
+ cmd.arg("--rtp");
+ cmd.arg(path);
+ cmd
+}
+
+/// Run the passed command and get the stdout of it.
+///
+/// This function does _not_ ensure that stdin is inherited.
+pub fn stdout_of_command(mut command: Command) -> Vec<String> {
+ let assert = command.assert();
+ let lines = String::from_utf8(assert.get_output().stdout.clone())
+ .unwrap()
+ .lines()
+ .map(String::from)
+ .collect();
+ assert.success();
+ lines
+}
+
+/// Run the passed command and get the stderr of it.
+///
+/// This function does _not_ ensure that stdin is inherited.
+pub fn stderr_of_command(command: &mut Command) -> (Assert, Vec<String>) {
+ let assert = command.assert();
+ let lines = String::from_utf8(assert.get_output().stderr.clone())
+ .unwrap()
+ .lines()
+ .map(String::from)
+ .collect();
+ (assert, lines)
+}
+
+/// Create a PathBuf for a file in a TempDir
+pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf {
+ create_path_for(tempdir.path().to_path_buf(), path_elements)
+}
+
+pub fn store_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf {
+ let mut path = tempdir.path().to_path_buf();
+ path.push("store");
+ create_path_for(path, path_elements)
+}
+
+fn create_path_for(mut path: PathBuf, path_elements: &[&str]) -> PathBuf {
+ path_elements.iter().for_each(|el| path.push(el));
+ debug!("Calculated path = {:?}", path);
+ path
+}
+
diff --git a/tests/ui/src/imag_annotate.rs b/tests/ui/src/imag_annotate.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_annotate.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_bookmark.rs b/tests/ui/src/imag_bookmark.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_bookmark.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_calendar.rs b/tests/ui/src/imag_calendar.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_calendar.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_category.rs b/tests/ui/src/imag_category.rs
new file mode 100644
index 00000000..cc2bfc42
--- /dev/null
+++ b/tests/ui/src/imag_category.rs
@@ -0,0 +1,70 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+
+use assert_fs::fixture::TempDir;
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-category")
+}
+
+pub fn call(tmpdir: &TempDir, args: &[&str]) -> Vec<String> {
+ let mut binary = binary(tmpdir);
+ binary.stdin(std::process::Stdio::inherit());
+ binary.arg("--ignore-ids");
+ binary.args(args);
+ debug!("Command = {:?}", binary);
+ crate::imag::stdout_of_command(binary)
+}
+
+#[test]
+fn test_new_entry_has_no_category() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+
+ let (assert, stderr_output) = {
+ let mut binary = binary(&imag_home);
+ binary.stdin(std::process::Stdio::inherit());
+ binary.args(&["--ignore-ids", "get", "test"]);
+ crate::imag::stderr_of_command(&mut binary)
+ };
+
+ assert.failure();
+ assert!(stderr_output.iter().any(|substr| substr.contains("Category name missing")));
+}
+
+#[test]
+fn test_after_setting_a_new_category_there_is_a_category() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+
+ let _ = call(&imag_home, &["create-category", "cat"]);
+ let _ = call(&imag_home, &["set", "cat", "test"]);
+ let output = call(&imag_home, &["get", "test"]);
+ debug!("output = {:?}", output);
+ assert!(!output.is_empty());
+ assert_eq!(output.len(), 1);
+ assert_eq!(output[0], "cat");
+}
+
diff --git a/tests/ui/src/imag_contact.rs b/tests/ui/src/imag_contact.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_contact.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_create.rs b/tests/ui/src/imag_create.rs
new file mode 100644
index 00000000..993ba366
--- /dev/null
+++ b/tests/ui/src/imag_create.rs
@@ -0,0 +1,76 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+
+use assert_cmd::prelude::*;
+use assert_fs::fixture::TempDir;
+
+/// Helper to call imag-create
+pub fn call(tempdir: &TempDir, targets: &[&str]) {
+ let mut bin = binary(tempdir);
+
+ // ensure that stdin is not used by the child process
+ bin.stdin(std::process::Stdio::inherit());
+
+ for target in targets.iter() {
+ bin.arg(target);
+ }
+ debug!("Command = {:?}", bin);
+
+ bin.assert().success();
+}
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-create")
+}
+
+
+#[test]
+fn test_creating_works() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+
+ call(&imag_home, &["test"]);
+
+ let entry_path = crate::imag::store_path(&imag_home, &["test"]);
+
+ assert!(entry_path.exists(), "Entry was not created: {:?}", entry_path);
+ assert!(entry_path.is_file() , "Entry is not a file: {:?}", entry_path);
+
+ let contents = std::fs::read_to_string(entry_path).unwrap();
+ let mut lines = contents.lines();
+
+ assert_eq!(lines.next(), Some("---"));
+ assert_eq!(lines.next(), Some("[imag]"));
+ {
+ let version_line = lines.next().unwrap();
+ assert!(version_line.starts_with("version = '"));
+ assert!(version_line.ends_with("'"));
+ let version = version_line.replace("version = '", "").replace("'", "");
+ let semver = semver::Version::parse(&version);
+ assert!(semver.is_ok());
+ assert!(!semver.unwrap().is_prerelease()); // we only want full versions in the header
+
+ }
+ assert_eq!(lines.next(), Some("---"));
+ assert_eq!(lines.next(), None);
+}
+
diff --git a/tests/ui/src/imag_diagnostics.rs b/tests/ui/src/imag_diagnostics.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_diagnostics.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_diary.rs b/tests/ui/src/imag_diary.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_diary.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_edit.rs b/tests/ui/src/imag_edit.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_edit.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_git.rs b/tests/ui/src/imag_git.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_git.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_gps.rs b/tests/ui/src/imag_gps.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_gps.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_grep.rs b/tests/ui/src/imag_grep.rs
new file mode 100644
index 00000000..9eac75a7
--- /dev/null
+++ b/tests/ui/src/imag_grep.rs
@@ -0,0 +1,119 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+use std::io::Write;
+
+use assert_fs::fixture::TempDir;
+
+pub fn call(tempdir: &TempDir, pattern: &str) -> Vec<String> {
+ let mut binary = binary(tempdir);
+ binary.arg("--ignore-ids");
+ binary.arg(pattern);
+
+ // ensure that stdin is not used by the child process
+ binary.stdin(std::process::Stdio::inherit());
+ crate::imag::stdout_of_command(binary)
+}
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-grep")
+}
+
+#[test]
+fn test_grepping_in_empty_store() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+
+ let output = call(&imag_home, "something");
+ assert_eq!(output[0], "Processed 0 files, 0 matches, 0 nonmatches");
+ assert_eq!(output.len(), 1);
+}
+
+#[test]
+fn test_grepping_nonempty_store() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["something"]);
+
+ let output = call(&imag_home, "something");
+ assert_eq!(output[0], "Processed 1 files, 0 matches, 1 nonmatches");
+ assert_eq!(output.len(), 1);
+}
+
+#[test]
+fn test_grepping_not_available_string() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+
+ let filename = &["something"];
+ crate::imag_create::call(&imag_home, filename);
+ let filepath = crate::imag::store_path(&imag_home, filename);
+
+ {
+ debug!("Appending to file = {}", filepath.display());
+ let mut file = ::std::fs::OpenOptions::new()
+ .append(true)
+ .create(false)
+ .open(&filepath)
+ .unwrap();
+
+ let _ = writeln!(file, "unavailable").unwrap();
+ }
+
+ let output = call(&imag_home, "something");
+ assert_eq!(output[0], "Processed 1 files, 0 matches, 1 nonmatches");
+ assert_eq!(output.len(), 1);
+}
+
+#[test]
+fn test_grepping_available_string() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+
+ let filename = &["something"];
+ crate::imag_create::call(&imag_home, filename);
+ let filepath = crate::imag::store_path(&imag_home, filename);
+
+ let filetext = "some text is here";
+ {
+ debug!("Appending to file = {}", filepath.display());
+ let mut file = ::std::fs::OpenOptions::new()
+ .append(true)
+ .create(false)
+ .open(&filepath)
+ .unwrap();
+
+ let _ = writeln!(file, "{}", filetext).unwrap();
+ }
+
+ let output = call(&imag_home, filetext);
+ debug!("output = {:?}", output);
+ assert!(!output.is_empty());
+ assert_eq!(output[0], format!("{}:", filename[0]));
+ assert_eq!(output[1], format!(" '{}'", filetext));
+ assert_eq!(output[2], "");
+ assert_eq!(output[3], "Processed 1 files, 1 matches, 0 nonmatches");
+ assert_eq!(output.len(), 4);
+}
+
diff --git a/tests/ui/src/imag_habit.rs b/tests/ui/src/imag_habit.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_habit.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_header.rs b/tests/ui/src/imag_header.rs
new file mode 100644
index 00000000..ebcc248d
--- /dev/null
+++ b/tests/ui/src/imag_header.rs
@@ -0,0 +1,76 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+use std::str::FromStr;
+
+use assert_cmd::prelude::*;
+use assert_fs::fixture::TempDir;
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-header")
+}
+
+pub fn call(tmpdir: &TempDir, args: &[&str]) -> Vec<String> {
+ let mut binary = binary(tmpdir);
+ binary.stdin(std::process::Stdio::inherit());
+ binary.args(args);
+ debug!("Command = {:?}", binary);
+ crate::imag::stdout_of_command(binary)
+}
+
+#[test]
+fn test_no_header_besides_version_after_creation() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+
+ let mut bin = binary(&imag_home);
+ bin.arg("test");
+ bin.arg("string");
+ bin.arg("imag.version");
+ bin.assert().success();
+}
+
+#[test]
+fn test_imag_version_as_semver_string() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+
+ let output = call(&imag_home, &["--ignore-ids", "test", "read", "imag.version"]);
+ let version = version::version!();
+ debug!("output = {:?}", output);
+ assert_eq!(output.len(), 1);
+ assert_eq!(output[0], version);
+
+ let version = semver::Version::from_str(&version).unwrap();
+ let parsed = semver::Version::from_str(&output[0]);
+
+ assert!(parsed.is_ok());
+ let parsed = parsed.unwrap();
+
+ assert_eq!(parsed.major, version.major);
+ assert_eq!(parsed.minor, version.minor);
+ assert_eq!(parsed.patch, version.patch);
+ assert_eq!(parsed.pre, version.pre);
+}
+
diff --git a/tests/ui/src/imag_id_in_collection.rs b/tests/ui/src/imag_id_in_collection.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_id_in_collection.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_ids.rs b/tests/ui/src/imag_ids.rs
new file mode 100644
index 00000000..f6351eb6
--- /dev/null
+++ b/tests/ui/src/imag_ids.rs
@@ -0,0 +1,62 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+
+use assert_cmd::prelude::*;
+use assert_fs::fixture::TempDir;
+use predicates::prelude::*;
+
+/// Helper to call imag-init
+pub fn call(tempdir: &TempDir) -> Vec<String> {
+ let mut binary = binary(tempdir);
+
+ // ensure that stdin is not used by the child process
+ binary.stdin(std::process::Stdio::inherit());
+ crate::imag::stdout_of_command(binary)
+}
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-ids")
+}
+
+
+#[test]
+fn test_no_ids_after_init() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+
+ binary(&imag_home)
+ .assert()
+ .success()
+ .stdout(predicate::eq(b"" as &[u8]));
+}
+
+#[test]
+fn test_one_id_after_creating_one_entry() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+ let ids = call(&imag_home);
+
+ assert_eq!(ids.len(), 1);
+ assert_eq!(ids[0], "test");
+}
diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs
new file mode 100644
index 00000000..736546b7
--- /dev/null
+++ b/tests/ui/src/imag_init.rs
@@ -0,0 +1,110 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+
+use assert_cmd::prelude::*;
+use assert_fs::fixture::TempDir;
+
+/// Helper to call imag-init
+pub fn call(tempdir: &TempDir) {
+ binary(tempdir).assert().success();
+}
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ let path = tempdir.path()
+ .to_str()
+ .map(String::from)
+ .unwrap_or_else(|| panic!("Cannot create imag home path string"));
+
+ let mut cmd = Command::cargo_bin("imag-init").unwrap();
+ cmd.arg("--path");
+ cmd.arg(path);
+ cmd
+}
+
+
+#[test]
+fn test_init_makes_imag_dir() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ call(&imag_home);
+ assert!(imag_home.path().exists(), "imag dir does not exist");
+}
+
+#[test]
+fn test_init_creates_default_config() {
+ use pretty_assertions::assert_eq;
+
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ call(&imag_home);
+
+ const CONFIGURATION_STR : &str = include_str!("../../../imagrc.toml");
+ let config = std::fs::read_to_string({
+ let mut path = imag_home.path().to_path_buf();
+ path.push("imagrc.toml");
+ path
+ })
+ .unwrap();
+
+ // the imagrc is based on the example imagrc from this repository, but the one
+ // thing that differs is that the default level for logging output is "info" rather than
+ // "default"
+ CONFIGURATION_STR
+ .to_string()
+ .replace(
+ r#"level = "debug""#,
+ r#"level = "info""#
+ )
+ .lines()
+ .zip(config.lines())
+ .for_each(|(orig, created)| {
+ assert_eq!(orig, created);
+ });
+}
+
+#[test]
+fn test_init_creates_store_directory() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ call(&imag_home);
+ let store_path = {
+ let mut path = imag_home.path().to_path_buf();
+ path.push("store");
+ path
+ };
+
+ assert!(store_path.exists(), "imag store path does not exist");
+}
+
+#[test]
+fn test_init_creates_empty_store_directory() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ call(&imag_home);
+ let store_path = {
+ let mut path = imag_home.path().to_path_buf();
+ path.push("store");
+ path
+ };
+
+ assert_eq!(0, std::fs::read_dir(store_path).unwrap().count(), "imag store directory is not empty after creation");
+}
+
diff --git a/tests/ui/src/imag_link.rs b/tests/ui/src/imag_link.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_link.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_log.rs b/tests/ui/src/imag_log.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_log.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_mail.rs b/tests/ui/src/imag_mail.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_mail.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_markdown.rs b/tests/ui/src/imag_markdown.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_markdown.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_mv.rs b/tests/ui/src/imag_mv.rs
new file mode 100644
index 00000000..91dd78b0
--- /dev/null
+++ b/tests/ui/src/imag_mv.rs
@@ -0,0 +1,60 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+
+use assert_fs::fixture::TempDir;
+use assert_cmd::prelude::*;
+
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-mv")
+}
+
+pub fn call(tmpdir: &TempDir, src: &str, dst: &str) {
+ let mut binary = binary(tmpdir);
+ binary.stdin(std::process::Stdio::inherit());
+ binary.arg("--ignore-ids");
+ binary.arg(src);
+ binary.arg(dst);
+
+ debug!("Command = {:?}", binary);
+
+ binary.assert().success();
+}
+
+#[test]
+fn test_after_moving_entry_is_moved() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+
+ call(&imag_home, "test", "moved");
+ {
+ let entry_path = crate::imag::store_path(&imag_home, &["moved"]);
+ assert!(entry_path.exists(), "Entry was not created: {:?}", entry_path);
+ assert!(entry_path.is_file() , "Entry is not a file: {:?}", entry_path);
+ }
+ {
+ let entry_path = crate::imag::store_path(&imag_home, &["test"]);
+ assert!(!entry_path.exists(), "Entry still exists: {:?}", entry_path);
+ }
+}
+
diff --git a/tests/ui/src/imag_notes.rs b/tests/ui/src/imag_notes.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_notes.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_ref.rs b/tests/ui/src/imag_ref.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_ref.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_store.rs b/tests/ui/src/imag_store.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_store.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_tag.rs b/tests/ui/src/imag_tag.rs
new file mode 100644
index 00000000..352dcf25
--- /dev/null
+++ b/tests/ui/src/imag_tag.rs
@@ -0,0 +1,96 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::process::Command;
+
+use assert_fs::fixture::TempDir;
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-tag")
+}
+
+pub fn call(tmpdir: &TempDir, args: &[&str]) -> Vec<String> {
+ let mut binary = binary(tmpdir);
+ binary.stdin(std::process::Stdio::inherit());
+ binary.arg("--ignore-ids");
+ binary.args(args);
+ debug!("Command = {:?}", binary);
+ crate::imag::stdout_of_command(binary)
+}
+
+#[test]
+fn test_new_entry_has_no_tags() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+
+ let output = call(&imag_home, &["test", "list", "--linewise"]);
+ debug!("output = {:?}", output);
+ assert!(output.is_empty());
+}
+
+#[test]
+fn test_after_adding_tag_there_is_tag() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+ let _ = call(&imag_home, &["test", "add", "tag"]);
+
+ let output = call(&imag_home, &["test", "list", "--linewise"]);
+ debug!("output = {:?}", output);
+
+ assert!(!output.is_empty());
+ assert_eq!(output.len(), 1);
+ assert_eq!(output[0], "tag");
+}
+
+#[test]
+fn test_after_adding_and_removing_there_is_no_tag() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+ let _ = call(&imag_home, &["test", "add", "tag"]);
+ let _ = call(&imag_home, &["test", "remove", "tag"]);
+
+ let output = call(&imag_home, &["test", "list", "--linewise"]);
+ debug!("output = {:?}", output);
+
+ assert!(output.is_empty());
+}
+
+#[test]
+fn test_adding_twice_does_not_add_twice() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+ crate::imag_create::call(&imag_home, &["test"]);
+ let _ = call(&imag_home, &["test", "add", "tag"]);
+ let _ = call(&imag_home, &["test", "add", "tag"]);
+
+ let output = call(&imag_home, &["test", "list", "--linewise"]);
+ debug!("output = {:?}", output);
+
+ assert!(!output.is_empty());
+ assert_eq!(output.len(), 1);
+ assert_eq!(output[0], "tag");
+}
+
diff --git a/tests/ui/src/imag_timetrack.rs b/tests/ui/src/imag_timetrack.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_timetrack.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_todo.rs b/tests/ui/src/imag_todo.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_todo.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_view.rs b/tests/ui/src/imag_view.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_view.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/imag_wiki.rs b/tests/ui/src/imag_wiki.rs
new file mode 100644
index 00000000..987eadc5
--- /dev/null
+++ b/tests/ui/src/imag_wiki.rs
@@ -0,0 +1,19 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
diff --git a/tests/ui/src/lib.rs b/tests/ui/src/lib.rs
new file mode 100644
index 00000000..56009df6
--- /dev/null
+++ b/tests/ui/src/lib.rs
@@ -0,0 +1,65 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 the imag contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+extern crate assert_cmd;
+extern crate assert_fs;
+extern crate env_logger;
+extern crate predicates;
+extern crate semver;
+#[macro_use] extern crate log;
+#[macro_use] extern crate pretty_assertions;
+
+#[cfg(test)] mod imag;
+#[cfg(test)] mod imag_annotate;
+#[cfg(test)] mod imag_category;
+#[cfg(test)] mod imag_create;
+#[cfg(test)] mod imag_diagnostics;
+#[cfg(test)] mod imag_edit;
+#[cfg(test)] mod imag_git;
+#[cfg(test)] mod imag_gps;
+#[cfg(test)] mod imag_grep;
+#[cfg(test)] mod imag_header;
+#[cfg(test)] mod imag_id_in_collection;
+#[cfg(test)] mod imag_ids;
+#[cfg(test)] mod imag_init;
+#[cfg(test)] mod imag_link;
+#[cfg(test)] mod imag_markdown;
+#[cfg(test)] mod imag_mv;
+#[cfg(test)] mod imag_ref;
+#[cfg(test)] mod imag_store;
+#[cfg(test)] mod imag_tag;
+#[cfg(test)] mod imag_view;
+#[cfg(test)] mod imag_bookmark;
+#[cfg(test)] mod imag_calendar;
+#[cfg(test)] mod imag_contact;
+#[cfg(test)] mod imag_diary;
+#[cfg(test)] mod imag_habit;
+#[cfg(test)] mod imag_log;
+#[cfg(test)] mod imag_mail;
+#[cfg(test)] mod imag_notes;
+#[cfg(test)] mod imag_timetrack;
+#[cfg(test)] mod imag_todo;
+#[cfg(test)] mod imag_wiki;
+
+static LOG_SYNC: std::sync::Once = std::sync::Once::new();
+
+pub fn setup_logging() {
+ LOG_SYNC.call_once(|| { let _ = env_logger::try_init(); });
+}
+