Changeset View
Changeset View
Standalone View
Standalone View
contrib/arcanist/test/test-rebase.sh
- This file was added.
Property | Old Value | New Value |
---|---|---|
File Mode | null | 100755 |
#!/usr/bin/env bash | |||||
# Copyright (c) 2019 The Bitcoin developers | |||||
# Distributed under the MIT software license, see the accompanying | |||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
export LC_ALL=C.UTF-8 | |||||
set -euxo pipefail | |||||
TOPLEVEL=$(git rev-parse --show-toplevel) | |||||
CURRENT_DIR=$(dirname $(readlink -f "$0")) | |||||
TEST_PATCH="${CURRENT_DIR}/test-commit.patch" | |||||
TEST_MERGE_CONFLICT_PATCH="${CURRENT_DIR}/test-merge-conflict.patch" | |||||
LATEST_MASTER=$(git rev-parse origin/master) | |||||
run_rebase_script() { | |||||
PATCH_ARGS="--patch $1" | |||||
# Setting the remote to this repo allows us to simulate an upstream without | |||||
# relying on external services for unit tests. | |||||
export EDITOR="${CURRENT_DIR}/test-commit-message.sh" | |||||
"${CURRENT_DIR}/../rebase.sh" -o "${TOPLEVEL}" --patch-args "${PATCH_ARGS}" | |||||
} | |||||
test_rebase() { | |||||
test_cleanup() { | |||||
# Cleanup current branch so that arcanist doesn't run out of branch names | |||||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | |||||
git checkout master | |||||
git branch -D "${CURRENT_BRANCH}" || true | |||||
} | |||||
trap "test_cleanup" RETURN ERR | |||||
if [ ! -z "$(git status --porcelain)" ]; then | |||||
echo "Error: There should be no unstaged changes." | |||||
exit 10 | |||||
fi | |||||
if [ "${LATEST_MASTER}" != "$(git rev-parse HEAD~)" ]; then | |||||
echo "Error: Failed to rebase on latest master." | |||||
exit 11 | |||||
fi | |||||
if [ ! -z "$(echo "$(git diff HEAD~)" | diff - "${TEST_PATCH}")" ]; then | |||||
echo "Error: Rebased changes do not match the given patch." | |||||
exit 12 | |||||
fi | |||||
# Make sure test file is not present. | |||||
if [ ! -z "$1" ] && [ -f "$1" ]; then | |||||
echo "Error: '$1' file was found but not expected!" | |||||
exit 20 | |||||
fi | |||||
} | |||||
TEST_STATUS="FAILED" | |||||
cleanup() { | |||||
# Cleanup the temporary test directory | |||||
rm -rf "$1" | |||||
# Nicely print the final test status | |||||
set +x | |||||
echo | |||||
echo "${0}:" | |||||
echo "${TEST_STATUS}" | |||||
} | |||||
TEMP_DIR=$(mktemp -d) | |||||
trap "cleanup ${TEMP_DIR}" RETURN EXIT | |||||
cd "${TEMP_DIR}" | |||||
git init | |||||
git pull "${TOPLEVEL}" origin/master | |||||
( | |||||
echo "TEST: Rebase script fast-forwards as expected" | |||||
git reset --hard HEAD~10 | |||||
run_rebase_script "${TEST_PATCH}" | |||||
test_rebase "" | |||||
) | |||||
( | |||||
echo "TEST: Merge conflicts fail as expected" | |||||
TEST_FILE="test-committed-changes" | |||||
touch "${TEST_FILE}" | |||||
git add "${TEST_FILE}" | |||||
git commit -m "test local commit" | |||||
run_rebase_script "${TEST_MERGE_CONFLICT_PATCH}" | |||||
if [ test_rebase "${TEST_FILE}" -ne 12 ]; then | |||||
Lint: ShellCheck found an issue:: The mentioned parser error was in this if expression. | |||||
Lint: ShellCheck found an issue: Couldn't parse this test expression. Lint: ShellCheck found an issue:: Couldn't parse this test expression. | |||||
Lint: ShellCheck found an issue: Use 'if cmd; then ..' to check exit code, or 'if $(cmd) == ..' to check output. Lint: ShellCheck found an issue:: Use 'if cmd; then ..' to check exit code, or 'if [[ $(cmd) == .. ]]' to check output. | |||||
Lint: ShellCheck found an issue: Expected "]". Fix any mentioned problems and try again. Lint: ShellCheck found an issue:: Expected "]". Fix any mentioned problems and try again. | |||||
echo "Error: Merge conflict unexpected succeeded." | |||||
exit 50 | |||||
fi | |||||
) | |||||
( | |||||
echo "TEST: Locally committed changes are not included in the rebase" | |||||
TEST_FILE="test-committed-changes" | |||||
touch "${TEST_FILE}" | |||||
git add "${TEST_FILE}" | |||||
git commit -m "test local commit" | |||||
run_rebase_script "${TEST_PATCH}" | |||||
test_rebase "${TEST_FILE}" | |||||
) | |||||
( | |||||
echo "TEST: Staged changes are not included in the rebase" | |||||
TEST_FILE="test-staged-changes" | |||||
touch "${TEST_FILE}" | |||||
git add "${TEST_FILE}" | |||||
run_rebase_script "${TEST_PATCH}" | |||||
test_rebase "${TEST_FILE}" | |||||
) | |||||
( | |||||
echo "TEST: Unstaged changes are not included in the rebase" | |||||
TEST_FILE="test-unstaged-changes" | |||||
touch "${TEST_FILE}" | |||||
run_rebase_script "${TEST_PATCH}" | |||||
test_rebase "${TEST_FILE}" | |||||
) | |||||
TEST_STATUS="PASSED" |
The mentioned parser error was in this if expression.