|
| 1 | +#!/usr/bin/env bash |
| 2 | +# CI/CD compatibility test for script-dialog library |
| 3 | +# Tests that the library can be sourced without errors in headless environments |
| 4 | + |
| 5 | +set -e # Exit on any error |
| 6 | + |
| 7 | +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 8 | +EXIT_CODE=0 |
| 9 | + |
| 10 | +echo "Testing CI/CD compatibility..." |
| 11 | +echo "" |
| 12 | + |
| 13 | +# Test 1: With TERM=dumb (common in CI environments) |
| 14 | +echo "Test 1: TERM=dumb (common in CI)" |
| 15 | +export TERM=dumb |
| 16 | +# shellcheck source=../script-dialog.sh |
| 17 | +# shellcheck disable=SC1091 # Source file path is constructed at runtime |
| 18 | +if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then |
| 19 | + if echo "$output" | grep -iq "tput.*error\|no value for"; then |
| 20 | + echo " ✗ FAILED: tput errors detected in output" |
| 21 | + echo "$output" |
| 22 | + EXIT_CODE=1 |
| 23 | + else |
| 24 | + echo " ✓ PASSED: Library loaded without tput errors" |
| 25 | + fi |
| 26 | +else |
| 27 | + echo " ✗ FAILED: Library failed to source" |
| 28 | + EXIT_CODE=1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Clean up for next test |
| 32 | +unset INTERFACE bold red yellow normal underline |
| 33 | + |
| 34 | +# Test 2: With TERM unset (also common in CI) |
| 35 | +echo "Test 2: TERM unset" |
| 36 | +unset TERM |
| 37 | +# shellcheck source=../script-dialog.sh |
| 38 | +# shellcheck disable=SC1091 # Source file path is constructed at runtime |
| 39 | +if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then |
| 40 | + if echo "$output" | grep -iq "tput.*error\|no value for"; then |
| 41 | + echo " ✗ FAILED: tput errors detected in output" |
| 42 | + echo "$output" |
| 43 | + EXIT_CODE=1 |
| 44 | + else |
| 45 | + echo " ✓ PASSED: Library loaded without tput errors" |
| 46 | + fi |
| 47 | +else |
| 48 | + echo " ✗ FAILED: Library failed to source" |
| 49 | + EXIT_CODE=1 |
| 50 | +fi |
| 51 | + |
| 52 | +# Clean up for next test |
| 53 | +unset INTERFACE bold red yellow normal underline |
| 54 | + |
| 55 | +# Test 3: With normal TERM (ensure we didn't break normal usage) |
| 56 | +echo "Test 3: TERM=xterm-256color (normal usage)" |
| 57 | +export TERM=xterm-256color |
| 58 | +# shellcheck source=../script-dialog.sh |
| 59 | +# shellcheck disable=SC1091 # Source file path is constructed at runtime |
| 60 | +if output=$(source "${SCRIPT_DIR}"/../script-dialog.sh 2>&1); then |
| 61 | + if echo "$output" | grep -iq "error"; then |
| 62 | + echo " ✗ FAILED: Unexpected errors in output" |
| 63 | + echo "$output" |
| 64 | + EXIT_CODE=1 |
| 65 | + else |
| 66 | + echo " ✓ PASSED: Library loaded successfully" |
| 67 | + fi |
| 68 | +else |
| 69 | + echo " ✗ FAILED: Library failed to source" |
| 70 | + EXIT_CODE=1 |
| 71 | +fi |
| 72 | + |
| 73 | +echo "" |
| 74 | +if [ $EXIT_CODE -eq 0 ]; then |
| 75 | + echo "All CI/CD compatibility tests passed ✓" |
| 76 | +else |
| 77 | + echo "Some CI/CD compatibility tests failed ✗" |
| 78 | +fi |
| 79 | + |
| 80 | +exit $EXIT_CODE |
0 commit comments