[med-svn] [freebayes] 06/06: Get tests running at all (not all tests are passing yet)
Andreas Tille
tille at debian.org
Fri Jan 13 16:10:11 UTC 2017
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository freebayes.
commit 815c00ceae3e2292c47ea12e37b7ce00f4d054c9
Author: Andreas Tille <tille at debian.org>
Date: Fri Jan 13 17:09:33 2017 +0100
Get tests running at all (not all tests are passing yet)
---
debian/bash-tap/bash-tap | 369 +++++++++++++++++++++++++++++++++++++
debian/bash-tap/bash-tap-bootstrap | 28 +++
debian/bash-tap/bash-tap-mock | 106 +++++++++++
debian/copyright | 4 +
debian/rules | 8 +-
5 files changed, 512 insertions(+), 3 deletions(-)
diff --git a/debian/bash-tap/bash-tap b/debian/bash-tap/bash-tap
new file mode 100755
index 0000000..e71fe9b
--- /dev/null
+++ b/debian/bash-tap/bash-tap
@@ -0,0 +1,369 @@
+#!/bin/bash
+
+bash_tap_version='1.0.2'
+
+# Our state.
+
+_bt_plan=''
+_bt_expected_tests=0
+_bt_plan_output=0
+_bt_current_test=0
+_bt_tap_output=''
+_bt_has_output_plan=0
+_bt_done_testing=0
+_bt_output_capture=0
+
+# Our test results so far
+unset _bt_test_ok
+unset _bt_test_actual_ok
+unset _bt_test_name
+unset _bt_test_type
+unset _bt_test_reason
+
+# Cleanup stuff.
+declare -a _bt_on_exit_cmds
+trap "_bt_on_exit" EXIT
+
+# Planning functions.
+
+function _bt_output_plan() {
+ local num_tests="$1"
+ local directive="$2"
+ local reason="$3"
+
+ if [ "$_bt_has_output_plan" = 1 ]; then
+ _caller_error "The plan was already output"
+ fi
+
+ _bt_clear_out
+ _bt_out "1..$num_tests"
+ if [ -n "$directive" ]; then
+ _bt_out " # $directive"
+ fi
+ if [ -n "$reason" ]; then
+ _bt_out " $reason"
+ fi
+ _bt_print_out
+ _bt_has_output_plan=1
+}
+
+function plan() {
+ local plan="$1"
+
+ case "$plan" in
+ no_plan) no_plan ;;
+ skip_all) skip_all "$2" ;;
+ tests) expected_tests "$2" ;;
+ *) _bt_die "Unknown or missing plan: '$plan'" ;;
+ esac
+}
+
+function expected_tests() {
+ local num="$1"
+
+ if [ -z "$num" ]; then
+ echo $_bt_expected_tests
+ else
+ if [ -n "$_bt_plan" ]; then
+ _bt_caller_error "Plan is already defined"
+ fi
+ # TODO: validate
+ _bt_plan="$num"
+ _bt_expected_tests="$num"
+ _bt_output_plan "$_bt_expected_tests"
+ fi
+}
+
+function no_plan() {
+ if [ -n "$_bt_plan" ]; then
+ _bt_caller_error "Plan is already defined"
+ fi
+ _bt_plan="no plan"
+}
+
+function done_testing() {
+ local num_tests="$1"
+
+ if [ -z "$num_tests" ]; then
+ num_tests="$_bt_current_test"
+ fi
+
+ if [ "$_bt_done_testing" = 1 ]; then
+ _bt_caller_error "done_testing was already called"
+ fi
+
+ if [ "$_bt_expected_tests" != 0 -a "$num_tests" != "$_bt_expected_tests" ]; then
+ ok 0 "planned to run $_bt_expected_tests but done_testing expects $num_tests"
+ else
+ _bt_expected_tests="$num_tests"
+ fi
+
+ if [ "$_bt_has_output_plan" = 0 ]; then
+ _bt_plan="done testing"
+ _bt_output_plan "$num_tests"
+ fi
+}
+
+function has_plan() {
+ test -n "$_bt_plan"
+}
+
+function skip_all() {
+ local reason="${*:?}"
+
+ _bt_output_plan 0 SKIP "$reason"
+}
+
+# Test functions.
+
+function ok() {
+ local result="$1"
+ local name="$2"
+
+ _bt_current_test=$((_bt_current_test + 1))
+
+ # TODO: validate $name
+ if [ -z "$name" ]; then
+ name='unnamed test'
+ fi
+ name="${name//#/\\#}"
+
+ _bt_clear_out
+ if [ "$result" = 0 ]; then
+ _bt_out "not ok"
+ if [ -n "$TODO" ]; then
+ _bt_test_ok[$_bt_current_test]=1
+ else
+ _bt_test_ok[$_bt_current_test]=0
+ fi
+ _bt_test_actual_ok[$_bt_current_test]=0
+ else
+ _bt_out "ok"
+ _bt_test_ok[$_bt_current_test]=1
+ _bt_test_actual_ok[$_bt_current_test]="$result"
+ fi
+
+ _bt_out " $_bt_current_test - $name"
+ _bt_test_name[$_bt_current_test]="$name"
+
+ if [ -n "$TODO" ]; then
+ _bt_out " # TODO $TODO"
+ _bt_test_reason[$_bt_current_test]="$TODO"
+ _bt_test_type[$_bt_current_test]="todo"
+ else
+ _bt_test_reason[$_bt_current_test]=''
+ _bt_test_type[$_bt_current_test]=''
+ fi
+
+ _bt_print_out
+}
+
+function _is_diag() {
+ local result="$1"
+ local expected="$2"
+
+ diag " got: '$result'"
+ diag " expected: '$expected'"
+}
+
+function is() {
+ local result="$1"
+ local expected="$2"
+ local name="$3"
+
+ if [ "$result" = "$expected" ]; then
+ ok 1 "$name"
+ else
+ ok 0 "$name"
+ _is_diag "$result" "$expected"
+ fi
+}
+
+function _isnt_diag() {
+ local result="$1"
+ local expected="$2"
+
+ diag " got: '$result'"
+ diag " expected: anything else"
+}
+
+function isnt() {
+ local result="$1"
+ local expected="$2"
+ local name="$3"
+
+ if [ "$result" != "$expected" ]; then
+ ok 1 "$name"
+ else
+ ok 0 "$name"
+ _isnt_diag "$result" "$expected"
+ fi
+}
+
+function like() {
+ local result="$1"
+ local pattern="$2"
+ local name="$3"
+
+ # NOTE: leave $pattern unquoted, see http://stackoverflow.com/a/218217/870000
+ if [[ "$result" =~ $pattern ]]; then
+ ok 1 "$name"
+ else
+ ok 0 "$name"
+ diag " got: '$result'"
+ diag " expected: match for '$pattern'"
+ fi
+}
+
+function unlike() {
+ local result="$1"
+ local pattern="$2"
+ local name="$3"
+
+ # NOTE: leave $pattern unquoted, see http://stackoverflow.com/a/218217/870000
+ if [[ ! "$result" =~ $pattern ]]; then
+ ok 1 "$name"
+ else
+ ok 0 "$name"
+ diag " got: '$result'"
+ diag " expected: no match for '$pattern'"
+ fi
+}
+
+function cmp_ok() {
+ echo TODO
+}
+
+# Other helper functions
+
+function BAIL_OUT() {
+ echo TODO
+}
+
+function skip() {
+ echo TODO
+}
+
+function todo_skip() {
+ echo TODO
+}
+
+function todo_start() {
+ echo TODO
+}
+
+function todo_end() {
+ echo TODO
+}
+
+# Output
+
+function diag() {
+ local message="$1"
+
+ if [ -n "$message" ]; then
+ _bt_escaped_echo "# $message"
+ fi
+}
+
+# Util functions for output capture within current shell
+
+function start_output_capture() {
+ if [ $_bt_output_capture = 1 ]; then
+ finish_output_capture
+ _bt_caller_error "Can't start output capture while already active"
+ fi
+ local stdout_tmpfile="/tmp/bash-itunes-test-out.$$"
+ local stderr_tmpfile="/tmp/bash-itunes-test-err.$$"
+ _bt_add_on_exit_cmd "rm -f '$stdout_tmpfile' '$stderr_tmpfile'"
+ _bt_output_capture=1
+ exec 3>&1 >$stdout_tmpfile 4>&2 2>$stderr_tmpfile
+}
+
+function finish_output_capture() {
+ local capture_stdout_varname="$1"
+ local capture_stderr_varname="$2"
+ if [ $_bt_output_capture != 1 ]; then
+ _bt_caller_error "Can't finish output capture when it wasn't started"
+ fi
+ exec 1>&3 3>&- 2>&4 4>&-
+ _bt_output_capture=0
+ if [ -n "$capture_stdout_varname" ]; then
+ local stdout_tmpfile="/tmp/bash-itunes-test-out.$$"
+ eval "$capture_stdout_varname=\$(< $stdout_tmpfile)"
+ fi
+ if [ -n "$capture_stderr_varname" ]; then
+ local stderr_tmpfile="/tmp/bash-itunes-test-err.$$"
+ eval "$capture_stderr_varname=\$(< $stderr_tmpfile)"
+ fi
+}
+
+# Internals
+
+function _bt_stdout() {
+ echo "$@"
+}
+
+function _bt_stderr() {
+ echo "$@" >&2
+}
+
+function _bt_die() {
+ _bt_stderr "$@"
+ exit 255
+}
+
+# Report an error from the POV of the first calling point outside this file
+function _bt_caller_error() {
+ local message="$*"
+
+ local thisfile="${BASH_SOURCE[0]}"
+ local file="$thisfile"
+ local frame_num=2
+ until [ "$file" != "$thisfile" ]; do
+ frame=$(caller "$frame_num")
+ IFS=' ' read line func file <<<"$frame"
+ done
+
+ _bt_die "Error: $message, on line $line of $file"
+}
+
+# Echo the supplied message with lines after the
+# first escaped as TAP comments.
+function _bt_escaped_echo() {
+ local message="$*"
+
+ local output=''
+ while IFS= read -r line; do
+ output="$output\n# $line"
+ done <<<"$message"
+ echo -e "${output:4}"
+}
+
+function _bt_clear_out() {
+ _bt_tap_output=""
+}
+
+function _bt_out() {
+ _bt_tap_output="$_bt_tap_output$*"
+}
+
+function _bt_print_out() {
+ _bt_escaped_echo "$_bt_tap_output"
+}
+
+# Cleanup stuff
+function _bt_add_on_exit_cmd() {
+ _bt_on_exit_cmds[${#_bt_on_exit_cmds[*]}]="$*"
+}
+
+function _bt_on_exit() {
+ if [ $_bt_output_capture = 1 ]; then
+ finish_output_capture
+ fi
+ for exit_cmd in "${_bt_on_exit_cmds[@]}"; do
+ diag "cleanup: $exit_cmd"
+ eval "$exit_cmd"
+ done
+ # TODO: check that we've output a plan/results
+}
diff --git a/debian/bash-tap/bash-tap-bootstrap b/debian/bash-tap/bash-tap-bootstrap
new file mode 100755
index 0000000..23074de
--- /dev/null
+++ b/debian/bash-tap/bash-tap-bootstrap
@@ -0,0 +1,28 @@
+#!/bin/bash
+#
+# Bash TAP Bootstrap:
+# Copy this file into your project tests dir and source it
+# from each test file with:
+# . $(dirname $0)/bash-tap-bootstrap
+# It takes care of finding bash-tap or outputing a usage message.
+#
+
+bash_tap_bootstrap_version='1.0.2'
+
+if [ "${BASH_SOURCE[0]}" = "$0" ]; then
+ # Being run directly, probably by test harness running entire dir.
+ echo "1..0 # SKIP bash-tap-bootstrap isn't a test file"
+ exit 0
+fi
+
+if [ -z "$BASH_TAP_ROOT" ]; then
+ # TODO: search likely locations.
+ BASH_TAP_ROOT="$(dirname ${BASH_SOURCE[0]})/../../bash-tap"
+fi
+
+if [ -f "$BASH_TAP_ROOT/bash-tap" ]; then
+ . "$BASH_TAP_ROOT/bash-tap"
+else
+ echo "Bail out! Unable to find bash-tap. Install from https://github.com/illusori/bash-tap or set \$BASH_TAP_ROOT if you have it installed somewhere unusual."
+ exit 255
+fi
diff --git a/debian/bash-tap/bash-tap-mock b/debian/bash-tap/bash-tap-mock
new file mode 100755
index 0000000..1800198
--- /dev/null
+++ b/debian/bash-tap/bash-tap-mock
@@ -0,0 +1,106 @@
+#!/bin/bash
+#
+# While not directly TAP-specific, being able to mock stuff
+# in tests is pretty useful.
+#
+# If you're using bash-tap-bootstrap, then just source this
+# file in your tests from the bash-tap directory found by
+# the bootstrap by including this line after you've sourced
+# bash-tap-bootstrap:
+#
+# . "$BASH_TAP_ROOT/bash-tap-mock"
+#
+# If you're not using bash-tap-bootstrap then copy this file
+# to your test directory and source it with:
+#
+# . $(dirname $0)/bash-tap-mock
+#
+# It's important to note that if you're capturing the arguments
+# passed to your mock function in a variable, and want that
+# variable to be accessible to your tests, you must ensure that
+# the mocked function is executed in the current shell and not
+# a subshell. In particular, this means you cannot use $() or
+# `` to capture output of the function at the same time, as these
+# invoke a subshell - the mock will happen, but any variables you
+# set within your mock will only exist within the subshell.
+# If you wish to capture output at the same time, you need to
+# make use of the start_output_capture and finish_output_capture
+# helper functons in bash-tap, or manually use file-descriptor
+# redirects yourself to achieve the same effect.
+
+bash_tap_mock_version='1.0.2'
+
+if [ "${BASH_SOURCE[0]}" = "$0" ]; then
+ # Being run directly, probably by test harness running entire dir.
+ echo "1..0 # SKIP bash-tap-mock isn't a test file"
+ exit 0
+fi
+
+function mock_function() {
+ local original_name="$1"
+ local mock_name="$2"
+ local save_original_as="_btm_mocked_${original_name}"
+
+ if [ -z $(declare -F "$save_original_as") ]; then
+ _btm_copy_function "$original_name" "$save_original_as"
+ fi
+ _btm_copy_function "$mock_name" "$original_name"
+}
+
+function restore_mocked_function() {
+ local original_name="$1"
+ local save_original_as="_btm_mocked_${original_name}"
+
+ if [ ! -z $(declare -F "$save_original_as") ]; then
+ _btm_copy_function "$save_original_as" "$original_name"
+ unset -f "$save_original_as"
+ else
+ _btm_caller_error "Can't find saved original function '$original_name' to restore"
+ fi
+}
+
+function mock_command() {
+ local command_name="$1"
+ local mock_name="$2"
+
+ if [ ! -z $(declare -F "$command_name") ]; then
+ # It's not actually a command, it's a function, mock that
+ mock_function "$command_name" "$mock_name"
+ else
+ _btm_copy_function "$mock_name" "$command_name"
+ fi
+}
+
+function restore_mocked_command() {
+ local command_name="$1"
+
+ local save_original_as="_btm_mocked_${command_name}"
+ if [ ! -z $(declare -F "$save_original_as") ]; then
+ # Was actually a function mock not a command mock.
+ restore_mocked_function "$command_name"
+ else
+ unset -f "$command_name" >/dev/null
+ fi
+}
+
+# Copied from http://stackoverflow.com/a/1203628/870000
+function _btm_copy_function() {
+ declare -F $1 >/dev/null || _btm_caller_error "Can't find function '$1' to copy"
+ eval "$(echo "${2}()"; declare -f ${1} | tail -n +2)"
+}
+
+# Report an error from the POV of the first calling point outside this file
+function _btm_caller_error() {
+ local message="$*"
+
+ local thisfile="${BASH_SOURCE[0]}"
+ local file="$thisfile"
+ local frame_num=2
+ until [ "$file" != "$thisfile" ]; do
+ frame=$(caller "$frame_num")
+ IFS=' ' read line func file <<<"$frame"
+ done
+
+ echo "Error: $message, on line $line of $file" >&2
+ exit 255
+}
diff --git a/debian/copyright b/debian/copyright
index f48eaa0..a2e21a5 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -10,6 +10,10 @@ Files: intervaltree/*
Copyright: Erik Garrison <erik.garrison at gmail.com>
License: MIT
+Files: debian/bash-tap/*
+Copyright: 2012-2016 Sam Graham
+License: MIT
+
Files: ttmath/*
Copyright: 2006-2012, Tomasz Sowa
License: BSD
diff --git a/debian/rules b/debian/rules
index c679fb0..6524b20 100755
--- a/debian/rules
+++ b/debian/rules
@@ -6,6 +6,8 @@
override_dh_auto_install:
echo "Skip autoinstall process - files are moved around by dh_install"
-get-orig-source:
- mkdir -p ../tarballs
- uscan --verbose --force-download --repack --compress xz --destdir=../tarballs
+override_dh_auto_test:
+ mkdir -p $(CURDIR)/test/bash-tap/
+ for bt in $(CURDIR)/debian/bash-tap/* ; do ln -s $${bt} $(CURDIR)/test/bash-tap/`basename $${bt}` ; done
+ dh_auto_test
+ rm -rf $(CURDIR)/test/bash-tap
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/freebayes.git
More information about the debian-med-commit
mailing list