aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2016-01-10 16:53:04 +0100
committerKate Ward <kate.ward@forestent.com>2016-01-10 16:53:04 +0100
commit4b66ecdc0d3f6b89d3132b75f5aca1773a29a1a3 (patch)
tree9668b6e23a484f660f25ff34c98876db0276ffe6 /bin
parentb11509fad7f5e9e66a734116fcec7c418419ee1f (diff)
downloadshflags-4b66ecdc0d3f6b89d3132b75f5aca1773a29a1a3.tar.gz
restructured source for GitHub
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cb_wrapper.sh1
-rwxr-xr-xbin/continuous_build.sh126
-rw-r--r--bin/gen_test_results.flags12
-rwxr-xr-xbin/gen_test_results.sh88
4 files changed, 227 insertions, 0 deletions
diff --git a/bin/cb_wrapper.sh b/bin/cb_wrapper.sh
new file mode 100755
index 0000000..418dd93
--- /dev/null
+++ b/bin/cb_wrapper.sh
@@ -0,0 +1 @@
+../bin/continuous_build.sh -c ./shflags_test.sh -w shflags -O ~/tmp
diff --git a/bin/continuous_build.sh b/bin/continuous_build.sh
new file mode 100755
index 0000000..6f47c69
--- /dev/null
+++ b/bin/continuous_build.sh
@@ -0,0 +1,126 @@
+# /bin/sh
+# $Id$
+# vim:et:ft=sh:sts=2:sw=2
+#
+# Copyright 2010 Kate Ward. All Rights Reserved.
+# Author: kate.ward@forestent.com (Kate Ward)
+#
+# Continuous build script for shell library testing.
+#
+# Sample usages:
+# $ blah
+
+# treat unset variables as an error
+set -u
+
+# global constants
+ARGV0=`basename "$0"`
+ARGV0_DIR=`dirname "$0"`
+SHLIB_DIR="${ARGV0_DIR}/../lib"
+
+# load libraries
+. ${SHFLAGS_LIB:-${SHLIB_DIR}/shflags} \
+ || (echo 'unable to load shflags library' >&2; exit 1)
+. ${VERSIONS_LIB:-${SHLIB_DIR}/versions} \
+ || (echo 'unable to load versions library' >&2; exit 1)
+
+OUTPUT_FILE="${VERSIONS_OS_NAME}_${VERSIONS_OS_RELEASE}"
+
+# define flags
+DEFINE_string 'command' '' 'the command to start a build' 'c'
+DEFINE_string 'watch' '' 'file to watch for changes' 'w'
+DEFINE_string 'watch_from' '' 'file containing filenames to watch' 'W'
+DEFINE_string 'output' "${OUTPUT_FILE}" 'output file to write to' 'o'
+DEFINE_string 'output_dir' '.' 'directory to write output file' 'O'
+DEFINE_integer 'pause' 60 'pause between successive runs (sec)' 'p'
+
+FLAGS_HELP="USAGE: ${ARGV0} [flags]"
+
+#------------------------------------------------------------------------------
+# functions
+#
+
+# This function exits the script, optionally printing a message
+#
+# Args:
+# message: string: an error message to be output (optional)
+# Output:
+# string: usable flags
+die() {
+ [ $# -ne 0 ] && echo "$@" >&2
+ flags_help
+ exit 1
+}
+
+# Function to give the current date in ISO format
+#
+# Args:
+# none
+# Output:
+# string: isodate
+isodate() {
+ date -u '+%Y%m%dT%H%M%SZ'
+}
+
+age() {
+ awkScript=''
+ case ${VERSIONS_OS_NAME} in
+ FreeBSD|Solaris) awkScript='{print $6,$7,$8}' ;;
+ Linux) awkScript='{print $6,$7}' ;;
+ *) echo "unrecognized OS name (${VERSIONS_OS_NAME})" >&2 ;;
+ esac
+ ls -l "$1" |awk "${awkScript}"
+}
+
+#------------------------------------------------------------------------------
+# main
+#
+
+main()
+{
+ # checks
+ [ -n "${FLAGS_command}" ] || die 'command required'
+ [ -z "${FLAGS_watch}" -a -z "${FLAGS_watch_from}" ] \
+ && die 'one of watch or watch_from required'
+ [ -n "${FLAGS_watch}" -a -n "${FLAGS_watch_from}" ] \
+ && die 'only one of watch or watch_from can be specified'
+ [ -r "${FLAGS_watch}" ] || die 'unable to read watch file'
+ [ -w "${FLAGS_output_dir}" ] || die 'unable to write to output directory'
+
+ watchAge=`age "${FLAGS_watch}"`
+ watchAgePrev=${watchAge}
+
+ # build
+ while true; do
+ if [ ! "${watchAge}" == "${watchAgePrev}" ]; then
+ date=`isodate`
+ echo "building ${VERSIONS_OS_NAME}-${VERSIONS_OS_RELEASE} @ ${date}"
+ outputFileDated="${FLAGS_output}-${date}"
+ ${FLAGS_command} >"${FLAGS_output_dir}/${outputFileDated}" 2>&1
+
+ ( cd "${FLAGS_output_dir}";
+ rm -f "${FLAGS_output}";
+ ln -s "${outputFileDated}" "${FLAGS_output}";
+ grep FAIL "${FLAGS_output}"; )
+
+ watchAgePrev=${watchAge}
+ fi
+
+ watchAge=`age "${FLAGS_watch}"`
+ if [ "${watchAge}" == "${watchAgePrev}" ]; then
+ echo 'sleeping...'
+ while [ "${watchAge}" == "${watchAgePrev}" ]; do
+ sleep ${FLAGS_pause}
+ watchAge=`age "${FLAGS_watch}"`
+ done
+ fi
+ done
+}
+
+# execute main() if this is run in standalone mode (i.e. not in a unit test)
+argv0=`echo "${ARGV0}" |sed 's/_test$//;s/_test\.sh$//'`
+if [ "${ARGV0}" = "${argv0}" ]; then
+ FLAGS "$@" || exit $?
+ eval set -- "${FLAGS_ARGV}"
+ if [ $# -gt 0 ]; then main "$@"; else main; fi
+fi
diff --git a/bin/gen_test_results.flags b/bin/gen_test_results.flags
new file mode 100644
index 0000000..f42e2ae
--- /dev/null
+++ b/bin/gen_test_results.flags
@@ -0,0 +1,12 @@
+# $Id$
+# vim:et:ft=sh:sts=2:sw=2
+#
+# Copyright 2011 Kate Ward. All Rights Reserved.
+# Released under the LGPL (GNU Lesser General Public License)
+#
+# Author: kate.ward@forestent.com (Kate Ward)
+#
+# Flag definition overrides for the gen_test_results.sh script.
+#
+
+DEFINE_string suite 'shflags_test.sh' 'unit test suite' s
diff --git a/bin/gen_test_results.sh b/bin/gen_test_results.sh
new file mode 100755
index 0000000..79d2fd4
--- /dev/null
+++ b/bin/gen_test_results.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# $Id$
+# vim:et:ft=sh:sts=2:sw=2
+#
+# Copyright 2008 Kate Ward. All Rights Reserved.
+# Released under the LGPL (GNU Lesser General Public License)
+#
+# Author: kate.ward@forestent.com (Kate Ward)
+#
+# This script runs the provided unit tests and sends the output to the
+# appropriate file.
+#
+
+# treat unset variables as an error
+set -u
+
+die()
+{
+ [ $# -gt 0 ] && echo "error: $@" >&2
+ exit 1
+}
+
+BASE_DIR="`dirname $0`/.."
+LIB_DIR="${BASE_DIR}/lib"
+
+# load libraries
+. ${LIB_DIR}/shflags || die 'unable to load shflags library'
+. ${LIB_DIR}/shlib || die 'unable to load shlib library'
+. ${LIB_DIR}/versions || die 'unable to load versions library'
+
+# redefining BASE_DIR now that we have the shlib functions
+BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"`
+BIN_DIR="${BASE_DIR}/bin"
+SRC_DIR="${BASE_DIR}/src"
+
+os_name=`versions_osName |sed 's/ /_/g'`
+os_version=`versions_osVersion`
+
+# load external flags
+. ${BIN_DIR}/gen_test_results.flags
+
+# define flags
+DEFINE_boolean force false 'force overwrite' f
+DEFINE_string output_dir "`pwd`" 'output dir' d
+DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o
+DEFINE_boolean dry_run false "supress logging to a file" n
+
+main()
+{
+ # determine output filename
+ output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}"
+ output=`shlib_relToAbsPath "${output}"`
+
+ # checks
+ [ -n "${FLAGS_suite:-}" ] || die 'suite flag missing'
+
+ if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} -a -f "${output}" ]; then
+ if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then
+ rm -f "${output}"
+ else
+ echo "not overwriting '${output}'" >&2
+ exit ${FLAGS_ERROR}
+ fi
+ fi
+ if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
+ touch "${output}" 2>/dev/null || die "unable to write to '${output}'"
+ fi
+
+ # run tests
+ (
+ cd "${SRC_DIR}";
+ if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
+ ./${FLAGS_suite} |tee "${output}"
+ else
+ ./${FLAGS_suite}
+ fi
+ )
+
+ if [ ! ${FLAGS_dry_run} ]; then
+ echo >&2
+ echo "output written to '${output}'" >&2
+ fi
+}
+
+FLAGS "$@" || exit $?
+[ ${FLAGS_help} -eq ${FALSE} ] || exit
+eval set -- "${FLAGS_ARGV}"
+main "$@"