From 44f69a87c5d7de042a4dac6704be417ab4a1d795 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 4 May 2022 16:26:33 -0400 Subject: [PATCH] Improve speed test output and test other cases (#16) Signed-off-by: Marc Khouzam --- tests/bash/comp-test-lib.bash | 5 +++-- tests/bash/comp-tests.bash | 28 ++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/bash/comp-test-lib.bash b/tests/bash/comp-test-lib.bash index 5ffdb80..28b6174 100755 --- a/tests/bash/comp-test-lib.bash +++ b/tests/bash/comp-test-lib.bash @@ -137,15 +137,16 @@ _completionTests_sort() { # $1 - The completion to measure # $2 - The maximum time to consider it an error +# $3 - An output prefix _completionTests_timing() { TIMEFORMAT=%R timing=$({ time { _completionTests_complete "$1" > /dev/null; } } 2>&1) if (( $(echo "$timing > ${2}" | bc -l) )); then _completionTests_TEST_FAILED=1 - echo -e "${RED}Processing 1000 completions took ${timing} seconds which is more than the ${2-0.1} seconds limit$NC" + echo -e "${RED}<= TIMING => ${3}: 1000 completions took ${timing} seconds > ${2-0.1} seconds limit$NC" return 1 else - echo -e "${GREEN}Processing 1000 completions took ${timing} seconds which is less than the ${2-0.1} seconds limit$NC" + echo -e "${GREEN}<= TIMING => ${3}: 1000 completions took ${timing} seconds < ${2-0.1} seconds limit$NC" return 0 fi } diff --git a/tests/bash/comp-tests.bash b/tests/bash/comp-tests.bash index 679dc97..5cf2965 100755 --- a/tests/bash/comp-tests.bash +++ b/tests/bash/comp-tests.bash @@ -187,6 +187,9 @@ if [ $BASH_VERSINFO != 3 ]; then verifyRedirect fi +# Measure speed of execution without descriptions (for both v1 and v2) +_completionTests_timing "testprog manycomps " 0.2 "no descriptions" + # Test other bash completion types with descriptions disabled. # There should be no change in behaviour when there are no descriptions. # The types are: menu-complete/menu-complete-backward (COMP_TYPE == 37) @@ -194,13 +197,18 @@ fi COMP_TYPE=37 _completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace _completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile + +# Measure speed of execution with menu-complete without descriptions (for both v1 and v2) +_completionTests_timing "testprog manycomps " 0.2 "menu-complete no descs" + COMP_TYPE=42 _completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace _completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile -unset COMP_TYPE -# Measure speed of execution without descriptions (for both v1 and v2) -_completionTests_timing "testprog manycomps " 0.2 +# Measure speed of execution with insert-completions without descriptions (for both v1 and v2) +_completionTests_timing "testprog manycomps " 0.2 "insert-completions no descs" + +unset COMP_TYPE # Test descriptions of bash v2 if [ "$BASHCOMP_VERSION" = bash2 ]; then @@ -258,6 +266,9 @@ forthComp" nofile forthComp" nofile _completionTests_verifyCompletion "testprog --customComp fi" "firstComp" nofile + # Measure speed of execution with descriptions + _completionTests_timing "testprog manycomps " 0.5 "with descriptions" + # Test descriptions are properly removed when using other bash completion types # The types are: menu-complete/menu-complete-backward (COMP_TYPE == 37) # and insert-completions (COMP_TYPE == 42) @@ -266,15 +277,20 @@ forthComp" nofile bearpaw" nospace _completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile + + # Measure speed of execution with menu-complete with descriptions + _completionTests_timing "testprog manycomps " 0.2 "menu-complete with descs" + COMP_TYPE=42 _completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace _completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile - unset COMP_TYPE - # Measure speed of execution with descriptions - _completionTests_timing "testprog manycomps " 0.5 + # Measure speed of execution with insert-completions with descriptions + _completionTests_timing "testprog manycomps " 0.2 "insert-completions no descs" + + unset COMP_TYPE fi # This must be the last call. It allows to exit with an exit code