|
| 1 | +exec >&2 |
| 2 | +. ../skip-if-minimal-do.sh |
| 3 | + |
| 4 | +# Test 1: With -q, successful build produces no output |
| 5 | +echo "Test 1: quiet mode suppresses output on success" |
| 6 | +rm -f target1 |
| 7 | +output=$(redo -q target1 2>&1) |
| 8 | +if [ -n "$output" ]; then |
| 9 | + echo "FAIL: expected no output with -q, got: $output" >&2 |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | +[ -e target1 ] || exit 2 |
| 13 | +echo " PASS" |
| 14 | + |
| 15 | +# Test 2: Without -q, successful build produces output |
| 16 | +echo "Test 2: normal mode shows output" |
| 17 | +rm -f target1 |
| 18 | +output=$(redo target1 2>&1) |
| 19 | +if [ -z "$output" ]; then |
| 20 | + echo "FAIL: expected output without -q" >&2 |
| 21 | + exit 3 |
| 22 | +fi |
| 23 | +echo " PASS" |
| 24 | + |
| 25 | +# Test 3: With -q, errors are still printed |
| 26 | +echo "Test 3: quiet mode still shows errors" |
| 27 | +rm -f failme |
| 28 | +set +e |
| 29 | +output=$(redo -q failme 2>&1) |
| 30 | +rc=$? |
| 31 | +set -e |
| 32 | +if [ "$rc" -eq 0 ]; then |
| 33 | + echo "FAIL: expected non-zero exit" >&2 |
| 34 | + exit 4 |
| 35 | +fi |
| 36 | +if [ -z "$output" ]; then |
| 37 | + echo "FAIL: expected error output with -q on failure" >&2 |
| 38 | + exit 5 |
| 39 | +fi |
| 40 | +case "$output" in |
| 41 | + *Error*) ;; # good |
| 42 | + *) echo "FAIL: expected 'Error' in output, got: $output" >&2; exit 6 ;; |
| 43 | +esac |
| 44 | +echo " PASS" |
| 45 | + |
| 46 | +# Test 4: -q propagates to child redo processes (nested builds) |
| 47 | +echo "Test 4: quiet mode propagates to nested builds" |
| 48 | +rm -f outer inner |
| 49 | +output=$(redo -q outer 2>&1) |
| 50 | +if [ -n "$output" ]; then |
| 51 | + echo "FAIL: expected no output from nested -q build, got: $output" >&2 |
| 52 | + exit 7 |
| 53 | +fi |
| 54 | +[ -e outer ] || exit 8 |
| 55 | +[ -e inner ] || exit 9 |
| 56 | +echo " PASS" |
| 57 | + |
| 58 | +# Test 5: --quiet long form works |
| 59 | +echo "Test 5: --quiet long form" |
| 60 | +rm -f target1 |
| 61 | +output=$(redo --quiet target1 2>&1) |
| 62 | +if [ -n "$output" ]; then |
| 63 | + echo "FAIL: expected no output with --quiet, got: $output" >&2 |
| 64 | + exit 10 |
| 65 | +fi |
| 66 | +echo " PASS" |
| 67 | + |
| 68 | +# Test 6: -q combined with other flags |
| 69 | +echo "Test 6: -q combined with -k (keep-going)" |
| 70 | +rm -f target1 |
| 71 | +output=$(redo -q -k target1 2>&1) |
| 72 | +if [ -n "$output" ]; then |
| 73 | + echo "FAIL: expected no output with -q -k, got: $output" >&2 |
| 74 | + exit 11 |
| 75 | +fi |
| 76 | +echo " PASS" |
| 77 | + |
| 78 | +# Test 7: -q with multiple targets |
| 79 | +echo "Test 7: -q with multiple targets" |
| 80 | +rm -f target1 inner |
| 81 | +output=$(redo -q target1 inner 2>&1) |
| 82 | +if [ -n "$output" ]; then |
| 83 | + echo "FAIL: expected no output with -q and multiple targets, got: $output" >&2 |
| 84 | + exit 12 |
| 85 | +fi |
| 86 | +[ -e target1 ] || exit 13 |
| 87 | +[ -e inner ] || exit 14 |
| 88 | +echo " PASS" |
| 89 | + |
| 90 | +# Test 8: -q doesn't affect build correctness (target content is right) |
| 91 | +echo "Test 8: -q doesn't affect build output content" |
| 92 | +rm -f target1 |
| 93 | +redo -q target1 |
| 94 | +content=$(cat target1) |
| 95 | +if [ "$content" != "built" ]; then |
| 96 | + echo "FAIL: expected 'built' in target1, got: $content" >&2 |
| 97 | + exit 15 |
| 98 | +fi |
| 99 | +echo " PASS" |
| 100 | + |
| 101 | +# Test 9: Nested error in quiet mode still shows error chain |
| 102 | +echo "Test 9: nested error in quiet mode shows error chain" |
| 103 | +rm -f outer_fail inner_fail |
| 104 | +set +e |
| 105 | +output=$(redo -q outer_fail 2>&1) |
| 106 | +rc=$? |
| 107 | +set -e |
| 108 | +if [ "$rc" -eq 0 ]; then |
| 109 | + echo "FAIL: expected non-zero exit from outer_fail" >&2 |
| 110 | + exit 16 |
| 111 | +fi |
| 112 | +case "$output" in |
| 113 | + *Error*) ;; # good |
| 114 | + *) echo "FAIL: expected error output, got: $output" >&2; exit 17 ;; |
| 115 | +esac |
| 116 | +echo " PASS" |
0 commit comments