From 380a81299fabac337dec25d8ac8c9eb42679c306 Mon Sep 17 00:00:00 2001 From: ArenM Date: Sat, 11 Jun 2022 20:31:08 -0400 Subject: [PATCH] Add basic tests for the appmenu My main motivation for writing this was as a regression test for my recent patch "appmenu: require exact match with picked" https://lists.sr.ht/~mil/sxmo-devel/patches/32362 Signed-off-by: Anjandev Momi --- scripts/core/sxmo_appmenu.sh | 5 ++- spec/scripts/core/sxmo_appmenu_spec.sh | 60 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 spec/scripts/core/sxmo_appmenu_spec.sh diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index fc1ad4e..ad6bdfd 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -144,4 +144,7 @@ mainloop() { fi } -mainloop "$@" +# Allow loading from shellspec +if [ -z "$SHELLSPEC_PATH" ]; then + mainloop "$@" +fi diff --git a/spec/scripts/core/sxmo_appmenu_spec.sh b/spec/scripts/core/sxmo_appmenu_spec.sh new file mode 100644 index 0000000..d02f3c2 --- /dev/null +++ b/spec/scripts/core/sxmo_appmenu_spec.sh @@ -0,0 +1,60 @@ +# shellcheck disable=SC2155 +# SPDX-License-Identifier: AGPL-3.0-only +# Copyright 2022 Sxmo Contributors + +# Don't check for unused variables +# shellcheck disable=SC2034 + +Describe 'sxmo_appmenu.sh' + Include scripts/core/sxmo_appmenu.sh + + # if the script successfully exits, it confuses shellspec + quit() { + true + } + + getprogchoices() { + true + } + + It 'can mock functions' + CHOICES="foo ^ 0 ^ echo bar" + Mock sxmo_dmenu.sh + echo 'foo ' + End + + When call mainloop + + The output should equal 'bar' + The stderr should match pattern '*' # ignore stderr + The status should be success + End + + It 'ignores invalid selections' + CHOICES="foo ^ 0 ^ echo bar" + Mock sxmo_dmenu.sh + echo 'baz ' + End + + When call mainloop + + The output should equal '' + The stderr should match pattern '*' # ignore stderr + The status should be success + End + + It 'handles substring menu items' + CHOICES="foobar ^ 0 ^ echo foobar +bar ^ 0 ^ echo bar2" + + Mock sxmo_dmenu.sh + echo 'bar ' + End + + When call mainloop + + The output should equal 'bar2' + The stderr should match pattern '*' # ignore stderr + The status should be success + End +End