Skip to content
pi-c Artifact [5dccb18ad8]
Login

Artifact [5dccb18ad8]

Artifact 5dccb18ad8028d6c88c6d1d538a827ed6c01b72e69f3a74af92c222b67a285f3:


#!/bin/sh
# Usage: run-logged.sh LOGDIR NAME [VAR=value ...] COMMAND [ARGS...]
# Runs the command with its output in LOGDIR/NAME.log. Prints one line with
# the result and the time taken; prints the whole log only when it fails, so
# parallel jobs keep their output apart. Exits with the command's status.
# PIC_TEST_PRIVATE_HOME: a pic the command runs with HOME left at the account's own home directory
# refuses to start, so no test reaches the real ~/.pic.
dir=$1
name=$2
shift 2
mkdir -p "$dir"
log=$dir/$name.log
start=$(date +%s)
env PIC_TEST_PRIVATE_HOME=1 "$@" > "$log" 2>&1
rc=$?
secs=$(($(date +%s) - start))
if [ "$rc" = 0 ]; then
    printf 'ok   %-16s %3ss\n' "$name" "$secs"
else
    printf 'FAIL %-16s %3ss (exit %s), log %s:\n' "$name" "$secs" "$rc" "$log"
    cat "$log"
    # The forge shows a log's end: repeat what failed there.
    grep -E '^(FAIL|not ok)' "$log" | tail -5 | sed "s/^/$name: /"
fi
exit "$rc"