#!/bin/bash ffoo import core ffoo import tmp FFOO_TESTING_ARTIFACTS=${FFOO_TESTING_ARTIFACTS:-+artifacts-%Y%m%d-%H%M%S} assert_linecount() { # # Assert that count of lines in stdin is $1 # local ex num ex="$@" case $ex in [0-9]*) ex="-eq $ex" ;; -*) true ;; *) usage_is "FILE EXPR|NUM" ;; esac num=$(wc -l) test 0$num $ex } collect_artifacts() { # # Collect everything that is registered as artifact # # Usage: collect_artifacts [-s symlink] [[+]target] # # If *target* starts with plus sign, the value is first # passed to `date` utility and output is replaced. If # *target* is not given, `$FFOO_TESTING_ARTIFACTS`, or # a hard-coded value `+artifacts-%Y%m%d-%H%M%S` is used. # # If *symlink* is provided, symbolic link to current # artifact collection will be created at that path. If the # link already exists, it's removed first. This enables # easier access to "last artifacts". # local alink aroot while true; do case "$1" in -s|--symlink) alink="$2"; shift 2;; *) aroot="$1"; break;; esac done aroot=${aroot:-$FFOO_TESTING_ARTIFACTS} test "${aroot:0:1}" == "+" && aroot="$(date "$aroot")" debug -v aroot test -e $aroot && warn "target exists, not collecting anything: $aroot" && return 1 test -f $FFOO_TMP/artifact_list || return 0 local tgt think "collecting artifacts to $aroot" cat $FFOO_TMP/artifact_list \ | while read path; do tgt=$aroot/$(dirname $path) mkdir -p $tgt debug -v path tgt cp -r "$path" "$tgt" done if test -n "$alink"; then if test -x "$alink" && ! test -L "$alink"; then warn "path exists but is not a symlink; not touching: $alink" return fi rm -f "$alink"; ln -sr "$aroot" "$alink" fi } register_artifact() { # # Register artifact path for later collection # local list=$FFOO_TMP/artifact_list debug -v list local a for a in "$@"; do local dn=$(cd $(dirname $a); pwd) test "$dn" = "/" && dn="" # hack: avoid "//" if path was abs local abspath="$dn/$(basename $a)" debug -v dn abspath think "registering artifact $abspath" append_if_missing "$abspath" $list done }