diff options
35 files changed, 1275 insertions, 0 deletions
@@ -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.p |