|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -ex |
| 3 | + |
| 4 | +# Test script for custom build directory functionality |
| 5 | +# Usage: ./test_custom_build_dir.sh [fpm_executable] [example_package_dir] |
| 6 | + |
| 7 | +if [ "$1" ]; then |
| 8 | + fpm="$1" |
| 9 | +else |
| 10 | + fpm=fpm |
| 11 | +fi |
| 12 | + |
| 13 | +if [ "$2" ]; then |
| 14 | + test_package="$2" |
| 15 | +else |
| 16 | + test_package="hello_world" |
| 17 | +fi |
| 18 | + |
| 19 | +echo "Testing custom build directory functionality with package: $test_package" |
| 20 | + |
| 21 | +# Test 1: Custom build directory with CLI option |
| 22 | +pushd "$test_package" |
| 23 | +echo "Test 1: CLI option --build-dir" |
| 24 | +rm -rf ./build custom_build_test |
| 25 | +"$fpm" build --build-dir custom_build_test |
| 26 | +test -d custom_build_test |
| 27 | +test -f custom_build_test/.gitignore |
| 28 | +"$fpm" run --build-dir custom_build_test --target "$test_package" |
| 29 | +# Verify standard build directory was not created |
| 30 | +test ! -d build |
| 31 | +echo "✓ CLI option --build-dir works" |
| 32 | + |
| 33 | +# Test 2: Environment variable |
| 34 | +echo "Test 2: Environment variable FPM_BUILD_DIR" |
| 35 | +rm -rf custom_build_test env_build_test |
| 36 | +FPM_BUILD_DIR=env_build_test "$fpm" build |
| 37 | +test -d env_build_test |
| 38 | +test -f env_build_test/.gitignore |
| 39 | +FPM_BUILD_DIR=env_build_test "$fpm" run --target "$test_package" |
| 40 | +echo "✓ Environment variable FPM_BUILD_DIR works" |
| 41 | + |
| 42 | +# Test 3: CLI option overrides environment variable |
| 43 | +echo "Test 3: CLI option overrides environment variable" |
| 44 | +rm -rf env_build_test cli_override_test |
| 45 | +FPM_BUILD_DIR=env_build_test "$fpm" build --build-dir cli_override_test |
| 46 | +test -d cli_override_test |
| 47 | +test ! -d env_build_test |
| 48 | +echo "✓ CLI option correctly overrides environment variable" |
| 49 | + |
| 50 | +# Test 4: Build directory validation - reserved names |
| 51 | +echo "Test 4: Build directory validation" |
| 52 | +# These should fail with specific error messages |
| 53 | +if "$fpm" build --build-dir src 2>&1 | grep -q "conflicts with source directory"; then |
| 54 | + echo "✓ Correctly rejected 'src'" |
| 55 | +else |
| 56 | + echo "ERROR: Should reject 'src'" && exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +if "$fpm" build --build-dir app 2>&1 | grep -q "conflicts with source directory"; then |
| 60 | + echo "✓ Correctly rejected 'app'" |
| 61 | +else |
| 62 | + echo "ERROR: Should reject 'app'" && exit 1 |
| 63 | +fi |
| 64 | + |
| 65 | +if "$fpm" build --build-dir test 2>&1 | grep -q "conflicts with source directory"; then |
| 66 | + echo "✓ Correctly rejected 'test'" |
| 67 | +else |
| 68 | + echo "ERROR: Should reject 'test'" && exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +if "$fpm" build --build-dir . 2>&1 | grep -q "would overwrite the current"; then |
| 72 | + echo "✓ Correctly rejected '.'" |
| 73 | +else |
| 74 | + echo "ERROR: Should reject '.'" && exit 1 |
| 75 | +fi |
| 76 | + |
| 77 | +# Test 5: Path normalization |
| 78 | +echo "Test 5: Path normalization" |
| 79 | +if "$fpm" build --build-dir ./src 2>&1 | grep -q "conflicts with source directory"; then |
| 80 | + echo "✓ Correctly rejected './src' (path normalization works)" |
| 81 | +else |
| 82 | + echo "ERROR: Should reject './src'" && exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +# Test 6: Different commands with custom build directory |
| 86 | +echo "Test 6: Different commands with custom build directory" |
| 87 | +rm -rf test_build_all |
| 88 | +"$fpm" build --build-dir test_build_all |
| 89 | +"$fpm" run --build-dir test_build_all --target "$test_package" |
| 90 | +# Some packages may not have tests, so this might fail but that's expected |
| 91 | +"$fpm" test --build-dir test_build_all 2>/dev/null || echo "No tests in $test_package (expected)" |
| 92 | +echo "✓ All commands work with custom build directory" |
| 93 | + |
| 94 | +# Cleanup test directories |
| 95 | +rm -rf custom_build_test env_build_test cli_override_test test_build_all |
| 96 | +popd |
| 97 | + |
| 98 | +echo "All custom build directory tests passed!" |
0 commit comments