tests: ocaml: Test NBDKit.version () binding
[nbdkit.git] / tests / test-data-bad.sh
blob302f9e2506c1decf8b56f589ac4e0917fe83dbd9
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 skip_if_valgrind
44 bad ()
46 data="$1"
48 # This command is expected to fail.
49 if nbdkit -U - -fv -D data.AST=1 data "$data" --run true; then
50 echo "$0: data plugin was expected to fail on bad input: $data"
51 exit 1
55 # Invalid bytes, numbers and words.
56 bad '-1'
57 bad '-'
58 bad '256'
59 bad '0400'
60 bad '0x100'
61 bad '0xfff'
62 bad '0xffffffffffffffff'
63 bad '0xffffffffffffffffffffffffffffffff'
65 for prefix in le16 be16 le32 be32 le64 be64; do
66 bad "$prefix"
67 bad "$prefix:"
68 bad "$prefix:-1"
69 bad "$prefix:abc"
70 bad "$prefix:0xffffffffffffffffffffffffffffffff"
71 done
73 bad 'le16:0x10000'
74 bad 'be16:0x10000'
75 bad 'le32:0x100000000'
76 bad 'be32:0x100000000'
77 bad 'le64:0x10000000000000000'
78 bad 'be64:0x10000000000000000'
80 # Invalid barewords and symbols.
81 bad 'a'
82 bad 'x'
83 bad 'be'
84 bad 'le'
85 bad 'be1'
86 bad 'le3'
87 bad 'ยข'
88 #bad '0x' # should fail but does not XXX
89 bad '?'
90 bad '\'
91 bad '^'
92 bad '@'
93 bad '@+'
94 bad '@-'
95 bad '@^'
96 bad '<'
97 bad '<('
98 bad '$'
99 bad '*'
100 bad '['
101 bad ':'
102 bad ']'
104 # Invalid offsets.
105 bad '@-2'
106 bad '@2 @-3'
107 bad '@2 @-2 @-1'
108 bad '@1 @^2 @-3'
110 # Mismatched parentheses.
111 bad "("
112 bad ")"
113 bad "( ("
114 bad "( ( )"
115 bad ") ( )"
116 bad "( ) )"
118 # Invalid strings.
119 bad '"'
120 bad '"\'
121 bad '"\\'
122 bad '"\"'
123 bad '"\x"'
125 # Bad repeats.
126 bad '*0'
127 bad '*1'
128 bad '0*-1'
129 bad '0*'
130 bad '0*x'
131 bad '0**'
133 # Bad slices.
134 bad '0[2:]'
135 bad '0[:2]'
136 bad '[:]'
137 bad '[0:1]'
138 bad '"111"[4:]'
139 bad '"123"[4:]'
140 bad '"123"[1:0]'
142 # Bad files.
143 if [ ! -r /NOFILE ]; then
144 bad '</NOFILE'
147 # Unknown and out of scope assignments.
148 bad '\a'
149 bad '( 0 -> \a ) \a'
150 bad '\a ( 0 -> \a )'
151 bad '0 -> \a \b'
152 bad '0 -> \a \a \b'
153 bad '( 0 -> \a \a ) \a'
155 # Currently this should fail. \b subtitutes (0 -> \a) which only
156 # defines \a in the scope, not where it is used outside the scope.
157 # Should we make it work in future?
158 bad '(0 -> \a) -> \b \b \a'
160 # Unknown variable definition
161 unset unknownvar
162 bad '$unknownvar'