source: zzuf/trunk/test/functions.inc @ 4253

Last change on this file since 4253 was 4253, checked in by sam, 5 years ago

Fix copyright information and remove Id tag everywhere.

File size: 1.7 KB
Line 
1# Source this file in shell scripts:
2# . "$(dirname "$0")/functions.inc"
3#
4#  functions.inc - utility functions for shell-based test scripts
5#  Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
6#                All Rights Reserved
7#
8#  This program is free software. It comes without any warranty, to
9#  the extent permitted by applicable law. You can redistribute it
10#  and/or modify it under the terms of the Do What The Fuck You Want
11#  To Public License, Version 2, as published by Sam Hocevar. See
12#  http://sam.zoy.org/wtfpl/COPYING for more details.
13#
14
15DIR="$(dirname "$0")"
16ZZUF="$DIR/../src/zzuf -E '[.]ilist$'"
17
18ZZCAT="$DIR/../src/zzcat"
19if [ ! -f "$ZZCAT" ]; then
20  echo "error: src/zzcat is missing"
21  exit 1
22fi
23
24ZZERO="$DIR/zzero"
25if [ ! -f "$ZZERO" ]; then
26  echo "error: test/zzero is missing"
27  exit 1
28fi
29
30if file /bin/cat | grep 'statically linked' >/dev/null 2>&1; then
31  STATIC_CAT=1
32fi
33if file /bin/dd | grep 'statically linked' >/dev/null 2>&1; then
34  STATIC_DD=1
35fi
36if tail -n 1 /dev/null >/dev/null 2>&1; then
37  TAILN="tail -n "
38  TAILP="tail -n +"
39else
40  TAILN="tail -"
41  TAILP="tail +"
42fi
43
44FAILED=0
45TESTED=0
46
47if [ -z "$1" ]; then
48  seed=$(date | $ZZUF -m 2>/dev/null | cut -f2 -d' ' | tr -d abcdef | cut -b1-8)
49else
50  seed="$1"
51fi
52
53start_test() {
54    echo ""
55    echo "*** running $1 with seed $seed ***"
56}
57
58new_test() {
59    echo "*** $1 *** "
60}
61
62pass_test() {
63    TESTED="$(($TESTED + 1))"
64    echo "$1"
65}
66
67fail_test() {
68    TESTED="$(($TESTED + 1))"
69    FAILED="$(($FAILED + 1))"
70    echo "$1"
71}
72
73stop_test() {
74    if [ "$FAILED" != 0 ]; then
75        echo "*** $FAILED tests failed out of $TESTED ***"
76        exit 1
77    fi
78    echo "*** all $TESTED tests OK ***"
79    echo ""
80}
81
Note: See TracBrowser for help on using the repository browser.