File: string-test

package info (click to toggle)
autogen 5.3.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,216 kB
  • ctags: 2,706
  • sloc: ansic: 17,527; sh: 11,794; awk: 629; makefile: 556; lisp: 164; yacc: 50
file content (133 lines) | stat: -rwxr-xr-x 4,046 bytes parent folder | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! /bin/sh
#  -*- Mode: Sh -*- 
# ----------------------------------------------------------------------
# string-test --- %s specifier
#
# Author:	      Gary V. Vaughan <gvv@techie.com>
# Maintainer:	      Gary V. Vaughan <gvv@techie.com>
# Created:	      Thu Nov 26 15:50:31 1998
# Last Modified:      Wed Jul 14 15:05:41 1999				      
#            by:      Gary V. Vaughan <gvv@techie.com>		      
# ----------------------------------------------------------------------
# @(#) $Id: string-test,v 1.3 2000/07/27 15:46:01 bkorb Exp $
# ----------------------------------------------------------------------
# Copyright (C) 1998, 1999 Gary V. Vaughan
#
# 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 2 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; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that also links with and
# uses the libopts library from AutoGen, you may include it under
# the same distribution terms used by the libopts library.

# Code:

# Common definitions
if test -z "$srcdir"; then
    srcdir=`echo "$0" | sed 's,[^/]*$,,'`
    test "$srcdir" = "$0" && srcdir=.
    test -z "$srcdir" && srcdir=.
    test "${VERBOSE+set}" != set && VERBOSE=1
fi
. $srcdir/defs


# this is the output we should expect to see
cat <<\EOF >ok
1 string
*** printfv returned 8 chars.
2 startstringend
*** printfv returned 16 chars.
3 string
*** printfv returned 8 chars.
4     string
*** printfv returned 12 chars.
5 strin
*** printfv returned 7 chars.
6 string
*** printfv returned 8 chars.
7 string
*** printfv returned 8 chars.
8 0000string
*** printfv returned 12 chars.
9 strin
*** printfv returned 7 chars.
10 string
*** printfv returned 9 chars.
11 string
*** printfv returned 9 chars.
12 string    
*** printfv returned 13 chars.
13 start0000strinend
*** printfv returned 20 chars.
14 startstrin    end
*** printfv returned 20 chars.
EOF

cat <<\EOF >errok
EOF

# straightforward string output
$SNPRINTFV '1 %s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '2 start%send' \"string\" 2> err | tee -ai out >&2

# test width flag
$SNPRINTFV '3 %5s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '4 %10s' \"string\" 2> err | tee -ai out >&2

# test precision flag
$SNPRINTFV '5 %.5s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '6 %.10s' \"string\" 2> err | tee -ai out >&2

# test zero padding
$SNPRINTFV '7 %05s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '8 %010s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '9 %0.5s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '10 %0.10s' \"string\" 2> err | tee -ai out >&2

# test left justfy flag
$SNPRINTFV '11 %-5s' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '12 %-10s' \"string\" 2> err | tee -ai out >&2

# try a bizarre combination
$SNPRINTFV '13 start%09.5send' \"string\" 2> err | tee -ai out >&2
$SNPRINTFV '14 start%-09.5send' \"string\" 2> err | tee -ai out >&2

# Test against expected output
if ${CMP} -s out ok; then
    :
else
    echo "ok:" >&2
    cat ok >&2
    exit 1
fi

# Munge error output to remove leading directories, `lt-' or trailing `.exe'
sed -e "s,^[^:]*[lt-]*snprintfv-test[.ex]*:,snprintfv-test:," err >sederr \
    && mv sederr err

# Show stderr if doesn't match expected output if VERBOSE == 1
if "$CMP" -s err errok; then
    :
else
    echo "err:" >&2
    cat err >&2
    echo "errok:" >&2
    cat errok >&2
    exit 1
fi

# string-test ends here