~nabijaczleweli/voreutils

ref: cb91cf21c628ab3d5e42d89694d99fcca6c8efc8 voreutils/tests/tac/test -rwxr-xr-x 6.0 KiB
cb91cf21наб Add uname (and arch). Centralise spaced print a month ago
                                                                                
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/sh
# SPDX-License-Identifier: 0BSD

# GNU coreutils ship their own regexes(!), which recognise \s but don't [[:space:]]
# Conversely, regcomp(3) universally recognises [[:space:]], but not always \s (glibc does, Berkeley libcs don't)
# For ease of testing (and regeneration), pat= is set to [[:space:]] if it's \s: if retesting against GNU tac or regenerating, comment out those lines

IFS="
"

tmpdir="$(mktemp -dt "tac.XXXXXXXXXX")/"
tac="${CMDDIR}tac"
# tac="tac"
data="$(readlink -f data)/"
files="$(for f in "$data"*; do [ -f "$f" ] && echo "${f##*/}"; done)"

mkdir "${tmpdir}singlef/"
for f in $files; do
	cp "$data$f" "${tmpdir}singlef/"
done
cp -r "${tmpdir}singlef/" "${tmpdir}withnull/"
cp -r "${tmpdir}singlef/" "${tmpdir}with-/"
cp -r "${tmpdir}singlef/" "${tmpdir}just-/"
cp -r "${tmpdir}singlef/" "${tmpdir}nothing/"

cd "${tmpdir}singlef/" && for f in $files; do
  mkdir "$f.d"
  "$tac"     "$f" > "$f.d/$f"    2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
  "$tac" -b  "$f" > "$f.d/$f-b"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
  "$tac" -r  "$f" > "$f.d/$f-r"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
  "$tac" -br "$f" > "$f.d/$f-br" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  for s in '' ' ' '  ' 'a ' ' ' '\s' '.' '..' 'a $'; do
    pat="$s"
    [ "$pat" = '\s' ] && pat='[[:space:]]'
    "$tac" -s   "$pat" "$f" > "$f.d/$f-s'$s'"   2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
    "$tac" -bs  "$pat" "$f" > "$f.d/$f-bs'$s'"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
    "$tac" -rs  "$pat" "$f" > "$f.d/$f-rs'$s'"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
    "$tac" -brs "$pat" "$f" > "$f.d/$f-brs'$s'" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  done
done
wait
diff -r -u "$data" "${tmpdir}singlef/" >&3 2>&1 && echo "Single-file ok"

cd "${tmpdir}withnull/" && for f in $files; do
  mkdir "$f.d"
  "$tac"     /dev/null "$f" /dev/null > "$f.d/$f"    2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
  "$tac" -b  /dev/null "$f" /dev/null > "$f.d/$f-b"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
  "$tac" -r  /dev/null "$f" /dev/null > "$f.d/$f-r"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
  "$tac" -br /dev/null "$f" /dev/null > "$f.d/$f-br" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  for s in '' ' ' '  ' 'a ' ' ' '\s' '.' '..' 'a $'; do
    pat="$s"
    [ "$pat" = '\s' ] && pat='[[:space:]]'
    "$tac" -s   "$pat" /dev/null "$f" /dev/null > "$f.d/$f-s'$s'"   2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
    "$tac" -bs  "$pat" /dev/null "$f" /dev/null > "$f.d/$f-bs'$s'"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
    "$tac" -rs  "$pat" /dev/null "$f" /dev/null > "$f.d/$f-rs'$s'"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
    "$tac" -brs "$pat" /dev/null "$f" /dev/null > "$f.d/$f-brs'$s'" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  done
done
wait
diff -r -u "$data" "${tmpdir}withnull/" >&3 2>&1 && echo "Interposed null ok"

cd "${tmpdir}with-/" && for f in $files; do
  mkdir "$f.d"
  printf "" | "$tac"     - "$f" - > "$f.d/$f"    2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
  printf "" | "$tac" -b  - "$f" - > "$f.d/$f-b"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
  printf "" | "$tac" -r  - "$f" - > "$f.d/$f-r"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
  printf "" | "$tac" -br - "$f" - > "$f.d/$f-br" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  for s in '' ' ' '  ' 'a ' ' ' '\s' '.' '..' 'a $'; do
    pat="$s"
    [ "$pat" = '\s' ] && pat='[[:space:]]'
    printf "" | "$tac" -s   "$pat" - "$f" - > "$f.d/$f-s'$s'"   2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
    printf "" | "$tac" -bs  "$pat" - "$f" - > "$f.d/$f-bs'$s'"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
    printf "" | "$tac" -rs  "$pat" - "$f" - > "$f.d/$f-rs'$s'"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
    printf "" | "$tac" -brs "$pat" - "$f" - > "$f.d/$f-brs'$s'" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  done
done
wait
diff -r -u "$data" "${tmpdir}with-/" >&3 2>&1 && echo "Interposed - ok"

cd "${tmpdir}just-/" && for f in $files; do
  mkdir "$f.d"
  "$tac"     - < "$f" > "$f.d/$f"    2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
  "$tac" -b  - < "$f" > "$f.d/$f-b"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
  "$tac" -r  - < "$f" > "$f.d/$f-r"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
  "$tac" -br - < "$f" > "$f.d/$f-br" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  for s in '' ' ' '  ' 'a ' ' ' '\s' '.' '..' 'a $'; do
    pat="$s"
    [ "$pat" = '\s' ] && pat='[[:space:]]'
    "$tac" -s   "$pat" - < "$f" > "$f.d/$f-s'$s'"   2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
    "$tac" -bs  "$pat" - < "$f" > "$f.d/$f-bs'$s'"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
    "$tac" -rs  "$pat" - < "$f" > "$f.d/$f-rs'$s'"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
    "$tac" -brs "$pat" - < "$f" > "$f.d/$f-brs'$s'" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  done
done
wait
diff -r -u "$data" "${tmpdir}just-/" >&3 2>&1 && echo "stdin ok"

cd "${tmpdir}nothing/" && for f in $files; do
  mkdir "$f.d"
  "$tac"     < "$f" > "$f.d/$f"    2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
  "$tac" -b  < "$f" > "$f.d/$f-b"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
  "$tac" -r  < "$f" > "$f.d/$f-r"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
  "$tac" -br < "$f" > "$f.d/$f-br" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  for s in '' ' ' '  ' 'a ' ' ' '\s' '.' '..' 'a $'; do
    pat="$s"
    [ "$pat" = '\s' ] && pat='[[:space:]]'
    "$tac" -s   "$pat" < "$f" > "$f.d/$f-s'$s'"   2>/dev/null || echo yes > "$f.d/$f-s'$s'.error" &
    "$tac" -bs  "$pat" < "$f" > "$f.d/$f-bs'$s'"  2>/dev/null || echo yes > "$f.d/$f-bs'$s'.error" &
    "$tac" -rs  "$pat" < "$f" > "$f.d/$f-rs'$s'"  2>/dev/null || echo yes > "$f.d/$f-rs'$s'.error" &
    "$tac" -brs "$pat" < "$f" > "$f.d/$f-brs'$s'" 2>/dev/null || echo yes > "$f.d/$f-brs'$s'.error" &
  done
done
wait
diff -r -u "$data" "${tmpdir}nothing/" >&3 2>&1 && echo "Default ok"

rm -rf "$tmpdir" >&3