From f3e237de4a12b577d82f07d1872063f55c1644ea Mon Sep 17 00:00:00 2001 From: Denis Isidoro Date: Wed, 12 Jan 2022 08:50:07 -0300 Subject: [PATCH] Fix tldr test (#669) --- tests/core.bash | 15 ++++++++++++++- tests/run | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/core.bash b/tests/core.bash index ae23424..8dc8bbd 100644 --- a/tests/core.bash +++ b/tests/core.bash @@ -46,7 +46,7 @@ test::_escape() { test::equals() { local -r actual="$(cat)" - local -r expected="$(echo "${1:-}")" + local -r expected="${1:-}" local -r actual2="$(echo "$actual" | test::_escape)" local -r expected2="$(echo "$expected" | test::_escape)" @@ -57,6 +57,19 @@ test::equals() { fi } +test::contains() { + local -r haystack="$(cat)" + local -r needle="${1:-}" + + local -r haystack2="$(echo "$haystack" | test::_escape)" + local -r needle2="$(echo "$needle" | test::_escape)" + + if [[ "$haystack2" != *"$needle2"* ]]; then + log::error "Expected '${haystack}' to include '${needle2}'" + return 2 + fi +} + test::finish() { echo if [ $SKIPPED -gt 0 ]; then diff --git a/tests/run b/tests/run index 08e9094..daf6bce 100755 --- a/tests/run +++ b/tests/run @@ -53,12 +53,12 @@ _get_tests() { _navi_tldr() { _navi --tldr docker --query ps --print --best-match \ - | test::equals "docker ps" + | test::contains "docker ps" } _navi_cheatsh() { _navi --cheatsh docker --query remove --print --best-match \ - | test::equals "docker rm container_name" + | test::contains "docker rm" } _navi_widget() {