summaryrefslogtreecommitdiff
path: root/tests/find/printf_escapechars.sh
blob: 8d6dcebe7d2fd6532419286f7a7f603d8698b259 (plain)
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
#!/bin/sh
# Test -printf with octal and letter escapes.

# Copyright (C) 2011-2021 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

. "${srcdir=.}/tests/init.sh"; fu_path_prepend_
print_ver_ find oldfind

# Check for working od(1).
echo test | od -c >/dev/null \
  || skip_ "no working 'od -c' found"

# Create file with expected output interpreted as octal; use:
#   $ printf '%s'   \
#       $'OCTAL1: \1\n' \
#       $'OCTAL2: \02\n' \
#       $'OCTAL3: \003\n' \
#       $'OCTAL4: \0044\n' \
#       $'OCTAL8: \0028\n' \
#       $'BEL: \a\n' \
#       $'CR: \r\n' \
#       $'FF: \f\n' \
#       $'TAB: \t\n' \
#       $'VTAB: \v\n' \
#       $'BS: \b\n' \
#       $'BACKSLASH: \\\n' \
#       $'UNKNOWN: \z\n' \
#       | od -t o1
cat <<_EOD_ > expout || framework_failure_
0000000 117 103 124 101 114 061 072 040 001 012 117 103 124 101 114 062
0000020 072 040 002 012 117 103 124 101 114 063 072 040 003 012 117 103
0000040 124 101 114 064 072 040 004 064 012 117 103 124 101 114 070 072
0000060 040 002 070 012 102 105 114 072 040 007 012 103 122 072 040 015
0000100 012 106 106 072 040 014 012 124 101 102 072 040 011 012 126 124
0000120 101 102 072 040 013 012 102 123 072 040 010 012 102 101 103 113
0000140 123 114 101 123 110 072 040 134 012 125 116 113 116 117 127 116
0000160 072 040 134 172 012
0000165
_EOD_

# Prepare expected stderr.
echo "warning: unrecognized escape" > experr || framework_failure_

for executable in oldfind find; do
  rm -f out* err* || framework_failure_

  $executable . -maxdepth 0 \
    -printf 'OCTAL1: \1\n' \
    -printf 'OCTAL2: \02\n' \
    -printf 'OCTAL3: \003\n' \
    -printf 'OCTAL4: \0044\n' \
    -printf 'OCTAL8: \0028\n' \
    -printf 'BEL: \a\n' \
    -printf 'CR: \r\n' \
    -printf 'FF: \f\n' \
    -printf 'TAB: \t\n' \
    -printf 'VTAB: \v\n' \
    -printf 'BS: \b\n' \
    -printf 'BACKSLASH: \\\n' \
    -printf 'UNKNOWN: \z\n' \
    > out 2> err || fail=1

  # Some 'od' implementations (e.g. on the *BSDs) produce different indentation
  # and trailing spaces, therefore squeeze the former and remove the latter.
  od -t o1 < out | sed 's/  */ /g; s/ *$//;' > out2 || framework_failure_
  compare expout out2 || fail=1

  sed 's/^.*\(warning: unrecognized escape\) .*$/\1/' err > err2 \
    || framework_failure_
  compare experr err2 || fail=1
done

Exit $fail