aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2023-08-07 13:59:00 +0200
committerMatěj Cepl <mcepl@cepl.eu>2023-08-11 11:59:10 +0200
commitdd3d3357cdeb05d83210b0f51d9fe4bffbc3f387 (patch)
treed933860f155c1ee69971dc0595e06611d17d0a76
parent36aed204ea52b6dbde81031a15fcfb1926e9e37c (diff)
downloadpinentry-rofi-dd3d3357cdeb05d83210b0f51d9fe4bffbc3f387.tar.gz
test: first attempt to test.
General mechanism works, but the first tested function breaks.
-rwxr-xr-xpinentry-rofi.sh11
-rw-r--r--tests/foundational.bats43
2 files changed, 47 insertions, 7 deletions
diff --git a/pinentry-rofi.sh b/pinentry-rofi.sh
index 1bfae50..5a32d65 100755
--- a/pinentry-rofi.sh
+++ b/pinentry-rofi.sh
@@ -45,14 +45,19 @@ assuan_send() {
split_line() {
rmfirst=${2:-0}
+ log_debug "args: \"$1\", ${rmfirst}"
read -ra out_arr <<< "$1"
- if [ "$rmfirst" -ne 1 ] ; then
+ log_debug "out: $(declare -p out_arr)"
+ if [ $rmfirst -ne 1 ] ; then
unset "out_arr[0]"
fi
echo "${out_arr[@]}"
}
rofi_cmd="rofi -dmenu -input /dev/null -password"
+INSIDE_BATS=${INSIDE_BATS:-0}
+
+if [ $INSIDE_BATS -ne 1 ] ; then
assuan_send "OK Please go ahead"
@@ -62,6 +67,8 @@ win_mesg=""
keyinfo=""
+
+
while : ; do
read -r line
log_debug "line=$line"
@@ -178,3 +185,5 @@ while : ; do
exit 1
fi
done
+
+fi # End of $INSIDE_BATS exclusion
diff --git a/tests/foundational.bats b/tests/foundational.bats
index 5683371..11073e1 100644
--- a/tests/foundational.bats
+++ b/tests/foundational.bats
@@ -1,11 +1,42 @@
#!/usr/bin/env bats
-@test "addition using bc" {
- result="$(echo 2+2 | bc)"
- [ "$result" -eq 4 ]
+# setup() {
+# export INSIDE_BATS=1
+# DIR="$( cd "$(dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
+# source ${DIR}/../pinentry-rofi.sh
+# }
+
+log_debug() {
+ echo "$@" >> /dev/stderr
+}
+
+split_line() {
+ rmfirst=${2:-0}
+ log_debug "args: \"$1\", ${rmfirst}"
+ read -ra out_arr <<< "$1"
+ log_debug "out: $(declare -p out_arr)"
+ if [ $rmfirst -ne 1 ] ; then
+ unset "out_arr[0]"
+ fi
+ echo "${out_arr[@]}"
+}
+
+
+@test "split line" {
+ line_arr=("$(split_line "GETINFO version")")
+ [ "${line_arr[0]}" = "version" ]
+}
+
+@test "split line rmfirst" {
+ line_arr=("$(split_line "GETINFO version" 0)")
+ [ "${line_arr[0]}" = "version" ]
}
-@test "addition using dc" {
- result="$(echo 2 2+p | dc)"
- [ "$result" -eq 4 ]
+@test "split line no-rmfirst" {
+ IFS=" " line_arr=("$(split_line "GETINFO version" 1)")
+ [[ "$(declare -p line_arr)" == 'declare -'[aA]* ]]
+ log_debug "$(declare -p line_arr)"
+ [[ "${line_arr[0]}" == "GETINFO" ]]
+ [[ ${#line_arr} -eq 2 ]]
+ [[ "${line_arr[1]}" == "version" ]]
}