Merge branch 'ui-testing' into master

This commit is contained in:
Matthias Beyer 2019-11-03 11:57:15 +01:00
commit 7b6e5eafba
35 changed files with 1275 additions and 0 deletions

View file

@ -61,4 +61,6 @@ members = [
"lib/etc/libimaginteraction",
"lib/etc/libimagtimeui",
"lib/etc/libimagutil",
"tests/ui",
]

22
tests/ui/Cargo.toml Normal file
View file

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

13
tests/ui/README.md Normal file
View file

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

86
tests/ui/src/imag.rs Normal file
View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

19
tests/ui/src/imag_edit.rs Normal file
View file

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

19
tests/ui/src/imag_git.rs Normal file
View file

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

19
tests/ui/src/imag_gps.rs Normal file
View file

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

119
tests/ui/src/imag_grep.rs Normal file
View file

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

View file

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

View file

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

View file

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

62
tests/ui/src/imag_ids.rs Normal file
View file

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

110
tests/ui/src/imag_init.rs Normal file
View file

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

19
tests/ui/src/imag_link.rs Normal file
View file

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

19
tests/ui/src/imag_log.rs Normal file
View file

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

19
tests/ui/src/imag_mail.rs Normal file
View file

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

View file

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

60
tests/ui/src/imag_mv.rs Normal file
View file

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

View file

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

19
tests/ui/src/imag_ref.rs Normal file
View file

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

View file

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

96
tests/ui/src/imag_tag.rs Normal file
View file

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

View file

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

19
tests/ui/src/imag_todo.rs Normal file
View file

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

19
tests/ui/src/imag_view.rs Normal file
View file

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

19
tests/ui/src/imag_wiki.rs Normal file
View file

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

65
tests/ui/src/lib.rs Normal file
View file

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