~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to tests/split/l-chunk

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
# test splitting into newline delineated chunks (-n l/...)
3
 
 
4
 
# Copyright (C) 2010-2011 Free Software Foundation, Inc.
5
 
 
6
 
# This program is free software: you can redistribute it and/or modify
7
 
# it under the terms of the GNU General Public License as published by
8
 
# the Free Software Foundation, either version 3 of the License, or
9
 
# (at your option) any later version.
10
 
 
11
 
# This program is distributed in the hope that it will be useful,
12
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
# GNU General Public License for more details.
15
 
 
16
 
# You should have received a copy of the GNU General Public License
17
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 
19
 
. "${srcdir=.}/init.sh"; path_prepend_ ../src
20
 
print_ver_ split
21
 
 
22
 
# invalid number of chunks
23
 
echo 'split: 1o: invalid number of chunks' > exp
24
 
split -n l/1o 2>err && fail=1
25
 
compare err exp || fail=1
26
 
 
27
 
echo "split: \`-': cannot determine file size" > exp
28
 
echo | split -n l/1 2>err && fail=1
29
 
compare err exp || fail=1
30
 
 
31
 
# N can be greater than the file size
32
 
# in which case no data is extracted, or empty files are written
33
 
split -n l/10 /dev/null || fail=1
34
 
test "$(stat -c %s x* | uniq -c | sed 's/^ *//; s/ /x/')" = "10x0" || fail=1
35
 
rm x??
36
 
 
37
 
# Ensure the correct number of files written
38
 
# even if there is more data than the reported file size
39
 
split -n l/2 /dev/zero
40
 
test "$(stat -c %s x* | wc -l)" = '2' || fail=1
41
 
rm x??
42
 
 
43
 
# Ensure --elide-empty-files is honored
44
 
split -e -n l/10 /dev/null || fail=1
45
 
stat x?? 2>/dev/null && fail=1
46
 
 
47
 
# 80 bytes. ~ transformed to \n below
48
 
lines=\
49
 
12345~1~12345~1~12345~1~12345~1~12345~~~12345~1~12345~1~12345~1~12345~1~12345~1~
50
 
 
51
 
printf "%s" "$lines" | tr '~' '\n' > in || framework_failure_
52
 
 
53
 
echo 'split: 16: invalid chunk number' > exp
54
 
split -n l/16/15 in 2>err && fail=1
55
 
compare err exp || fail=1
56
 
 
57
 
printf '%s' "\
58
 
14 16 09 15 16 10
59
 
14 08 08 10 14 08 08 10
60
 
06 08 08 02 06 08 08 02 06 08 08 10
61
 
06 08 02 06 08 00 08 02 06 08 02 06 08 00 10
62
 
06 00 08 00 02 06 00 02 06 00 08 00 01 07 00 02 06 00 08 00 02 16
63
 
" > exp || framework_failure_
64
 
 
65
 
sed 's/00 *//g' exp > exp.elide_empty || framework_failure_
66
 
 
67
 
DEBUGGING=
68
 
test "$DEBUGGING" && test "$VERBOSE" && set +x
69
 
for ELIDE_EMPTY in '' '-e'; do
70
 
  for IO_BLKSIZE in 1 2 5 10 80 100; do
71
 
    : > out
72
 
    test "$DEBUGGING" && printf "\n---io-blk-size=$IO_BLKSIZE $ELIDE_EMPTY\n"
73
 
    for N in 6 8 12 15 22; do
74
 
      rm -f x*
75
 
 
76
 
      if test -z "$ELIDE_EMPTY"; then
77
 
        split ---io-blksize=$IO_BLKSIZE -n l/2/$N in > chunk.k
78
 
        stat x* 2>/dev/null && fail=1
79
 
      fi
80
 
 
81
 
      split ---io-blksize=$IO_BLKSIZE $ELIDE_EMPTY -n l/$N in
82
 
      echo $(stat -c "%02s" x*) >> out
83
 
 
84
 
      if test -z "$ELIDE_EMPTY"; then
85
 
        compare chunk.k xab || fail=1
86
 
      fi
87
 
 
88
 
      if test "$DEBUGGING"; then
89
 
        # Output partition pattern
90
 
        size=$(printf "%s" "$lines" | wc -c)
91
 
        chunk_size=$(($size/$N))
92
 
        end_size=$(($chunk_size + ($size % $N)))
93
 
        {
94
 
          yes "$(printf %${chunk_size}s ])" | head -n$(($N-1))
95
 
          printf %${end_size}s ]
96
 
        } | tr -d '\n' | sed "s/\\(^.\\{1,$size\\}\\).*/\\1/"
97
 
        echo
98
 
 
99
 
        # Output pattern generated for comparison
100
 
        for s in $(stat -c "%s" x*); do
101
 
          #s=0 transitions are not shown
102
 
          test "$m" = "_" && m=- || m=_
103
 
          printf "%${s}s" '' | tr ' ' $m
104
 
        done
105
 
        echo
106
 
 
107
 
        # Output lines for reference
108
 
        echo "$lines"
109
 
      fi
110
 
    done
111
 
    test -z "$ELIDE_EMPTY" && EXP=exp || EXP=exp.elide_empty
112
 
    compare out $EXP || fail=1
113
 
  done
114
 
done
115
 
test "$DEBUGGING" && test "$VERBOSE" && set -x
116
 
 
117
 
 
118
 
# Check extraction of particular chunks
119
 
: > out
120
 
printf '1\n12345\n' > exp
121
 
split -n l/13/15 in > out
122
 
compare out exp || fail=1
123
 
: > out
124
 
printf '' > exp
125
 
split -n l/14/15 in > out
126
 
compare out exp || fail=1
127
 
: > out
128
 
printf '1\n12345\n1\n' > exp
129
 
split -n l/15/15 in > out
130
 
compare out exp || fail=1
131
 
 
132
 
# test input with no \n at end
133
 
printf '12\n34\n5' > in
134
 
printf '5' > exp
135
 
split -n l/7/7 in > out
136
 
compare out exp || fail=1
137
 
 
138
 
Exit $fail