Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve speed test output and test other cases #16

Merged
merged 1 commit into from May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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