Skip to content

Commit

Permalink
Improve speed test output and test other cases (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
  • Loading branch information
marckhouzam committed May 4, 2022
1 parent 9b537b1 commit 44f69a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
5 changes: 3 additions & 2 deletions tests/bash/comp-test-lib.bash
Expand Up @@ -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
}
Expand Down
28 changes: 22 additions & 6 deletions tests/bash/comp-tests.bash
Expand Up @@ -187,20 +187,28 @@ 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)
# and insert-completions (COMP_TYPE == 42)
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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 44f69a8

Please sign in to comment.