name=$1
shift
+# Detect a working time command
+if command time --quiet -f%e true 2>/dev/null; then
+ TIME="command time --quiet -f%e -o ${name}.t.out"
+elif command time -f%e true 2>/dev/null; then
+ TIME="command time -f%e -o ${name}.t.out"
+elif command gtime -f%e true 2>/dev/null; then
+ TIME="command gtime -f%e -o ${name}.t.out"
+else
+ TIME=
+fi
+
+# Detect a working date command
+if date -Iseconds >/dev/null 2>&1; then
+ TIMESTAMP="timestamp='`date -Iseconds`'"
+else
+ TIMESTAMP=
+fi
+
# Magic here! This tee and save both stdout and stderr in distinct files without messing with them
# Time just get the user time
-/usr/bin/time -f%U --quiet -o "${name}.t.out" "$@" > >(tee "${name}.out") 2> >(tee "${name}.2.out" >&2)
+$TIME "$@" > >(tee "${name}.out") 2> >(tee "${name}.2.out" >&2)
res=$?
c=`echo "${name%-*}" | tr "-" "."`
n=${name##*-}
+# Do we have a time result?
+if test -f "${name}.t.out"; then
+ T="time='`cat "${name}.t.out"`'"
+else
+ T=
+fi
+
cat > "${name}.xml"<<END
<testsuites><testsuite>
-<testcase classname='$c' name='$n' time='`cat "${name}.t.out"`' timestamp='`date -Iseconds`'>
+<testcase classname='$c' name='$n' $T $TIMESTAMP>
END
if test "$res" != "0"; then
echo >> "${name}.xml" "<error message='Command returned $res'/>"
echo "+ Command returned $res" >&2
fi
+if test -s "${name}.out"; then
cat >> "${name}.xml"<<END
<system-out><![CDATA[
`cat -v ${name}.out`
]]></system-out>
+END
+fi
+if test -s "${name}.2.out"; then
+cat >> "${name}.xml"<<END
<system-err><![CDATA[
`cat -v ${name}.2.out`
]]></system-err>
+END
+fi
+cat >> "${name}.xml"<<END
</testcase>
</testsuite></testsuites>
END
-rm "${name}.out" "${name}.2.out" "${name}.t.out"
+rm "${name}.out" "${name}.2.out" "${name}.t.out" 2> /dev/null || true