File: errorcase.sh

package info (click to toggle)
cssc 1.0.1-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,612 kB
  • ctags: 1,424
  • sloc: cpp: 13,502; sh: 4,759; ansic: 2,971; perl: 342; makefile: 339; awk: 11
file content (206 lines) | stat: -rw-r--r-- 5,690 bytes parent folder | download | duplicates (3)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#! /bin/sh
# errorcase.sh:  Testing for the various error cases for "delta".

# Import common functions & definitions.
. ../common/test-common
. ../common/real-thing

remove command.log log log.stdout log.stderr
mkdir test 2>/dev/null

g=foo
s=s.$g
p=p.$g
z=z.$g
q=q.$g
d=d.$g
x=x.$g
files="$g $s $p $z ${g}_1 ${g}_2 $g $q $d $x $g.saved $g.old"

remove $files
test -d $x.bak && rmdir $x.bak

append() {
   f="$1"
   shift
   echo  "$@" >> "$f" || miscarry "Could not append a line to $1" 
}


createfile () {
    touch "$1" && test -r "$1" || miscarry "could not create file $1"
}

removedirs () {
    for d
    do
      if test -d "$d"
      then
	  rmdir "$d" || miscarry "Failed to remove directory $d"
      else 
	  if test -f "$d"
	  then
	      remove "$d"
          fi
      fi
    done
}


if wrong_group=`../../testutils/user foreigngroup`
then
    true
else
    miscarry "could not select the name of a group to which you do not belong"
fi
# echo "You do not belong to group number" $wrong_group


# Create the SCCS file - and make sure that delta can be made to work at all.
docommand E1 "${admin} -n $s" 0 IGNORE IGNORE 
docommand E2 "${get} -e $s"   0 IGNORE IGNORE 
append $g "test data"
docommand E3 "${delta} -yNoComment $s"   0 IGNORE IGNORE 

# Now set up the authorised groups list.   
docommand E4 "${admin} -a${wrong_group} $s" 0 IGNORE IGNORE

# cannot do get -e if you are not in the authorised user list.
docommand E5 "${get} -e $s"   1 IGNORE IGNORE 

# Momentarily zap the authorised user list so that "get -e" works.
docommand E6 "${admin} -e${wrong_group} $s" 0 IGNORE IGNORE
docommand E7 "${get} -e $s"   0 IGNORE IGNORE
docommand E8 "${admin} -a${wrong_group} $s" 0 IGNORE IGNORE

append $g "more test data"

# delta should still fail if we are not in the authorised user list
# (in other words the list is checked both by get -e and delta).
docommand E9 "${delta} -yNoComment $s"   1 IGNORE IGNORE

# Remove the authorised group list; check-in should now work
docommand E10 "${admin} -e${wrong_group} $s" 0 IGNORE IGNORE
docommand E11 "${delta} -yNoComment $s"   0 IGNORE IGNORE 


# Now, what if the authorised user list just excludes?
remove $s
if mygroup=`../../testutils/user group`
then
    true
else
    miscarry "could not determine group-id"
fi

if myname=`../../testutils/user name`
then
    true
else
    miscarry "could not determine user name"
fi

# Regular SCCS does not underatand the use of "!username" 
# to specifically exclude users.  Hence for compatibility 
# nor must we.
docommand E12 "${admin} -n $s"              0 IGNORE IGNORE 
docommand E13 "${admin} -a${mygroup} $s"    0 IGNORE IGNORE
docommand E14 "${admin} -a\!${myname} $s"   0 IGNORE IGNORE
docommand E15 "${get} -e $s"                0 IGNORE IGNORE
# this means that the above tests should succeed.

# Check - use of delta when a q-file already exists...
createfile $q
docommand E16 "${delta} -yNoComment $s" 1 IGNORE IGNORE
remove $q

# Unreadable g-file should also cause a failure. 
chmod 0 $g
docommand E17 "${delta} -yNoComment $s" 1 IGNORE IGNORE
chmod +r $g
docommand E18 "${delta} -yNoComment $s" 0 IGNORE IGNORE


# Failure to create the d-file should NOT cause a failure. 
docommand E19 "${get} -e $s"                0 IGNORE IGNORE
remove $x
createfile $d
docommand E20 "${delta} -yNoComment $s" 0 IGNORE IGNORE

# This should not leave any other temporary file lying about
# but it should also not delete the s-file
docommand E22 "test -r $x" 1 "" ""
docommand E23 "test -r $q" 1 "" ""

# The d-file would have been deleted (without causing an error) in E20.
# Since there was no error the g-file should no longer be there either.
docommand E24 "test -r $d" 1 "" ""
docommand E25 "test -r $s" 0 "" "" 
docommand E26 "test -w $g" 1 "" "" 

# Since E20 was successful, no need to do the delta again
#remove $d
#docommand E27 "${delta} -yNoComment $s" 0 IGNORE IGNORE

# %A as the last two characters of the file to be checked in 
# should not cause the world to end. 
remove $s
if ${TESTING_CSSC}
then
    docommand E28 "${admin} -b -n $s" 0 IGNORE IGNORE 
    
    docommand E29 "${get} -e $s"                0 IGNORE IGNORE
    echo_nonl "%A" > $g
    cp $g $g.saved || miscarry "could not back up $g"
    docommand E30 "${delta} -yNoComment $s" 0 IGNORE IGNORE
    docommand E31 "${get} -k $s"                0 IGNORE IGNORE
    
    echo_nonl E32...
    if diff $g.saved $g 
    then
        echo passed
    else
        fail "E32: Expcected to get the same contents back, did we did not" 
    fi
    remove $g


    # Now tests for not being able to rename an existing x-file.  This 
    # is not an error - we just overwrite the original x-file as 
    # SCCS does, rather than backing it up. 
    # This test is specific to CSSC because SCCS doesn't rename the x-file...
    mkdir $x.bak
    createfile $x
    docommand E33 "${get} -e $s"                0 IGNORE IGNORE
    docommand E34 "${delta} -yNoComment $s"     0 IGNORE IGNORE
    removedirs $x.bak

else
    echo "(Some tests skipped - we are not sure if ${admin} has binary file support)"
fi 
remove $s


# Test for the case where the p-file lists a SID which is not in the 
# SCCS file. 

# Create deltas 1.1 and 1.2
docommand E35 "${admin} -n $s"     0 IGNORE IGNORE
docommand E36 "${get} -e $s"       0 IGNORE IGNORE
docommand E37 "${delta} -yNoComment $s" 0 IGNORE IGNORE

# Edit delta 1.2 and then remove delta 1.2
docommand E38 "${get} -e $s"       0 IGNORE IGNORE
rename $p saved.$p
docommand E39 "${rmdel} -r1.2 $s" 0 IGNORE IGNORE
rename saved.$p $p

# Try to check in the file - this should fail. 
docommand E40 "${delta} -yNoComment $s" 1 "" IGNORE
remove $p

remove $files


success