tests: ocaml: Test NBDKit.version () binding
[nbdkit.git] / tests / test-debug-flags.sh
blobe249fb3d780254b0b627ee54ccbd27a6707ade1d
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2018 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 nbdkit -D option.
35 source ./functions.sh
36 set -x
38 requires_plugin example2
39 requires_run
40 requires_nbdinfo
41 requires test -f disk
43 export LANG=C
45 files=debug-flags.out
46 rm -f $files
47 cleanup_fn rm -f $files
49 # This should work and show the "extra debugging" line in debug output.
50 nbdkit -U - -f -v -D example2.extra=1 example2 file=disk \
51 --run 'nbdinfo "$uri"' 2>debug-flags.out
52 cat debug-flags.out
53 if ! grep -sq 'extra debugging:' debug-flags.out ; then
54 echo "$0: expected to see extra debugging output"
55 exit 1
58 # Now test various expected failures.
60 expected_failure ()
62 echo "expected previous nbdkit command to fail, but it did not"
63 exit 1
66 check_error ()
68 cat debug-flags.out
69 if ! grep -sq "$1" debug-flags.out; then
70 echo "$0: expected error message not present in above output: '$1'"
71 exit 1
75 check_warning ()
77 cat debug-flags.out
78 if ! grep -sq "warning.*$1" debug-flags.out; then
79 echo "$0: expected warning message not present in above output: '$1'"
80 exit 1
84 # This is expected to fail because we didn't set the file= parameter,
85 # but it should not fail because of the debug flag.
86 nbdkit -U - -f -D example2.extra=1 example2 2>debug-flags.out && expected_failure
87 check_error "you must supply the file="
89 # This should fail because we didn't set the file= parameter, but it
90 # should also print a warning about the unknown -D flag.
91 nbdkit -U - -f -D example2.unknown=1 example2 2>debug-flags.out && expected_failure
92 check_error "you must supply the file="
93 check_warning "does not contain a global variable called example2_debug_unknown"
95 # This should fail because we didn't set the file= parameter, but it
96 # should also print a warning because the -D flag is unused.
97 nbdkit -U - -f -D example1.foo=1 example2 2>debug-flags.out && expected_failure
98 check_error "you must supply the file="
99 check_warning "was not used"
101 # These should fail because the -D flag has a bad format.
102 nbdkit -U - -f -D = example2 2>debug-flags.out && expected_failure
103 check_error "must have the format"
104 nbdkit -U - -f -D . example2 2>debug-flags.out && expected_failure
105 check_error "must have the format"
106 nbdkit -U - -f -D =. example2 2>debug-flags.out && expected_failure
107 check_error "must have the format"
108 nbdkit -U - -f -D .= example2 2>debug-flags.out && expected_failure
109 check_error "must have the format"
110 nbdkit -U - -f -D .extra=1 example2 2>debug-flags.out && expected_failure
111 check_error "must have the format"
112 nbdkit -U - -f -D example2.=1 example2 2>debug-flags.out && expected_failure
113 check_error "must have the format"
114 nbdkit -U - -f -D example2.extra= example2 2>debug-flags.out && expected_failure
115 check_error "must have the format"