aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitattributes2
-rw-r--r--.gitignore1
-rw-r--r--.travis.yml11
-rw-r--r--test/all-tests.sh69
-rw-r--r--test/bootstrap.sh87
-rw-r--r--test/tests/empty-filter-options.fail5
-rw-r--r--test/tests/filter-directory-visited-tags.success25
-rw-r--r--test/tests/get-help.success7
-rw-r--r--test/tests/invalid-filter-options.fail5
-rw-r--r--test/tests/misplaced-help.fail5
10 files changed, 217 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..d745553
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+/.* export-ignore
+/test/ export-ignore \ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..001e30f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/test/temp/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..90cdcee
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,11 @@
+language: generic
+
+sudo: true
+
+before_script:
+ - sudo add-apt-repository ppa:git-core/ppa
+ - sudo apt update
+ - sudo apt install -y git || sudo apt upgrade -y git
+
+script:
+ - ./test/all-tests.sh
diff --git a/test/all-tests.sh b/test/all-tests.sh
new file mode 100644
index 0000000..be10e10
--- /dev/null
+++ b/test/all-tests.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+IS_TEST_CASE=0
+if ! . "$(cd -- "$(dirname -- "$0")" && pwd -P)/bootstrap.sh"
+then
+ echo 'Unable to find bootstrap script'>&2
+ exit 1
+fi
+
+wantedFilter=''
+if test $# -eq 1
+then
+ wantedFilter="${1}"
+else
+ wantedFilter=''
+fi
+
+someTestExecuted=0
+for testFile in "${DIR_TESTCASES}"/*
+do
+ fullTestName="$(basename "${testFile}")"
+ testName=${fullTestName%.success}
+ if test "${fullTestName}" != "${testName}"
+ then
+ should='succeed'
+ else
+ testName=${fullTestName%.fail}
+ if test "${fullTestName}" != "${testName}"
+ then
+ should='fail'
+ else
+ printf 'Unrecognized test case: %s\n', "${fullTestName}"
+ exit 1
+ fi
+ fi
+ if test -z "${wantedFilter}" -o "${testName}" = "${wantedFilter}"
+ then
+ printf '%s should %s... ' "${testName}" "${should}"
+ case "${should}" in
+ 'succeed')
+ if testOutput="$(${testFile} 2>&1)"
+ then
+ printf 'ok.\n'
+ else
+ printf 'FAILED!\n'
+ printf '%s\n' "${testOutput}" >&2
+ exit 1
+ fi
+ ;;
+ 'fail')
+ if testOutput="$(${testFile} 2>&1)"
+ then
+ printf 'FAILED!\n'
+ printf '%s\n' "${testOutput}" >&2
+ exit 1
+ else
+ printf 'ok.\n'
+ fi
+ ;;
+ esac
+ someTestExecuted=1
+ fi
+done
+
+if test ${someTestExecuted} -eq 0
+then
+ echo 'No test found!'>&2
+ exit 1
+fi
diff --git a/test/bootstrap.sh b/test/bootstrap.sh
new file mode 100644
index 0000000..831c13d
--- /dev/null
+++ b/test/bootstrap.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+set -o errexit
+set -o nounset
+IFS='
+'
+
+if test "${IS_TEST_CASE:-1}" -eq '1'
+then
+ DIR_TESTCASES="$(cd -- "$(dirname -- "$0")" && pwd -P)"
+ DIR_TEST="$(dirname "${DIR_TESTCASES}")"
+else
+ DIR_TEST="$(cd -- "$(dirname -- "$0")" && pwd -P)"
+ DIR_TESTCASES="${DIR_TEST}/tests"
+fi
+DIR_ROOT="$(dirname "${DIR_TEST}")"
+DIR_BIN="${DIR_ROOT}/bin"
+DIR_TEMP="${DIR_TEST}/temp"
+DIR_SOURCE="${DIR_TEMP}/source"
+DIR_DESTINATION="${DIR_TEMP}/destination"
+
+BIN_MAIN="${DIR_BIN}/incremental-git-filterbranch.sh"
+if test ! -f "${BIN_MAIN}"
+then
+ echo 'Failed to detect environment'>&2
+ exit 1
+fi
+
+alias git-source='git -C "${DIR_SOURCE}"'
+alias git-destination='git -C "${DIR_DESTINATION}"'
+
+initializeRepositories () {
+ rm -rf "${DIR_TEMP}"
+ mkdir "${DIR_TEMP}"
+
+ git init --quiet "${DIR_SOURCE}"
+ git-source config --local user.email 'email@example.com'
+ git-source config --local user.name 'John Doe'
+
+ echo 'test'>"${DIR_SOURCE}/in-root"
+ git-source add --all
+ git-source commit --quiet --message 'Commit #1'
+ git-source tag tag-01
+
+ mkdir "${DIR_SOURCE}/subdir"
+ echo 'test'>"${DIR_SOURCE}/subdir/subfile"
+ git-source add --all
+ git-source commit --quiet --message 'Commit #2'
+
+ git-source tag tag-02
+
+ echo 'test'>>"${DIR_SOURCE}/in-root"
+ git-source add --all
+ git-source commit --quiet --message 'Commit #3'
+
+ git-source tag tag-03
+
+ echo 'test'>>"${DIR_SOURCE}/in-root"
+ git-source add --all
+ git-source commit --quiet --message 'Commit #3'
+
+ git init --bare --quiet "${DIR_DESTINATION}"
+}
+
+getTagList () {
+ printf '%s\n' $(git -C "${1}" show-ref --tags | sed -E 's:^.*?refs/tags/::' || true)
+}
+
+itemInList () {
+ for itemInListItem in ${2}
+ do
+ if test "${1}" = "${itemInListItem}"
+ then
+ return 0
+ fi
+ done
+ return 1
+}
+
+itemNotInList () {
+ if itemInList "${1}" "${2}"
+ then
+ return 1
+ else
+ return 0
+ fi
+}
diff --git a/test/tests/empty-filter-options.fail b/test/tests/empty-filter-options.fail
new file mode 100644
index 0000000..59d086d
--- /dev/null
+++ b/test/tests/empty-filter-options.fail
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. "$(cd -- "$(dirname -- "$0")" && pwd -P)/../bootstrap.sh"
+
+"${BIN_MAIN}" -- "${DIR_SOURCE}" '' "${DIR_DESTINATION}"
diff --git a/test/tests/filter-directory-visited-tags.success b/test/tests/filter-directory-visited-tags.success
new file mode 100644
index 0000000..527ee5a
--- /dev/null
+++ b/test/tests/filter-directory-visited-tags.success
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+. "$(cd -- "$(dirname -- "$0")" && pwd -P)/../bootstrap.sh"
+
+initializeRepositories
+
+"${BIN_MAIN}" "${DIR_SOURCE}" '--prune-empty --subdirectory-filter subdir' "${DIR_DESTINATION}"
+
+echo 'Fetching tags'
+tags=$(getTagList "${DIR_DESTINATION}")
+if itemInList 'tag-01' "${tags}"
+then
+ printf '%s should not be in tag list:\n%s\n' 'tag-01' "${tags}" >&2
+ exit 1
+fi
+if itemNotInList 'tag-02' "${tags}"
+then
+ printf '%s should be in tag list:\n%s\n' 'tag-02' "${tags}" >&2
+ exit 1
+fi
+if itemInList 'tag-03' "${tags}"
+then
+ printf '%s should not be in tag list:\n%s\n' 'tag-02' "${tags}" >&2
+ exit 1
+fi
diff --git a/test/tests/get-help.success b/test/tests/get-help.success
new file mode 100644
index 0000000..58036a8
--- /dev/null
+++ b/test/tests/get-help.success
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "$(cd -- "$(dirname -- "$0")" && pwd -P)/../bootstrap.sh"
+
+"${BIN_MAIN}" -h
+"${BIN_MAIN}" --help
+"${BIN_MAIN}" --help this is an invalid number of arguments
diff --git a/test/tests/invalid-filter-options.fail b/test/tests/invalid-filter-options.fail
new file mode 100644
index 0000000..5ee6680
--- /dev/null
+++ b/test/tests/invalid-filter-options.fail
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. "$(cd -- "$(dirname -- "$0")" && pwd -P)/../bootstrap.sh"
+
+"${BIN_MAIN}" -- "${DIR_SOURCE}" b "${DIR_DESTINATION}"
diff --git a/test/tests/misplaced-help.fail b/test/tests/misplaced-help.fail
new file mode 100644
index 0000000..a5c2e8f
--- /dev/null
+++ b/test/tests/misplaced-help.fail
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. "$(cd -- "$(dirname -- "$0")" && pwd -P)/../bootstrap.sh"
+
+"${BIN_MAIN}" -- --help

© 2014-2024 Faster IT GmbH | imprint | privacy policy