-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtap-shell-tap.sh
87 lines (79 loc) · 2.24 KB
/
tap-shell-tap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# small library which can generate tap comaptible files
# If you want to stream as you run, you will need to fale header total infomration
# start your output or each sub suite with `tapHeader total meta1 meta2 .. metaN` call. only totla is mandatory
# print individual tests with `tapTestStart ok/not ok, numerical id and title` (three) params
# print details by `tapLine id content`
# or by `tapFromFile id alias` where each file is head/grep/tail or message that it do nto exists is printed (alilas is wildchar or human readabel explanation of file)
# close each test by `tapTestEnd`
## First mandatroy argument is number of tests
## all others are strings, written in as header metadata
function tapHeader() {
local counter=0
for var in "$@" ; do
let counter=$counter+1
if [ $counter -eq 1 ] ; then
echo "1..$var"
else
echo "# $var"
fi
done
}
function tapTestStart() {
local ok="$1"
local id="$2"
local title="$3"
if [ "$ok" == "ok" ] ; then
echo "ok $id - $title"
else
echo "not ok $id - $title"
fi
echo " ---"
}
function tapTestEnd() {
echo " ..."
}
function tapLine() {
local id="$1"
local line="$2"
echo " $id: $line"
}
function tapFromFile() {
local file="$1"
local alilas="$2"
if [ ! -e "$file" ]; then
tapLine "$file/$alilas" "do not exists"
else
echo " head $file/$alilas:"
echo " |"
head "$file" -n 10 | while IFS= read -r line; do
line=`echo $line | sed 's/^\s*\|\s*$//g'`
echo " $line"
done
echo " grep $file/$alilas:"
echo " |"
grep -n -i -e fail -e error -e "not ok" -B 0 -A 0 $file| while IFS= read -r line; do
line=`echo $line | sed 's/^\s*\|\s*$//g'`
echo " $line"
done
echo " tail $file/$alilas:"
echo " |"
tail "$file" -n 10 | while IFS= read -r line; do
line=`echo $line | sed 's/^\s*\|\s*$//g'`
echo " $line"
done
fi
}
function tapFromWholeFile() {
local file="$1"
local alilas="$2"
if [ ! -e "$file" ]; then
tapLine "$file/$alilas" "do not exists"
else
echo " cat $file/$alilas:"
echo " |"
cat $file| while IFS= read -r line; do
line=`echo $line | sed 's/^\s*\|\s*$//g'`
echo " $line"
done
fi
}