From d78ab6795616cb131a3467141d7635f70f4face9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 15:42:19 +0200 Subject: [PATCH 01/21] Add crate for ui-tests Signed-off-by: Matthias Beyer --- Cargo.toml | 2 + tests/ui/Cargo.toml | 18 ++++++++ tests/ui/README.md | 13 ++++++ tests/ui/src/imag.rs | 19 ++++++++ tests/ui/src/imag_annotate.rs | 19 ++++++++ tests/ui/src/imag_bookmark.rs | 19 ++++++++ tests/ui/src/imag_calendar.rs | 19 ++++++++ tests/ui/src/imag_category.rs | 19 ++++++++ tests/ui/src/imag_contact.rs | 19 ++++++++ tests/ui/src/imag_create.rs | 19 ++++++++ tests/ui/src/imag_diagnostics.rs | 19 ++++++++ tests/ui/src/imag_diary.rs | 19 ++++++++ tests/ui/src/imag_edit.rs | 19 ++++++++ tests/ui/src/imag_git.rs | 19 ++++++++ tests/ui/src/imag_gps.rs | 19 ++++++++ tests/ui/src/imag_grep.rs | 19 ++++++++ tests/ui/src/imag_habit.rs | 19 ++++++++ tests/ui/src/imag_header.rs | 19 ++++++++ tests/ui/src/imag_id_in_collection.rs | 19 ++++++++ tests/ui/src/imag_ids.rs | 19 ++++++++ tests/ui/src/imag_init.rs | 19 ++++++++ tests/ui/src/imag_link.rs | 19 ++++++++ tests/ui/src/imag_log.rs | 19 ++++++++ tests/ui/src/imag_mail.rs | 19 ++++++++ tests/ui/src/imag_markdown.rs | 19 ++++++++ tests/ui/src/imag_mv.rs | 19 ++++++++ tests/ui/src/imag_notes.rs | 19 ++++++++ tests/ui/src/imag_ref.rs | 19 ++++++++ tests/ui/src/imag_store.rs | 19 ++++++++ tests/ui/src/imag_tag.rs | 19 ++++++++ tests/ui/src/imag_timetrack.rs | 19 ++++++++ tests/ui/src/imag_todo.rs | 19 ++++++++ tests/ui/src/imag_view.rs | 19 ++++++++ tests/ui/src/imag_wiki.rs | 19 ++++++++ tests/ui/src/lib.rs | 63 +++++++++++++++++++++++++++ 35 files changed, 685 insertions(+) create mode 100644 tests/ui/Cargo.toml create mode 100644 tests/ui/README.md create mode 100644 tests/ui/src/imag.rs create mode 100644 tests/ui/src/imag_annotate.rs create mode 100644 tests/ui/src/imag_bookmark.rs create mode 100644 tests/ui/src/imag_calendar.rs create mode 100644 tests/ui/src/imag_category.rs create mode 100644 tests/ui/src/imag_contact.rs create mode 100644 tests/ui/src/imag_create.rs create mode 100644 tests/ui/src/imag_diagnostics.rs create mode 100644 tests/ui/src/imag_diary.rs create mode 100644 tests/ui/src/imag_edit.rs create mode 100644 tests/ui/src/imag_git.rs create mode 100644 tests/ui/src/imag_gps.rs create mode 100644 tests/ui/src/imag_grep.rs create mode 100644 tests/ui/src/imag_habit.rs create mode 100644 tests/ui/src/imag_header.rs create mode 100644 tests/ui/src/imag_id_in_collection.rs create mode 100644 tests/ui/src/imag_ids.rs create mode 100644 tests/ui/src/imag_init.rs create mode 100644 tests/ui/src/imag_link.rs create mode 100644 tests/ui/src/imag_log.rs create mode 100644 tests/ui/src/imag_mail.rs create mode 100644 tests/ui/src/imag_markdown.rs create mode 100644 tests/ui/src/imag_mv.rs create mode 100644 tests/ui/src/imag_notes.rs create mode 100644 tests/ui/src/imag_ref.rs create mode 100644 tests/ui/src/imag_store.rs create mode 100644 tests/ui/src/imag_tag.rs create mode 100644 tests/ui/src/imag_timetrack.rs create mode 100644 tests/ui/src/imag_todo.rs create mode 100644 tests/ui/src/imag_view.rs create mode 100644 tests/ui/src/imag_wiki.rs create mode 100644 tests/ui/src/lib.rs 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..d5595ca0 --- /dev/null +++ b/tests/ui/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "tests-ui" +version = "0.10.0" +authors = ["Matthias Beyer "] +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" 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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 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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_category.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_create.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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 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 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 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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_grep.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_header.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_ids.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_init.rs b/tests/ui/src/imag_init.rs new file mode 100644 index 00000000..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_init.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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 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 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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_mv.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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 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 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..987eadc5 --- /dev/null +++ b/tests/ui/src/imag_tag.rs @@ -0,0 +1,19 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2019 Matthias Beyer 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_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 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 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 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 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..3fffb1f8 --- /dev/null +++ b/tests/ui/src/lib.rs @@ -0,0 +1,63 @@ +// +// 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; +#[macro_use] extern crate log; + +#[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(); }); +} + From 49af82cc68580568c0301dc14695988dd39c738e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 16:07:17 +0200 Subject: [PATCH 02/21] Add imag-init test * Extract function to call imag-init for a tempdir path * Simplify setup helper functions Signed-off-by: Matthias Beyer --- tests/ui/src/imag.rs | 21 +++++++++++++++++++++ tests/ui/src/imag_init.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index 987eadc5..a10a19ba 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -17,3 +17,24 @@ // 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 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 +} + diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs index 987eadc5..2c9cda31 100644 --- a/tests/ui/src/imag_init.rs +++ b/tests/ui/src/imag_init.rs @@ -17,3 +17,34 @@ // 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"); +} + From 409660b07ba75e6773441a630f9c26eba9dea1da Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 16:34:21 +0200 Subject: [PATCH 03/21] Add test: check whether default configuration is added when imag-init is called Signed-off-by: Matthias Beyer --- tests/ui/Cargo.toml | 13 +++++++------ tests/ui/src/imag_init.rs | 31 +++++++++++++++++++++++++++++++ tests/ui/src/lib.rs | 1 + 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml index d5595ca0..44f2d8d7 100644 --- a/tests/ui/Cargo.toml +++ b/tests/ui/Cargo.toml @@ -10,9 +10,10 @@ edition = "2018" publish = false [dependencies] -assert_cmd = "0.11" -assert_fs = "0.11" -duct = "0.13" -env_logger = "0.7" -log = "0.4" -predicates = "1" +assert_cmd = "0.11" +assert_fs = "0.11" +duct = "0.13" +env_logger = "0.7" +log = "0.4" +predicates = "1" +pretty_assertions = "0.6" diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs index 2c9cda31..0c3c6cab 100644 --- a/tests/ui/src/imag_init.rs +++ b/tests/ui/src/imag_init.rs @@ -48,3 +48,34 @@ fn test_init_makes_imag_dir() { 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); + }); +} diff --git a/tests/ui/src/lib.rs b/tests/ui/src/lib.rs index 3fffb1f8..827f8505 100644 --- a/tests/ui/src/lib.rs +++ b/tests/ui/src/lib.rs @@ -22,6 +22,7 @@ extern crate assert_fs; extern crate env_logger; extern crate predicates; #[macro_use] extern crate log; +#[macro_use] extern crate pretty_assertions; #[cfg(test)] mod imag; #[cfg(test)] mod imag_annotate; From 966eb6d045f92370131e0c338fa6d6b89b66ad0f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 16:46:52 +0200 Subject: [PATCH 04/21] Add test: check whether imag-init creates store path Signed-off-by: Matthias Beyer --- tests/ui/src/imag_init.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs index 0c3c6cab..2ef6aec3 100644 --- a/tests/ui/src/imag_init.rs +++ b/tests/ui/src/imag_init.rs @@ -79,3 +79,18 @@ fn test_init_creates_default_config() { 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"); +} + From eb6029537abf2c15d9e8be058168e0aab98458a9 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 17:01:07 +0200 Subject: [PATCH 05/21] Add test: check with imag-ids whether no entries exist after init Signed-off-by: Matthias Beyer --- tests/ui/src/imag_ids.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/ui/src/imag_ids.rs b/tests/ui/src/imag_ids.rs index 987eadc5..cc6ead25 100644 --- a/tests/ui/src/imag_ids.rs +++ b/tests/ui/src/imag_ids.rs @@ -17,3 +17,43 @@ // 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 { + let mut binary = binary(tempdir); + + // ensure that stdin is not used by the child process + binary.stdin(std::process::Stdio::inherit()); + + let assert = binary.assert(); + let lines = String::from_utf8(assert.get_output().stdout.clone()) + .unwrap() + .lines() + .map(String::from) + .collect(); + assert.success(); + lines +} + +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])); +} + From 4c67450b0c05eec5ce091b11575ad9b422848306 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 12 Oct 2019 17:03:03 +0200 Subject: [PATCH 06/21] Add test: store is empty after creation Signed-off-by: Matthias Beyer --- tests/ui/src/imag_init.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/ui/src/imag_init.rs b/tests/ui/src/imag_init.rs index 2ef6aec3..736546b7 100644 --- a/tests/ui/src/imag_init.rs +++ b/tests/ui/src/imag_init.rs @@ -94,3 +94,17 @@ fn test_init_creates_store_directory() { 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"); +} + From ceabde799b07cb2bd375519e91819b3d762f88eb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 13 Oct 2019 10:04:29 +0200 Subject: [PATCH 07/21] Add test: check whether imag-create works as expected Signed-off-by: Matthias Beyer --- tests/ui/Cargo.toml | 1 + tests/ui/src/imag_create.rs | 64 +++++++++++++++++++++++++++++++++++++ tests/ui/src/lib.rs | 1 + 3 files changed, 66 insertions(+) diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml index 44f2d8d7..1fef31ac 100644 --- a/tests/ui/Cargo.toml +++ b/tests/ui/Cargo.toml @@ -17,3 +17,4 @@ env_logger = "0.7" log = "0.4" predicates = "1" pretty_assertions = "0.6" +semver = "0.9" diff --git a/tests/ui/src/imag_create.rs b/tests/ui/src/imag_create.rs index 987eadc5..4e6719f3 100644 --- a/tests/ui/src/imag_create.rs +++ b/tests/ui/src/imag_create.rs @@ -17,3 +17,67 @@ // 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 = { + let mut path = imag_home.path().to_path_buf(); + path.push("store"); + path.push("test"); + path + }; + + debug!("Calculated path = {:?}", entry_path); + + 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/lib.rs b/tests/ui/src/lib.rs index 827f8505..56009df6 100644 --- a/tests/ui/src/lib.rs +++ b/tests/ui/src/lib.rs @@ -21,6 +21,7 @@ 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; From 61a1a241c82c79baa8b2a6dbb03fb70b49cca5ea Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 13 Oct 2019 10:11:59 +0200 Subject: [PATCH 08/21] Add test: imag-ids reports id after it was created Signed-off-by: Matthias Beyer --- tests/ui/src/imag_ids.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/ui/src/imag_ids.rs b/tests/ui/src/imag_ids.rs index cc6ead25..2c38906e 100644 --- a/tests/ui/src/imag_ids.rs +++ b/tests/ui/src/imag_ids.rs @@ -57,3 +57,14 @@ fn test_no_ids_after_init() { .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"); +} From 4b3e2ea4cde252f3cfeef979628f166ab0cbdd22 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 13 Oct 2019 12:52:41 +0200 Subject: [PATCH 09/21] Add test: Test whether imag-header reports header at imag.version after entry creation Signed-off-by: Matthias Beyer --- tests/ui/src/imag_header.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/ui/src/imag_header.rs b/tests/ui/src/imag_header.rs index 987eadc5..5119689e 100644 --- a/tests/ui/src/imag_header.rs +++ b/tests/ui/src/imag_header.rs @@ -17,3 +17,26 @@ // 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; + +pub fn binary(tempdir: &TempDir) -> Command { + crate::imag::binary(tempdir, "imag-header") +} + +#[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(); +} + From 4cbcdc118c36aaa32c358740627439a45d2ea200 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 13 Oct 2019 13:00:07 +0200 Subject: [PATCH 10/21] Add test: Check whether imag-header prints correct string when querying imag.version header Signed-off-by: Matthias Beyer --- tests/ui/Cargo.toml | 2 ++ tests/ui/src/imag_header.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml index 1fef31ac..3d601d03 100644 --- a/tests/ui/Cargo.toml +++ b/tests/ui/Cargo.toml @@ -18,3 +18,5 @@ log = "0.4" predicates = "1" pretty_assertions = "0.6" semver = "0.9" +version = "3" + diff --git a/tests/ui/src/imag_header.rs b/tests/ui/src/imag_header.rs index 5119689e..3f87b300 100644 --- a/tests/ui/src/imag_header.rs +++ b/tests/ui/src/imag_header.rs @@ -21,6 +21,7 @@ use std::process::Command; use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; +use predicates::prelude::*; pub fn binary(tempdir: &TempDir) -> Command { crate::imag::binary(tempdir, "imag-header") @@ -40,3 +41,23 @@ fn test_no_header_besides_version_after_creation() { 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 imag_version = version::version!(); + + let mut bin = binary(&imag_home); + bin.arg("test"); + bin.arg("string"); + bin.arg("imag.version"); + + let expected_output_str = format!("test - {}", imag_version); + bin.assert() + .stdout(predicate::eq(expected_output_str.as_bytes())) + .success(); +} + From fd2afad72a045e2fb1bfbd44062a5c30ee0631be Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 13 Oct 2019 13:07:07 +0200 Subject: [PATCH 11/21] Move path calculation to helper function Signed-off-by: Matthias Beyer --- tests/ui/src/imag.rs | 23 +++++++++++++++++++++++ tests/ui/src/imag_create.rs | 9 +-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index a10a19ba..094a0dfe 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -18,6 +18,7 @@ // use std::process::Command; +use std::path::PathBuf; use assert_fs::fixture::TempDir; use assert_cmd::prelude::*; @@ -38,3 +39,25 @@ pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command { 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(command: Command) -> Vec { + let assert = command.assert(); + let lines = String::from_utf8(assert.get_output().stdout.clone()) + .unwrap() + .lines() + .map(String::from) + .collect(); + assert.success(); + lines +} + +/// Create a PathBuf for a file in a TempDir +pub fn file_path(tempdir: &TempDir, path_elements: &[&str]) -> PathBuf { + let mut path = tempdir.path().to_path_buf(); + path_elements.iter().for_each(|el| path.push(el)); + debug!("Calculated path = {:?}", path); + path +} + diff --git a/tests/ui/src/imag_create.rs b/tests/ui/src/imag_create.rs index 4e6719f3..a857ed28 100644 --- a/tests/ui/src/imag_create.rs +++ b/tests/ui/src/imag_create.rs @@ -50,14 +50,7 @@ fn test_creating_works() { call(&imag_home, &["test"]); - let entry_path = { - let mut path = imag_home.path().to_path_buf(); - path.push("store"); - path.push("test"); - path - }; - - debug!("Calculated path = {:?}", entry_path); + let entry_path = crate::imag::file_path(&imag_home, &["store", "test"]); assert!(entry_path.exists(), "Entry was not created: {:?}", entry_path); assert!(entry_path.is_file() , "Entry is not a file: {:?}", entry_path); From a8b75ad2ba2ec04ac9ec0f317f87659e15cb4a78 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 12:25:13 +0200 Subject: [PATCH 12/21] Refactor out helper function to simply get stdout of a command Signed-off-by: Matthias Beyer --- tests/ui/src/imag.rs | 2 +- tests/ui/src/imag_ids.rs | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index 094a0dfe..3c517ce2 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -42,7 +42,7 @@ pub fn binary(tempdir: &TempDir, binary_name: &str) -> Command { /// Run the passed command and get the stdout of it. /// /// This function does _not_ ensure that stdin is inherited. -pub fn stdout_of_command(command: Command) -> Vec { +pub fn stdout_of_command(mut command: Command) -> Vec { let assert = command.assert(); let lines = String::from_utf8(assert.get_output().stdout.clone()) .unwrap() diff --git a/tests/ui/src/imag_ids.rs b/tests/ui/src/imag_ids.rs index 2c38906e..f6351eb6 100644 --- a/tests/ui/src/imag_ids.rs +++ b/tests/ui/src/imag_ids.rs @@ -29,15 +29,7 @@ pub fn call(tempdir: &TempDir) -> Vec { // ensure that stdin is not used by the child process binary.stdin(std::process::Stdio::inherit()); - - let assert = binary.assert(); - let lines = String::from_utf8(assert.get_output().stdout.clone()) - .unwrap() - .lines() - .map(String::from) - .collect(); - assert.success(); - lines + crate::imag::stdout_of_command(binary) } pub fn binary(tempdir: &TempDir) -> Command { From f1b5b0915b40beca9c34a38f7799fb795682fa0f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 13:11:44 +0200 Subject: [PATCH 13/21] Refactor file_path and provide helper function for store path Signed-off-by: Matthias Beyer --- tests/ui/src/imag.rs | 9 +++++++++ tests/ui/src/imag_create.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index 3c517ce2..34edbb4c 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -55,7 +55,16 @@ pub fn stdout_of_command(mut command: Command) -> Vec { /// 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_create.rs b/tests/ui/src/imag_create.rs index a857ed28..993ba366 100644 --- a/tests/ui/src/imag_create.rs +++ b/tests/ui/src/imag_create.rs @@ -50,7 +50,7 @@ fn test_creating_works() { call(&imag_home, &["test"]); - let entry_path = crate::imag::file_path(&imag_home, &["store", "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); From a837cff38228d1383b774cd27737af7b2ee29a70 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 13:12:08 +0200 Subject: [PATCH 14/21] Add tests for imag-grep Signed-off-by: Matthias Beyer Vec { + 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); +} + From cf4298b9daf180256900d3e5ae61a66b8d9466ff Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 14:47:25 +0200 Subject: [PATCH 15/21] Add call() helper Signed-off-by: Matthias Beyer --- tests/ui/src/imag_header.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/ui/src/imag_header.rs b/tests/ui/src/imag_header.rs index 3f87b300..28d95227 100644 --- a/tests/ui/src/imag_header.rs +++ b/tests/ui/src/imag_header.rs @@ -27,6 +27,14 @@ pub fn binary(tempdir: &TempDir) -> Command { crate::imag::binary(tempdir, "imag-header") } +pub fn call(tmpdir: &TempDir, args: &[&str]) -> Vec { + 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(); From 00d6e78c5d1342a33ddeca6feb0fd2d2d0a3cde7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 14:47:44 +0200 Subject: [PATCH 16/21] Rewrite imag header version output test Signed-off-by: Matthias Beyer --- tests/ui/src/imag_header.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/ui/src/imag_header.rs b/tests/ui/src/imag_header.rs index 28d95227..5f539afb 100644 --- a/tests/ui/src/imag_header.rs +++ b/tests/ui/src/imag_header.rs @@ -18,10 +18,10 @@ // use std::process::Command; +use std::str::FromStr; use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; -use predicates::prelude::*; pub fn binary(tempdir: &TempDir) -> Command { crate::imag::binary(tempdir, "imag-header") @@ -56,16 +56,25 @@ fn test_imag_version_as_semver_string() { crate::imag_init::call(&imag_home); crate::imag_create::call(&imag_home, &["test"]); - let imag_version = version::version!(); + let output = call(&imag_home, &["--ignore-ids", "test", "read", "imag.version"]); + let version = version::version!(); + let imag_version = format!("\"{}\"", version); + debug!("output = {:?}", output); + assert_eq!(output.len(), 1); + assert_eq!(output[0], imag_version); - let mut bin = binary(&imag_home); - bin.arg("test"); - bin.arg("string"); - bin.arg("imag.version"); + let version = semver::Version::from_str(&version).unwrap(); + let parsed = { + let output_version = output[0].replace("\"", ""); + semver::Version::from_str(&output_version) + }; - let expected_output_str = format!("test - {}", imag_version); - bin.assert() - .stdout(predicate::eq(expected_output_str.as_bytes())) - .success(); + 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); } From f7bc7d0834134bb60927e3cf0a4315227fb96dba Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 15:05:10 +0200 Subject: [PATCH 17/21] Adapt to quote-less output Signed-off-by: Matthias Beyer --- tests/ui/src/imag_header.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/ui/src/imag_header.rs b/tests/ui/src/imag_header.rs index 5f539afb..ebcc248d 100644 --- a/tests/ui/src/imag_header.rs +++ b/tests/ui/src/imag_header.rs @@ -58,16 +58,12 @@ fn test_imag_version_as_semver_string() { let output = call(&imag_home, &["--ignore-ids", "test", "read", "imag.version"]); let version = version::version!(); - let imag_version = format!("\"{}\"", version); debug!("output = {:?}", output); assert_eq!(output.len(), 1); - assert_eq!(output[0], imag_version); + assert_eq!(output[0], version); let version = semver::Version::from_str(&version).unwrap(); - let parsed = { - let output_version = output[0].replace("\"", ""); - semver::Version::from_str(&output_version) - }; + let parsed = semver::Version::from_str(&output[0]); assert!(parsed.is_ok()); let parsed = parsed.unwrap(); From 0c685fde738736ec8476c13e8f22ab1a55226206 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 18:41:15 +0200 Subject: [PATCH 18/21] Add imag-tag tests Signed-off-by: Matthias Beyer --- tests/ui/src/imag_tag.rs | 77 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/ui/src/imag_tag.rs b/tests/ui/src/imag_tag.rs index 987eadc5..352dcf25 100644 --- a/tests/ui/src/imag_tag.rs +++ b/tests/ui/src/imag_tag.rs @@ -17,3 +17,80 @@ // 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 { + 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"); +} + From 485ad3815f20184b59a1212d0379e998cbdc37c7 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 19:18:39 +0200 Subject: [PATCH 19/21] Add helper function to get stderr of a command But also get back the Assert object, which can then be used to check whether the command succeeded or failed. Signed-off-by: Matthias Beyer --- tests/ui/src/imag.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/ui/src/imag.rs b/tests/ui/src/imag.rs index 34edbb4c..fb413ab3 100644 --- a/tests/ui/src/imag.rs +++ b/tests/ui/src/imag.rs @@ -22,6 +22,7 @@ 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()) @@ -53,6 +54,19 @@ pub fn stdout_of_command(mut command: Command) -> Vec { 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) { + 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) From a8107ae6e07338fd829b89cf998ab3056559e6fe Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 19:19:16 +0200 Subject: [PATCH 20/21] Add tests for imag-category Signed-off-by: Matthias Beyer --- tests/ui/src/imag_category.rs | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/ui/src/imag_category.rs b/tests/ui/src/imag_category.rs index 987eadc5..cc2bfc42 100644 --- a/tests/ui/src/imag_category.rs +++ b/tests/ui/src/imag_category.rs @@ -17,3 +17,54 @@ // 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 { + 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"); +} + From d68797a1156c5ad228b6b4e30e89ef82d15b167a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 20 Oct 2019 19:49:28 +0200 Subject: [PATCH 21/21] Test imag-mv Signed-off-by: Matthias Beyer --- tests/ui/src/imag_mv.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/ui/src/imag_mv.rs b/tests/ui/src/imag_mv.rs index 987eadc5..91dd78b0 100644 --- a/tests/ui/src/imag_mv.rs +++ b/tests/ui/src/imag_mv.rs @@ -17,3 +17,44 @@ // 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); + } +} +