CI: Test bash completion

Originally generated by CursorAI, manually edited.

[skip changelog]
This commit is contained in:
Lukáš Zachar 2025-07-03 07:58:05 +02:00 committed by Miro Hrončok
commit 685d136d85
4 changed files with 244 additions and 0 deletions

View file

@ -0,0 +1,35 @@
summary: PIP bash completion functionality smoke test
description: |
Comprehensive test for pip bash completion functionality on Fedora/RHEL systems.
The test performs the following steps:
1. Finds the bash completion script in the given (e.g. python3-pip) RPM package
2. Discovers all pip executables in the package (e.g. /usr/bin/pip and /usr/bin/pip3.14)
3. Sources the completion script and verifies completion for all executables is registered
4. Runs functional TAB completion tests using expect (for regular and POSIX mode of Bash)
5. Validates that completion works for basic pip commands
This is a smoke test to ensure pip bash completion is properly
installed and functional after package installation.
component:
- python3-pip
test: ./pip_completion_full_test.sh
framework: shell
duration: 5m
tier: 1
require:
- python3-pip
- bash-completion
- expect
- rpm
- bash
environment:
PACKAGE: python3-pip

View file

@ -0,0 +1,88 @@
#!/bin/bash
# Comprehensive PIP bash completion test for RHEL
# Finds completion scripts from RPM, tests all pip binaries, and runs functional tests
PACKAGE="${PACKAGE:-python3-pip}"
# Step 1: Find bash completion scripts in python3-pip RPM package
echo "Step 1: Finding bash completion scripts in $PACKAGE RPM package..."
COMPLETION_FILE=$(rpm -ql $PACKAGE 2>/dev/null | grep -E "/usr/share/bash-completion/completions/" || true)
if [[ -z "$COMPLETION_FILE" ]]; then
echo "✗ No bash completion files found in $PACKAGE package"
exit 1
fi
# Check if there's exactly one completion file
COMPLETION_FILE_COUNT=$(echo "$COMPLETION_FILE" | wc -l)
if [[ $COMPLETION_FILE_COUNT -gt 1 ]]; then
echo "✗ Multiple bash completion files found in $PACKAGE package:"
echo "$COMPLETION_FILE" | sed 's/^/ - /'
echo "Expected exactly one completion file, found $COMPLETION_FILE_COUNT"
exit 1
fi
echo "✓ Found completion file from $PACKAGE package:"
echo "$COMPLETION_FILE" | sed 's/^/ - /'
# Step 2: Find all pip binaries
echo
echo "Step 2: Finding all pip binaries..."
PIP_BINARIES=()
PIP_FILES=$(rpm -ql $PACKAGE | grep /bin/p)
for pip_file in $PIP_FILES; do
if [[ -x "$pip_file" ]]; then
pip_cmd=$(basename "$pip_file")
PIP_BINARIES+=("$pip_cmd")
echo "✓ Found: $pip_cmd -> $pip_file"
fi
done
if [[ ${#PIP_BINARIES[@]} -eq 0 ]]; then
echo "✗ No pip binaries found"
exit 1
fi
echo "Total pip binaries found: ${#PIP_BINARIES[@]}"
# Step 3: Source completion scripts and test each binary
echo
echo "Step 3: Testing completion for each pip binary..."
for AS_POSIX in 0 1; do
if [[ $AS_POSIX -eq 1 ]]; then
echo "Testing in POSIX mode"
POSIX="--posix"
else
echo "Testing in non-POSIX mode"
POSIX=""
fi
echo "Sourcing: $COMPLETION_FILE"
if bash --norc $POSIX -c "source $COMPLETION_FILE" ; then
echo "✓ Successfully sourced $COMPLETION_FILE"
else
echo "! Warning: Failed to source $COMPLETION_FILE"
exit 1
fi
export AS_POSIX
for pip_exec in "${PIP_BINARIES[@]}"; do
echo "Running expect test with $COMPLETION_FILE and $pip_exec..."
if ./test_pip_completion.exp "$COMPLETION_FILE" "$pip_exec"; then
echo "✓ Functional test passed"
else
echo "✗ Functional test failed"
exit 1
fi
done
done
echo "✓ All tests completed successfully!"

View file

@ -0,0 +1,117 @@
#!/usr/bin/expect -f
# PIP bash completion smoke test using expect
# Tests actual TAB completion functionality
# Usage: test_pip_completion.exp [completion_file] [pip_binary]
set timeout 5
set completion_file [lindex $argv 0]
set pip_exec [lindex $argv 1]
puts "=== PIP Bash Completion Test (using expect) ==="
puts "Testing completion file: $completion_file"
puts "Testing pip binary: $pip_exec"
# Check if completion file exists first
if {![file exists $completion_file]} {
puts "✗ Completion file not found: $completion_file"
exit 1
}
puts "✓ Completion file found: $completion_file"
# Start bash shell
if {[info exists env(AS_POSIX)] && $env(AS_POSIX) == "1"} {
spawn bash --norc --posix
} else {
spawn bash --norc
}
expect "$ "
# Source the completion file
send "source $completion_file\r"
expect "$ "
puts "Attempted to source completion file"
# Test 1: Basic pip command completion
puts "\nTest 1: Testing '$pip_exec ' + TAB completion..."
send "$pip_exec "
sleep 0.1
# Send TAB TAB using hex codes
send "\x09\x09"
expect {
-re "(install|uninstall|list|show)" {
puts "✓ Basic pip commands found in completion"
expect "$ "
}
-re "Display all" {
puts "✓ Completion showing options menu"
send "n\r"
expect "$ "
}
timeout {
puts "✗ Timeout waiting for completion - test failed"
exit 1
}
}
# Clear the line and ensure clean prompt
send "\x03"
expect "$ "
send "\r"
expect "$ "
# Test 2: Test partial command completion (simpler test)
puts "\nTest 2: Testing '$pip_exec insta' + TAB completion..."
send "$pip_exec insta"
sleep 0.1
# Single TAB for completion
send "\x09"
expect {
-re "install" {
puts "✓ Partial command completion works (insta -> install)"
expect "$ "
}
timeout {
puts "✗ Timeout on partial completion test - test failed"
exit 1
}
}
# Clear the line and ensure clean prompt
send "\x03"
expect "$ "
send "\r"
expect "$ "
# Test 3: Test help completion
puts "\nTest 3: Testing '$pip_exec --' + TAB completion..."
send "$pip_exec --"
sleep 0.1
send "\x09\x09"
expect {
-re "(--help|--version)" {
puts "✓ Command options found in completion"
expect "$ "
}
timeout {
puts "✗ Timeout on options completion test - test failed"
exit 1
}
}
# Final cleanup - make sure we're at clean prompt
send "\x03"
expect "$ "
send "\r"
expect "$ "
# Exit bash cleanly
send "exit\r"
expect eof
puts "\n=== Completion Test Complete ==="
puts "PIP bash completion functionality tested!"

View file

@ -73,6 +73,9 @@
dir: pyproject-rpm-macros/tests
run: ./mocktest.sh python-clikit
- pip_install_upgrade
- bash_completion:
dir: tests/bash_completion
run: ./pip_completion_full_test.sh
required_packages:
- gcc
- virtualenv
@ -91,3 +94,4 @@
- grep
- util-linux
- shadow-utils
- expect