rust: prevent dead_code warning
[nbdkit.git] / tests / test-data-bad.sh
blob8432aa295a7336f3c533a29f6e999665a7c0572b
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2018-2021 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 # SUCH DAMAGE.
33 # Test bad input to the data plugin.
35 source ./functions.sh
36 set -e
37 set -x
39 requires_run
41 # Since this test is expected to fail, valgrind will also fail.
42 if [ "$NBDKIT_VALGRIND" = "1" ]; then
43 echo "$0: skipping test under valgrind."
44 exit 77
47 bad ()
49 data="$1"
51 # This command is expected to fail.
52 if nbdkit -U - -fv -D data.AST=1 data "$data" --run true; then
53 echo "$0: data plugin was expected to fail on bad input: $data"
54 exit 1
58 # Invalid bytes, numbers and words.
59 bad '-1'
60 bad '-'
61 bad '256'
62 bad '0400'
63 bad '0x100'
64 bad '0xfff'
65 bad '0xffffffffffffffff'
66 bad '0xffffffffffffffffffffffffffffffff'
68 for prefix in le16 be16 le32 be32 le64 be64; do
69 bad "$prefix"
70 bad "$prefix:"
71 bad "$prefix:-1"
72 bad "$prefix:abc"
73 bad "$prefix:0xffffffffffffffffffffffffffffffff"
74 done
76 bad 'le16:0x10000'
77 bad 'be16:0x10000'
78 bad 'le32:0x100000000'
79 bad 'be32:0x100000000'
80 bad 'le64:0x10000000000000000'
81 bad 'be64:0x10000000000000000'
83 # Invalid barewords and symbols.
84 bad 'a'
85 bad 'x'
86 bad 'be'
87 bad 'le'
88 bad 'be1'
89 bad 'le3'
90 bad 'ยข'
91 #bad '0x' # should fail but does not XXX
92 bad '?'
93 bad '\'
94 bad '^'
95 bad '@'
96 bad '@+'
97 bad '@-'
98 bad '@^'
99 bad '<'
100 bad '<('
101 bad '$'
102 bad '*'
103 bad '['
104 bad ':'
105 bad ']'
107 # Invalid offsets.
108 bad '@-2'
109 bad '@2 @-3'
110 bad '@2 @-2 @-1'
111 bad '@1 @^2 @-3'
113 # Mismatched parentheses.
114 bad "("
115 bad ")"
116 bad "( ("
117 bad "( ( )"
118 bad ") ( )"
119 bad "( ) )"
121 # Invalid strings.
122 bad '"'
123 bad '"\'
124 bad '"\\'
125 bad '"\"'
126 bad '"\x"'
128 # Bad repeats.
129 bad '*0'
130 bad '*1'
131 bad '0*-1'
132 bad '0*'
133 bad '0*x'
134 bad '0**'
136 # Bad slices.
137 bad '0[2:]'
138 bad '0[:2]'
139 bad '[:]'
140 bad '[0:1]'
141 bad '"111"[4:]'
142 bad '"123"[4:]'
143 bad '"123"[1:0]'
145 # Bad files.
146 if [ ! -r /NOFILE ]; then
147 bad '</NOFILE'
150 # Unknown and out of scope assignments.
151 bad '\a'
152 bad '( 0 -> \a ) \a'
153 bad '\a ( 0 -> \a )'
154 bad '0 -> \a \b'
155 bad '0 -> \a \a \b'
156 bad '( 0 -> \a \a ) \a'
158 # Currently this should fail. \b subtitutes (0 -> \a) which only
159 # defines \a in the scope, not where it is used outside the scope.
160 # Should we make it work in future?
161 bad '(0 -> \a) -> \b \b \a'
163 # Unknown variable definition
164 unset unknownvar
165 bad '$unknownvar'