|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +# TODO: REmove --- temporary |
| 6 | +realpath() { |
| 7 | + readlink -f "$1" |
| 8 | +} |
| 9 | + |
| 10 | +PROJ_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")/..")" |
| 11 | +EXAMPLE_PROJECT_BASE_DIR="${EXAMPLE_PROJECT_BASE_DIR:-"$PROJ_DIR/tests/example_project"}" |
| 12 | + |
| 13 | +if [ -z "${UTILS_LOADED}" ]; then |
| 14 | + # shellcheck source=tests/utils.sh |
| 15 | + source "$PROJ_DIR/tests/utils.sh" |
| 16 | +fi |
| 17 | + |
| 18 | +create_example_project() { |
| 19 | + local EXAMPLE_PROJECT_DIR="$1" |
| 20 | + |
| 21 | + log "Creating example project in: $EXAMPLE_PROJECT_DIR" |
| 22 | + mkdir -vp "$(dirname "$EXAMPLE_PROJECT_DIR")" |
| 23 | + cp -r "${EXAMPLE_PROJECT_BASE_DIR}" "$EXAMPLE_PROJECT_DIR" |
| 24 | + |
| 25 | + pushd "$EXAMPLE_PROJECT_DIR" >/dev/null || return 1 |
| 26 | + log "Constructing git history in repository" |
| 27 | + git init |
| 28 | + git add . |
| 29 | + git commit -m "Initial commit" |
| 30 | + git remote add origin "https://github.com/python-semantic-release/example-project.git" |
| 31 | + |
| 32 | + cat <<EOF >pyproject.toml |
| 33 | +[project] |
| 34 | +name = "example" |
| 35 | +version = "1.0.0" |
| 36 | +description = "Example project" |
| 37 | +EOF |
| 38 | + git commit -am '1.0.0' |
| 39 | + git tag -a v1.0.0 -m "v1.0.0" |
| 40 | + |
| 41 | + popd >/dev/null || return 1 |
| 42 | + log "Example project created successfully" |
| 43 | +} |
| 44 | + |
| 45 | +# ------------------------------ |
| 46 | +# TEST SUITE DRIVER |
| 47 | +# ------------------------------ |
| 48 | + |
| 49 | +run_test_suite() { |
| 50 | + local ALL_TEST_FNS |
| 51 | + |
| 52 | + # Dynamically import all test scripts |
| 53 | + for test_script in "$PROJ_DIR"/tests/suite/test_*.sh; do |
| 54 | + if [ -f "$test_script" ]; then |
| 55 | + if ! source "$test_script"; then |
| 56 | + error "Failed to load test script: $test_script" |
| 57 | + fi |
| 58 | + fi |
| 59 | + done |
| 60 | + |
| 61 | + # Extract all test functions |
| 62 | + tests_in_env="$(compgen -A function | grep "^test_")" |
| 63 | + read -r -a ALL_TEST_FNS <<< "$(printf '%s' "$tests_in_env" | tr '\n' ' ')" |
| 64 | +
|
| 65 | + log "" |
| 66 | + log "************************" |
| 67 | + log "* Running test suite *" |
| 68 | + log "************************" |
| 69 | +
|
| 70 | + # Incrementally run all test functions and flag if any fail |
| 71 | + local test_index=1 |
| 72 | + local test_failures=0 |
| 73 | + for test_fn in "${ALL_TEST_FNS[@]}"; do |
| 74 | + if command -v "$test_fn" &>/dev/null; then |
| 75 | + if ! "$test_fn" "$test_index"; then |
| 76 | + ((test_failures++)) |
| 77 | + fi |
| 78 | + fi |
| 79 | + log "--------------------------------------------------------------------------------" |
| 80 | + ((test_index++)) |
| 81 | + done |
| 82 | +
|
| 83 | + log "" |
| 84 | + log "************************" |
| 85 | + log "* Test Summary *" |
| 86 | + log "************************" |
| 87 | + log "" |
| 88 | + log "Total tests executed: ${#ALL_TEST_FNS[@]}" |
| 89 | + log "Successes: $((${#ALL_TEST_FNS[@]} - test_failures))" |
| 90 | + log "Failures: $test_failures" |
| 91 | +
|
| 92 | + if [ "$test_failures" -gt 0 ]; then |
| 93 | + return 1 |
| 94 | + fi |
| 95 | +} |
| 96 | +
|
| 97 | +# ------------------------------ |
| 98 | +# MAIN |
| 99 | +# ------------------------------ |
| 100 | +
|
| 101 | +log "================================================================================" |
| 102 | +log "|| Publish Action Test Runner ||" |
| 103 | +log "================================================================================" |
| 104 | +log "Initializing..." |
| 105 | +
|
| 106 | +# Make absolute path to project directory |
| 107 | +PROJECT_MOUNT_DIR="${PROJ_DIR:?}/${PROJECT_MOUNT_DIR:?}" |
| 108 | +
|
| 109 | +log "" |
| 110 | +log "******************************" |
| 111 | +log "* Running test suite setup *" |
| 112 | +log "******************************" |
| 113 | +log "" |
| 114 | +
|
| 115 | +# Setup project environment |
| 116 | +create_example_project "$PROJECT_MOUNT_DIR" |
| 117 | +trap 'rm -rf "${PROJECT_MOUNT_DIR:?}"' EXIT |
| 118 | +
|
| 119 | +run_test_suite |
0 commit comments